mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2024-11-14 13:27:41 -07:00
rewrite of aa code
should behave identically
This commit is contained in:
parent
ed79b1772c
commit
0c8095c1bb
@ -1063,14 +1063,11 @@ void SoftRenderer::RenderPolygonScanline(RendererPolygon* rp, s32 y)
|
|||||||
if (x < 0) x = 0;
|
if (x < 0) x = 0;
|
||||||
s32 xlimit;
|
s32 xlimit;
|
||||||
|
|
||||||
s32 xcov = 0;
|
|
||||||
|
|
||||||
// part 1: left edge
|
// part 1: left edge
|
||||||
edge = yedge | 0x1;
|
edge = yedge | 0x1;
|
||||||
xlimit = xstart+l_edgelen;
|
xlimit = xstart+l_edgelen;
|
||||||
if (xlimit > xend+1) xlimit = xend+1;
|
if (xlimit > xend+1) xlimit = xend+1;
|
||||||
if (xlimit > 256) xlimit = 256;
|
if (xlimit > 256) xlimit = 256;
|
||||||
if (l_edgecov & (1<<31)) xcov = (l_edgecov >> 12) & 0x3FF;
|
|
||||||
|
|
||||||
if (!l_filledge) x = xlimit;
|
if (!l_filledge) x = xlimit;
|
||||||
else
|
else
|
||||||
@ -1129,14 +1126,12 @@ void SoftRenderer::RenderPolygonScanline(RendererPolygon* rp, s32 y)
|
|||||||
// anti-aliasing: all edges are rendered
|
// anti-aliasing: all edges are rendered
|
||||||
|
|
||||||
// calculate coverage
|
// calculate coverage
|
||||||
s32 cov = l_edgecov;
|
attr |= (l_edgecov >> 5) << 8;
|
||||||
if (cov & (1<<31))
|
if (x < xlimit-1)
|
||||||
{
|
{
|
||||||
cov = xcov >> 5;
|
l_edgecov += rp->SlopeL.XCov_Incr;
|
||||||
if (cov > 31) cov = 31;
|
if (l_edgecov > 0x3FF) l_edgecov = 0x3FF;
|
||||||
xcov += (l_edgecov & 0x3FF);
|
|
||||||
}
|
}
|
||||||
attr |= (cov << 8);
|
|
||||||
|
|
||||||
// push old pixel down if needed
|
// push old pixel down if needed
|
||||||
if (pixeladdr < BufferSize)
|
if (pixeladdr < BufferSize)
|
||||||
@ -1255,7 +1250,6 @@ void SoftRenderer::RenderPolygonScanline(RendererPolygon* rp, s32 y)
|
|||||||
edge = yedge | 0x2;
|
edge = yedge | 0x2;
|
||||||
xlimit = xend+1;
|
xlimit = xend+1;
|
||||||
if (xlimit > 256) xlimit = 256;
|
if (xlimit > 256) xlimit = 256;
|
||||||
if (r_edgecov & (1<<31)) xcov = (r_edgecov >> 12) & 0x3FF;
|
|
||||||
|
|
||||||
if (r_filledge)
|
if (r_filledge)
|
||||||
for (; x < xlimit; x++)
|
for (; x < xlimit; x++)
|
||||||
@ -1313,14 +1307,12 @@ void SoftRenderer::RenderPolygonScanline(RendererPolygon* rp, s32 y)
|
|||||||
// anti-aliasing: all edges are rendered
|
// anti-aliasing: all edges are rendered
|
||||||
|
|
||||||
// calculate coverage
|
// calculate coverage
|
||||||
s32 cov = r_edgecov;
|
attr |= (r_edgecov >> 5) << 8;
|
||||||
if (cov & (1<<31))
|
if (x < xlimit-1)
|
||||||
{
|
{
|
||||||
cov = 0x1F - (xcov >> 5);
|
r_edgecov -= rp->SlopeR.XCov_Incr;
|
||||||
if (cov < 0) cov = 0;
|
if (r_edgecov < 0) r_edgecov = 0;
|
||||||
xcov += (r_edgecov & 0x3FF);
|
|
||||||
}
|
}
|
||||||
attr |= (cov << 8);
|
|
||||||
|
|
||||||
// push old pixel down if needed
|
// push old pixel down if needed
|
||||||
if (pixeladdr < BufferSize)
|
if (pixeladdr < BufferSize)
|
||||||
|
@ -246,7 +246,7 @@ private:
|
|||||||
Interp.Setup(0, 0, 0, 0);
|
Interp.Setup(0, 0, 0, 0);
|
||||||
Interp.SetX(0);
|
Interp.SetX(0);
|
||||||
|
|
||||||
xcov_incr = 0;
|
XCov_Incr = 0;
|
||||||
|
|
||||||
return x0;
|
return x0;
|
||||||
}
|
}
|
||||||
@ -322,7 +322,7 @@ private:
|
|||||||
Interp.SetX(y);
|
Interp.SetX(y);
|
||||||
|
|
||||||
// used for calculating AA coverage
|
// used for calculating AA coverage
|
||||||
if (XMajor) xcov_incr = (ylen << 10) / xlen;
|
if (XMajor) XCov_Incr = ((ylen << 10) / xlen) & 0x3FF;
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
@ -373,9 +373,11 @@ private:
|
|||||||
// fix the y value for negative slopes
|
// fix the y value for negative slopes
|
||||||
s32 ycoord = Negative ? (ylen << 10) - startcov >> 10 : startcov >> 10;
|
s32 ycoord = Negative ? (ylen << 10) - startcov >> 10 : startcov >> 10;
|
||||||
// if yvalue is not equal to actual y value, invert coverage value
|
// if yvalue is not equal to actual y value, invert coverage value
|
||||||
if (ycoord != y - y0) startcov = 0x3FF - (startcov & 0x3FF);
|
startcov &= 0x3FF;
|
||||||
|
if (ycoord != y - y0) startcov = 0x3FF - startcov;
|
||||||
|
if (side ^ swapped) startcov = 0x3FF - startcov;
|
||||||
|
|
||||||
*coverage = (1<<31) | (startcov << 12) | (xcov_incr & 0x3FF);
|
*coverage = startcov;
|
||||||
|
|
||||||
if constexpr (swapped) *length = 1;
|
if constexpr (swapped) *length = 1;
|
||||||
}
|
}
|
||||||
@ -389,26 +391,17 @@ private:
|
|||||||
{
|
{
|
||||||
// for some reason vertical edges' aa values
|
// for some reason vertical edges' aa values
|
||||||
// are inverted too when the edges are swapped
|
// are inverted too when the edges are swapped
|
||||||
if constexpr (swapped)
|
*coverage = swapped ? 0 : 31 << 5;
|
||||||
*coverage = 0;
|
|
||||||
else
|
|
||||||
*coverage = 31;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
s32 cov = ((dx >> 9) + (Increment >> 10)) >> 4;
|
s32 cov = ((dx >> 9) + (Increment >> 10)) >> 4;
|
||||||
if ((cov >> 5) != (dx >> 18)) cov = 31;
|
if ((cov >> 5) != (dx >> 18)) cov = 31;
|
||||||
cov &= 0x1F;
|
cov &= 0x1F;
|
||||||
if constexpr (swapped)
|
if (side ^ !Negative ^ swapped) cov = 0x1F - cov;
|
||||||
{
|
|
||||||
if (side ^ Negative) cov = 0x1F - cov;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!(side ^ Negative)) cov = 0x1F - cov;
|
|
||||||
}
|
|
||||||
|
|
||||||
*coverage = cov;
|
// shift left 5 just to make it align with xmajor coverage values
|
||||||
|
*coverage = cov << 5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -425,15 +418,13 @@ private:
|
|||||||
bool Negative;
|
bool Negative;
|
||||||
bool XMajor;
|
bool XMajor;
|
||||||
Interpolator<1> Interp;
|
Interpolator<1> Interp;
|
||||||
|
s32 XCov_Incr;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
s32 x0, y0, xmin, xmax;
|
s32 x0, y0, xmin, xmax;
|
||||||
s32 xlen, ylen;
|
s32 xlen, ylen;
|
||||||
s32 dx;
|
s32 dx;
|
||||||
s32 y;
|
s32 y;
|
||||||
|
|
||||||
s32 xcov_incr;
|
|
||||||
s32 ycoverage, ycov_incr;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
Loading…
Reference in New Issue
Block a user