3D: move opaque/translucent sorting to GPU3D.cpp

This commit is contained in:
StapleButter 2017-07-05 18:11:00 +02:00
parent 1acf355d99
commit 01404ac6c3
3 changed files with 26 additions and 20 deletions

View File

@ -248,6 +248,7 @@ u32 VertexNum;
u32 VertexNumInPoly; u32 VertexNumInPoly;
u32 NumConsecutivePolygons; u32 NumConsecutivePolygons;
Polygon* LastStripPolygon; Polygon* LastStripPolygon;
u32 NumOpaquePolygons;
Vertex VertexRAM[6144 * 2]; Vertex VertexRAM[6144 * 2];
Polygon PolygonRAM[2048 * 2]; Polygon PolygonRAM[2048 * 2];
@ -257,8 +258,7 @@ Polygon* CurPolygonRAM;
u32 NumVertices, NumPolygons; u32 NumVertices, NumPolygons;
u32 CurRAMBank; u32 CurRAMBank;
Vertex* RenderVertexRAM; std::array<Polygon*,2048> RenderPolygonRAM;
Polygon* RenderPolygonRAM;
u32 RenderNumPolygons; u32 RenderNumPolygons;
u32 FlushRequest; u32 FlushRequest;
@ -338,6 +338,7 @@ void Reset()
CurPolygonRAM = &PolygonRAM[0]; CurPolygonRAM = &PolygonRAM[0];
NumVertices = 0; NumVertices = 0;
NumPolygons = 0; NumPolygons = 0;
NumOpaquePolygons = 0;
// TODO: confirm initial polyid/color/fog values // TODO: confirm initial polyid/color/fog values
ClearAttr1 = 0x3F000000; ClearAttr1 = 0x3F000000;
@ -754,6 +755,8 @@ void SubmitPolygon()
poly->IsShadowMask = ((CurPolygonAttr & 0x3F000030) == 0x00000030); poly->IsShadowMask = ((CurPolygonAttr & 0x3F000030) == 0x00000030);
poly->IsShadow = ((CurPolygonAttr & 0x30) == 0x30) && !poly->IsShadowMask; poly->IsShadow = ((CurPolygonAttr & 0x30) == 0x30) && !poly->IsShadowMask;
if (!poly->Translucent) NumOpaquePolygons++;
if (LastStripPolygon && clipstart > 0) if (LastStripPolygon && clipstart > 0)
{ {
if (nverts == lastpolyverts) if (nverts == lastpolyverts)
@ -1792,8 +1795,18 @@ void VBlank()
{ {
if (FlushRequest) if (FlushRequest)
{ {
RenderVertexRAM = CurVertexRAM; // separate translucent polygons from opaque ones
RenderPolygonRAM = CurPolygonRAM;
u32 io = 0, it = NumOpaquePolygons;
for (u32 i = 0; i < NumPolygons; i++)
{
Polygon* poly = &CurPolygonRAM[i];
if (poly->Translucent)
RenderPolygonRAM[it++] = poly;
else
RenderPolygonRAM[io++] = poly;
}
RenderNumPolygons = NumPolygons; RenderNumPolygons = NumPolygons;
RenderDispCnt = DispCnt; RenderDispCnt = DispCnt;
@ -1817,6 +1830,7 @@ void VBlank()
NumVertices = 0; NumVertices = 0;
NumPolygons = 0; NumPolygons = 0;
NumOpaquePolygons = 0;
FlushRequest = 0; FlushRequest = 0;
} }

View File

@ -19,6 +19,8 @@
#ifndef GPU3D_H #ifndef GPU3D_H
#define GPU3D_H #define GPU3D_H
#include <array>
namespace GPU3D namespace GPU3D
{ {
@ -77,8 +79,7 @@ extern u8 RenderFogDensityTable[34];
extern u32 RenderClearAttr1, RenderClearAttr2; extern u32 RenderClearAttr1, RenderClearAttr2;
extern Vertex* RenderVertexRAM; extern std::array<Polygon*,2048> RenderPolygonRAM;
extern Polygon* RenderPolygonRAM;
extern u32 RenderNumPolygons; extern u32 RenderNumPolygons;
bool Init(); bool Init();

View File

@ -1675,7 +1675,7 @@ void ClearBuffers()
} }
} }
void RenderPolygons(bool threaded, Polygon* polygons, int npolys) void RenderPolygons(bool threaded, Polygon** polygons, int npolys)
{ {
// sort polygons // sort polygons
// TODO: Y-sorting for translucent polygons // TODO: Y-sorting for translucent polygons
@ -1686,17 +1686,8 @@ void RenderPolygons(bool threaded, Polygon* polygons, int npolys)
int j = 0; int j = 0;
for (int i = 0; i < npolys; i++) for (int i = 0; i < npolys; i++)
{ {
if (polygons[i].Translucent) continue; if (polygons[i]->YBottom > 192) continue;
SetupPolygon(&PolygonList[j++], polygons[i]);
if (polygons[i].YBottom > 192) continue;
SetupPolygon(&PolygonList[j++], &polygons[i]);
}
for (int i = 0; i < npolys; i++)
{
if (!polygons[i].Translucent) continue;
if (polygons[i].YBottom > 192) continue;
SetupPolygon(&PolygonList[j++], &polygons[i]);
} }
RenderScanline(0, j); RenderScanline(0, j);
@ -1731,7 +1722,7 @@ void RenderFrame()
else else
{ {
ClearBuffers(); ClearBuffers();
RenderPolygons(false, RenderPolygonRAM, RenderNumPolygons); RenderPolygons(false, &RenderPolygonRAM[0], RenderNumPolygons);
} }
} }
@ -1744,7 +1735,7 @@ void RenderThreadFunc()
RenderThreadRendering = true; RenderThreadRendering = true;
ClearBuffers(); ClearBuffers();
RenderPolygons(true, RenderPolygonRAM, RenderNumPolygons); RenderPolygons(true, &RenderPolygonRAM[0], RenderNumPolygons);
Platform::Semaphore_Post(Sema_RenderDone); Platform::Semaphore_Post(Sema_RenderDone);
RenderThreadRendering = false; RenderThreadRendering = false;