proper stencil buffer

This commit is contained in:
StapleButter 2017-05-22 22:29:21 +02:00
parent b66ac09e43
commit 88d982b7e3
1 changed files with 8 additions and 11 deletions

View File

@ -36,11 +36,7 @@ u32 AttrBuffer[256*192];
// bit24-29: polygon ID
// bit30: translucent flag
u8 StencilBuffer[256*192];
// note: the stencil buffer isn't emulated properly.
// emulating it properly would require rendering polygons per-scanline
// the stencil buffer is normally limited to 2 scanlines
u8 StencilBuffer[256*2];
bool Init()
@ -751,8 +747,6 @@ void SetupPolygon(RendererPolygon* rp, Polygon* polygon)
void RenderPolygonScanline(RendererPolygon* rp, s32 y)
{
// TODO: shit
Polygon* polygon = rp->PolyData;
u32 polyalpha = (polygon->Attr >> 16) & 0x1F;
@ -764,6 +758,9 @@ void RenderPolygonScanline(RendererPolygon* rp, s32 y)
else
fnDepthTest = DepthTest<false>;
if (polygon->ClearStencil)
memset(&StencilBuffer[256 * (y&0x1)], 0, 256);
if (polygon->YTop != polygon->YBottom)
{
if (y >= polygon->Vertices[rp->NextVL]->FinalPosition[1] && rp->CurVL != polygon->VBottom)
@ -904,7 +901,7 @@ void RenderPolygonScanline(RendererPolygon* rp, s32 y)
// check stencil buffer for shadows
if (polygon->IsShadow)
{
if (StencilBuffer[pixeladdr] == 0)
if (StencilBuffer[pixeladdr & 0x1FF] == 0)
continue;
}
@ -930,7 +927,7 @@ void RenderPolygonScanline(RendererPolygon* rp, s32 y)
}
if (!fnDepthTest(DepthBuffer[pixeladdr], z))
StencilBuffer[pixeladdr] = 1;
StencilBuffer[pixeladdr & 0x1FF] = 1;
continue;
}
@ -1130,10 +1127,10 @@ void RenderPolygon(RendererPolygon* rp)
if (ybot > 192) ybot = 192;
if (polygon->ClearStencil)
/*if (polygon->ClearStencil)
{
memset(StencilBuffer, 0, 192*256);
}
}*/
for (s32 y = ytop; y < ybot; y++)
{