mirror of https://github.com/mgba-emu/mgba.git
DS GX: Add polygon IDs to the framebuffer
This commit is contained in:
parent
d7ce8f9f06
commit
d5445799a6
|
@ -55,6 +55,7 @@ DECL_BIT(DSGXPolygonAttrs, BackFace, 7);
|
||||||
DECL_BIT(DSGXPolygonAttrs, UpdateDepth, 11);
|
DECL_BIT(DSGXPolygonAttrs, UpdateDepth, 11);
|
||||||
// TODO
|
// TODO
|
||||||
DECL_BITS(DSGXPolygonAttrs, Alpha, 16, 5);
|
DECL_BITS(DSGXPolygonAttrs, Alpha, 16, 5);
|
||||||
|
DECL_BITS(DSGXPolygonAttrs, Id, 24, 6);
|
||||||
|
|
||||||
enum DSGXCommand {
|
enum DSGXCommand {
|
||||||
DS_GX_CMD_NOP = 0,
|
DS_GX_CMD_NOP = 0,
|
||||||
|
|
|
@ -70,6 +70,7 @@ struct DSGXSoftwareEndpoint {
|
||||||
|
|
||||||
struct DSGXSoftwareSpan {
|
struct DSGXSoftwareSpan {
|
||||||
struct DSGXSoftwarePolygon* poly;
|
struct DSGXSoftwarePolygon* poly;
|
||||||
|
int polyId;
|
||||||
struct DSGXSoftwareEndpoint ep[2];
|
struct DSGXSoftwareEndpoint ep[2];
|
||||||
struct DSGXSoftwareEndpoint step;
|
struct DSGXSoftwareEndpoint step;
|
||||||
};
|
};
|
||||||
|
@ -87,6 +88,7 @@ struct DSGXSoftwareRenderer {
|
||||||
struct DSGXSoftwareSpan** bucket;
|
struct DSGXSoftwareSpan** bucket;
|
||||||
|
|
||||||
int32_t depthBuffer[DS_VIDEO_HORIZONTAL_PIXELS];
|
int32_t depthBuffer[DS_VIDEO_HORIZONTAL_PIXELS];
|
||||||
|
uint8_t polygonIdBuffer[DS_VIDEO_HORIZONTAL_PIXELS];
|
||||||
color_t* scanlineCache;
|
color_t* scanlineCache;
|
||||||
bool flushPending;
|
bool flushPending;
|
||||||
bool wSort;
|
bool wSort;
|
||||||
|
|
|
@ -639,6 +639,7 @@ static void DSGXSoftwareRendererDrawScanline(struct DSGXRenderer* renderer, int
|
||||||
span = DSGXSoftwareSpanListAppend(&softwareRenderer->activeSpans);
|
span = DSGXSoftwareSpanListAppend(&softwareRenderer->activeSpans);
|
||||||
memset(&span->ep[1], 0, sizeof(span->ep[1]));
|
memset(&span->ep[1], 0, sizeof(span->ep[1]));
|
||||||
span->poly = DSGXSoftwarePolygonListGetPointer(&softwareRenderer->activePolys, poly);
|
span->poly = DSGXSoftwarePolygonListGetPointer(&softwareRenderer->activePolys, poly);
|
||||||
|
span->polyId = DSGXPolygonAttrsGetId(span->poly->poly->polyParams);
|
||||||
if (!_edgeToSpan(span, edge, 0, y << 12)) {
|
if (!_edgeToSpan(span, edge, 0, y << 12)) {
|
||||||
// Horizontal line
|
// Horizontal line
|
||||||
DSGXSoftwareSpanListShift(&softwareRenderer->activeSpans, DSGXSoftwareSpanListSize(&softwareRenderer->activeSpans) - 1, 1);
|
DSGXSoftwareSpanListShift(&softwareRenderer->activeSpans, DSGXSoftwareSpanListSize(&softwareRenderer->activeSpans) - 1, 1);
|
||||||
|
@ -650,6 +651,7 @@ static void DSGXSoftwareRendererDrawScanline(struct DSGXRenderer* renderer, int
|
||||||
|
|
||||||
color_t* scanline = &softwareRenderer->scanlineCache[DS_VIDEO_HORIZONTAL_PIXELS * y];
|
color_t* scanline = &softwareRenderer->scanlineCache[DS_VIDEO_HORIZONTAL_PIXELS * y];
|
||||||
memset(scanline, 0, sizeof(color_t) * DS_VIDEO_HORIZONTAL_PIXELS);
|
memset(scanline, 0, sizeof(color_t) * DS_VIDEO_HORIZONTAL_PIXELS);
|
||||||
|
memset(softwareRenderer->polygonIdBuffer, 0, sizeof(softwareRenderer->polygonIdBuffer[0]) * DS_VIDEO_HORIZONTAL_PIXELS);
|
||||||
for (i = 0; i < DS_VIDEO_HORIZONTAL_PIXELS; i += 4) {
|
for (i = 0; i < DS_VIDEO_HORIZONTAL_PIXELS; i += 4) {
|
||||||
softwareRenderer->depthBuffer[i] = INT32_MAX;
|
softwareRenderer->depthBuffer[i] = INT32_MAX;
|
||||||
softwareRenderer->depthBuffer[i + 1] = INT32_MAX;
|
softwareRenderer->depthBuffer[i + 1] = INT32_MAX;
|
||||||
|
@ -678,11 +680,13 @@ static void DSGXSoftwareRendererDrawScanline(struct DSGXRenderer* renderer, int
|
||||||
if (softwareRenderer->wSort) {
|
if (softwareRenderer->wSort) {
|
||||||
if (span->ep[0].w < softwareRenderer->depthBuffer[x]) {
|
if (span->ep[0].w < softwareRenderer->depthBuffer[x]) {
|
||||||
softwareRenderer->depthBuffer[x] = span->ep[0].w;
|
softwareRenderer->depthBuffer[x] = span->ep[0].w;
|
||||||
|
softwareRenderer->polygonIdBuffer[x] = span->polyId;
|
||||||
scanline[x] = color;
|
scanline[x] = color;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (span->ep[0].z < softwareRenderer->depthBuffer[x]) {
|
if (span->ep[0].z < softwareRenderer->depthBuffer[x]) {
|
||||||
softwareRenderer->depthBuffer[x] = span->ep[0].z;
|
softwareRenderer->depthBuffer[x] = span->ep[0].z;
|
||||||
|
softwareRenderer->polygonIdBuffer[x] = span->polyId;
|
||||||
scanline[x] = color;
|
scanline[x] = color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -692,19 +696,23 @@ static void DSGXSoftwareRendererDrawScanline(struct DSGXRenderer* renderer, int
|
||||||
color = _mix32(a, color, 0x1F - a, current);
|
color = _mix32(a, color, 0x1F - a, current);
|
||||||
color |= ab << 27;
|
color |= ab << 27;
|
||||||
}
|
}
|
||||||
if (softwareRenderer->wSort) {
|
if (softwareRenderer->polygonIdBuffer[x] != span->polyId) {
|
||||||
if (span->ep[0].w < softwareRenderer->depthBuffer[x]) {
|
if (softwareRenderer->wSort) {
|
||||||
if (DSGXPolygonAttrsIsUpdateDepth(span->poly->poly->polyParams)) {
|
if (span->ep[0].w < softwareRenderer->depthBuffer[x]) {
|
||||||
softwareRenderer->depthBuffer[x] = span->ep[0].w;
|
if (DSGXPolygonAttrsIsUpdateDepth(span->poly->poly->polyParams)) {
|
||||||
|
softwareRenderer->depthBuffer[x] = span->ep[0].w;
|
||||||
|
}
|
||||||
|
softwareRenderer->polygonIdBuffer[x] = span->polyId;
|
||||||
|
scanline[x] = color;
|
||||||
}
|
}
|
||||||
scanline[x] = color;
|
} else {
|
||||||
}
|
if (span->ep[0].z < softwareRenderer->depthBuffer[x]) {
|
||||||
} else {
|
if (DSGXPolygonAttrsIsUpdateDepth(span->poly->poly->polyParams)) {
|
||||||
if (span->ep[0].z < softwareRenderer->depthBuffer[x]) {
|
softwareRenderer->depthBuffer[x] = span->ep[0].z;
|
||||||
if (DSGXPolygonAttrsIsUpdateDepth(span->poly->poly->polyParams)) {
|
}
|
||||||
softwareRenderer->depthBuffer[x] = span->ep[0].z;
|
softwareRenderer->polygonIdBuffer[x] = span->polyId;
|
||||||
|
scanline[x] = color;
|
||||||
}
|
}
|
||||||
scanline[x] = color;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue