3D: Y-sorting
This commit is contained in:
parent
01404ac6c3
commit
d5376b4184
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <algorithm>
|
||||||
#include "NDS.h"
|
#include "NDS.h"
|
||||||
#include "GPU.h"
|
#include "GPU.h"
|
||||||
#include "FIFO.h"
|
#include "FIFO.h"
|
||||||
|
@ -855,6 +856,10 @@ void SubmitPolygon()
|
||||||
poly->VTop = vtop; poly->VBottom = vbot;
|
poly->VTop = vtop; poly->VBottom = vbot;
|
||||||
poly->YTop = ytop; poly->YBottom = ybot;
|
poly->YTop = ytop; poly->YBottom = ybot;
|
||||||
poly->XTop = xtop; poly->XBottom = xbot;
|
poly->XTop = xtop; poly->XBottom = xbot;
|
||||||
|
|
||||||
|
poly->SortKey = (ybot << 8) | ytop;
|
||||||
|
if (poly->Translucent) poly->SortKey |= 0x10000;
|
||||||
|
|
||||||
poly->WShift = wshift;
|
poly->WShift = wshift;
|
||||||
poly->WBuffer = (FlushAttributes & 0x2);
|
poly->WBuffer = (FlushAttributes & 0x2);
|
||||||
|
|
||||||
|
@ -1791,9 +1796,21 @@ void VCount144()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool YSort(Polygon* a, Polygon* b)
|
||||||
|
{
|
||||||
|
// Y-sorting rules:
|
||||||
|
// * polygons with lower bottom Y come first
|
||||||
|
// * upon equal bottom Y, polygons with lower top Y come first
|
||||||
|
// * upon equal bottom AND top Y, original ordering is used
|
||||||
|
|
||||||
|
return a->SortKey < b->SortKey;
|
||||||
|
}
|
||||||
|
|
||||||
void VBlank()
|
void VBlank()
|
||||||
{
|
{
|
||||||
if (FlushRequest)
|
if (FlushRequest)
|
||||||
|
{
|
||||||
|
if (NumPolygons)
|
||||||
{
|
{
|
||||||
// separate translucent polygons from opaque ones
|
// separate translucent polygons from opaque ones
|
||||||
|
|
||||||
|
@ -1807,6 +1824,13 @@ void VBlank()
|
||||||
RenderPolygonRAM[io++] = poly;
|
RenderPolygonRAM[io++] = poly;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// apply Y-sorting
|
||||||
|
|
||||||
|
std::stable_sort(RenderPolygonRAM.begin(),
|
||||||
|
RenderPolygonRAM.begin() + ((FlushAttributes & 0x1) ? NumOpaquePolygons : NumPolygons),
|
||||||
|
YSort);
|
||||||
|
}
|
||||||
|
|
||||||
RenderNumPolygons = NumPolygons;
|
RenderNumPolygons = NumPolygons;
|
||||||
|
|
||||||
RenderDispCnt = DispCnt;
|
RenderDispCnt = DispCnt;
|
||||||
|
|
|
@ -60,12 +60,12 @@ typedef struct
|
||||||
bool IsShadowMask;
|
bool IsShadowMask;
|
||||||
bool IsShadow;
|
bool IsShadow;
|
||||||
|
|
||||||
// data below rather specific to the software renderer
|
|
||||||
|
|
||||||
u32 VTop, VBottom; // vertex indices
|
u32 VTop, VBottom; // vertex indices
|
||||||
s32 YTop, YBottom; // Y coords
|
s32 YTop, YBottom; // Y coords
|
||||||
s32 XTop, XBottom; // associated X coords
|
s32 XTop, XBottom; // associated X coords
|
||||||
|
|
||||||
|
u32 SortKey;
|
||||||
|
|
||||||
} Polygon;
|
} Polygon;
|
||||||
|
|
||||||
extern u32 RenderDispCnt;
|
extern u32 RenderDispCnt;
|
||||||
|
|
|
@ -1677,10 +1677,6 @@ void ClearBuffers()
|
||||||
|
|
||||||
void RenderPolygons(bool threaded, Polygon** polygons, int npolys)
|
void RenderPolygons(bool threaded, Polygon** polygons, int npolys)
|
||||||
{
|
{
|
||||||
// sort polygons
|
|
||||||
// TODO: Y-sorting for translucent polygons
|
|
||||||
// TODO: all sorting should be done in GPU3D.cpp
|
|
||||||
|
|
||||||
// polygons with ybottom>192 aren't rendered at all
|
// polygons with ybottom>192 aren't rendered at all
|
||||||
|
|
||||||
int j = 0;
|
int j = 0;
|
||||||
|
|
Loading…
Reference in New Issue