mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-23 14:19:55 -06:00
Fix aa being upside down on swapped y-major slopes (#1803)
* fix aa being upside down on swapped y-major slopes * further improvements to swapped aa in addition to fixing swapped y-major slope aa, now fixes: swapped x-major slope aa swapped vertical slope aa * use templates instead + style/comment tweaks should force the compiler to precompile if statements like i want it to do, instead of just hoping it does so on its own
This commit is contained in:
@ -354,13 +354,19 @@ private:
|
||||
else if (ret > xmax) ret = xmax;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
template<bool swapped>
|
||||
void EdgeParams_XMajor(s32* length, s32* coverage)
|
||||
{
|
||||
if (side ^ Negative)
|
||||
*length = (dx >> 18) - ((dx-Increment) >> 18);
|
||||
else
|
||||
*length = ((dx+Increment) >> 18) - (dx >> 18);
|
||||
// only do length calc for right side when swapped as it's
|
||||
// only needed for aa calcs, as actual line spans are broken
|
||||
if constexpr (!swapped || side)
|
||||
{
|
||||
if (side ^ Negative)
|
||||
*length = (dx >> 18) - ((dx-Increment) >> 18);
|
||||
else
|
||||
*length = ((dx+Increment) >> 18) - (dx >> 18);
|
||||
}
|
||||
|
||||
// for X-major edges, we return the coverage
|
||||
// for the first pixel, and the increment for
|
||||
@ -371,33 +377,49 @@ private:
|
||||
|
||||
s32 startcov = (((startx << 10) + 0x1FF) * ylen) / xlen;
|
||||
*coverage = (1<<31) | ((startcov & 0x3FF) << 12) | (xcov_incr & 0x3FF);
|
||||
|
||||
if constexpr (swapped) *length = 1;
|
||||
}
|
||||
|
||||
template<bool swapped>
|
||||
void EdgeParams_YMajor(s32* length, s32* coverage)
|
||||
{
|
||||
*length = 1;
|
||||
|
||||
if (Increment == 0)
|
||||
{
|
||||
*coverage = 31;
|
||||
// for some reason vertical edges' aa values
|
||||
// are inverted too when the edges are swapped
|
||||
if constexpr (swapped)
|
||||
*coverage = 0;
|
||||
else
|
||||
*coverage = 31;
|
||||
}
|
||||
else
|
||||
{
|
||||
s32 cov = ((dx >> 9) + (Increment >> 10)) >> 4;
|
||||
if ((cov >> 5) != (dx >> 18)) cov = 31;
|
||||
cov &= 0x1F;
|
||||
if (!(side ^ Negative)) cov = 0x1F - cov;
|
||||
if constexpr (swapped)
|
||||
{
|
||||
if (side ^ Negative) cov = 0x1F - cov;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!(side ^ Negative)) cov = 0x1F - cov;
|
||||
}
|
||||
|
||||
*coverage = cov;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<bool swapped>
|
||||
void EdgeParams(s32* length, s32* coverage)
|
||||
{
|
||||
if (XMajor)
|
||||
return EdgeParams_XMajor(length, coverage);
|
||||
return EdgeParams_XMajor<swapped>(length, coverage);
|
||||
else
|
||||
return EdgeParams_YMajor(length, coverage);
|
||||
return EdgeParams_YMajor<swapped>(length, coverage);
|
||||
}
|
||||
|
||||
s32 Increment;
|
||||
|
Reference in New Issue
Block a user