From 560e928d58c24d5e6f89ae51502be647bd7d049d Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Wed, 1 Mar 2017 18:12:47 -0800 Subject: [PATCH] DS GX: Fix z-fighting and transparent colors --- src/ds/gx/software.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/ds/gx/software.c b/src/ds/gx/software.c index 8f59ae6c2..fe790ad27 100644 --- a/src/ds/gx/software.c +++ b/src/ds/gx/software.c @@ -100,6 +100,9 @@ static color_t _lookupColor(struct DSGXSoftwareEndpoint* ep, struct DSGXSoftware case 7: return _finishColor(0x3F, 0x3F, 0x3F); } + if (DSGXTexParamsIs0Transparent(poly->poly->texParams) && !texel) { + return FLAG_UNWRITTEN; + } uint8_t r, g, b; texel = poly->palBase[texel]; _expandColor(texel, &r, &g, &b); @@ -392,6 +395,7 @@ static void DSGXSoftwareRendererDrawScanline(struct DSGXRenderer* renderer, int struct DSGXSoftwareSpan* span = NULL; struct DSGXSoftwareEndpoint ep; int32_t depth = INT32_MIN; + scanline[i] = FLAG_UNWRITTEN; if (i >= nextSpanX) { size_t nextSpanId = DSGXSoftwareSpanListSize(&softwareRenderer->activeSpans); span = DSGXSoftwareSpanListGetPointer(&softwareRenderer->activeSpans, nextSpanId - 1); @@ -412,10 +416,17 @@ static void DSGXSoftwareRendererDrawScanline(struct DSGXRenderer* renderer, int struct DSGXSoftwareSpan* testSpan = DSGXSoftwareSpanListGetPointer(&softwareRenderer->activeSpans, nextSpanId - 1); while (i > (testSpan->ep[0].x >> 12)) { if (i <= (testSpan->ep[1].x >> 12)) { - _lerpEndpoint(testSpan, &ep, i); - if (ep.w > depth) { + _lerpEndpoint(testSpan, &ep, i); + color_t color = _lookupColor(&ep, testSpan->poly); + if (scanline[i] == FLAG_UNWRITTEN) { + scanline[i] = color; + } + if (ep.w >= depth) { depth = ep.w; span = testSpan; + if (color != FLAG_UNWRITTEN) { + scanline[i] = color; + } } } --nextSpanId; @@ -426,12 +437,6 @@ static void DSGXSoftwareRendererDrawScanline(struct DSGXRenderer* renderer, int } } } - if (span) { - _lerpEndpoint(span, &ep, i); - scanline[i] = _lookupColor(&ep, span->poly); - } else { - scanline[i] = FLAG_UNWRITTEN; // TODO - } } }