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 // bit24-29: polygon ID
// bit30: translucent flag // bit30: translucent flag
u8 StencilBuffer[256*192]; u8 StencilBuffer[256*2];
// 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
bool Init() bool Init()
@ -751,8 +747,6 @@ void SetupPolygon(RendererPolygon* rp, Polygon* polygon)
void RenderPolygonScanline(RendererPolygon* rp, s32 y) void RenderPolygonScanline(RendererPolygon* rp, s32 y)
{ {
// TODO: shit
Polygon* polygon = rp->PolyData; Polygon* polygon = rp->PolyData;
u32 polyalpha = (polygon->Attr >> 16) & 0x1F; u32 polyalpha = (polygon->Attr >> 16) & 0x1F;
@ -764,6 +758,9 @@ void RenderPolygonScanline(RendererPolygon* rp, s32 y)
else else
fnDepthTest = DepthTest<false>; fnDepthTest = DepthTest<false>;
if (polygon->ClearStencil)
memset(&StencilBuffer[256 * (y&0x1)], 0, 256);
if (polygon->YTop != polygon->YBottom) if (polygon->YTop != polygon->YBottom)
{ {
if (y >= polygon->Vertices[rp->NextVL]->FinalPosition[1] && rp->CurVL != polygon->VBottom) 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 // check stencil buffer for shadows
if (polygon->IsShadow) if (polygon->IsShadow)
{ {
if (StencilBuffer[pixeladdr] == 0) if (StencilBuffer[pixeladdr & 0x1FF] == 0)
continue; continue;
} }
@ -930,7 +927,7 @@ void RenderPolygonScanline(RendererPolygon* rp, s32 y)
} }
if (!fnDepthTest(DepthBuffer[pixeladdr], z)) if (!fnDepthTest(DepthBuffer[pixeladdr], z))
StencilBuffer[pixeladdr] = 1; StencilBuffer[pixeladdr & 0x1FF] = 1;
continue; continue;
} }
@ -1130,10 +1127,10 @@ void RenderPolygon(RendererPolygon* rp)
if (ybot > 192) ybot = 192; if (ybot > 192) ybot = 192;
if (polygon->ClearStencil) /*if (polygon->ClearStencil)
{ {
memset(StencilBuffer, 0, 192*256); memset(StencilBuffer, 0, 192*256);
} }*/
for (s32 y = ytop; y < ybot; y++) for (s32 y = ytop; y < ybot; y++)
{ {