From 8f58343e2b3ff091f51254983c54e581581b118e Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Thu, 23 Mar 2017 21:23:47 -0700 Subject: [PATCH] DS GX: Move rendering until first scanline is requested --- include/mgba/internal/ds/gx/software.h | 1 + src/ds/gx/software.c | 18 +++++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/include/mgba/internal/ds/gx/software.h b/include/mgba/internal/ds/gx/software.h index b11e41f46..7abbf64c0 100644 --- a/include/mgba/internal/ds/gx/software.h +++ b/include/mgba/internal/ds/gx/software.h @@ -93,6 +93,7 @@ struct DSGXSoftwareRenderer { uint8_t* stencilBuffer; color_t* scanlineCache; int sort; + bool flushPending; struct DSGXVertex* verts; }; diff --git a/src/ds/gx/software.c b/src/ds/gx/software.c index f258f4693..2e8aa5636 100644 --- a/src/ds/gx/software.c +++ b/src/ds/gx/software.c @@ -697,18 +697,27 @@ static void DSGXSoftwareRendererSetRAM(struct DSGXRenderer* renderer, struct DSG softwareRenderer->depthBuffer[i + 2] = INT32_MAX; softwareRenderer->depthBuffer[i + 3] = INT32_MAX; } + softwareRenderer->flushPending = true; +} + +static void DSGXSoftwareRendererDrawScanline(struct DSGXRenderer* renderer, int y) { + struct DSGXSoftwareRenderer* softwareRenderer = (struct DSGXSoftwareRenderer*) renderer; + if (!softwareRenderer->flushPending || y) { + return; + } size_t p; for (p = 0; p < DSGXSoftwarePolygonListSize(&softwareRenderer->activePolys); ++p) { struct DSGXSoftwarePolygon* poly = DSGXSoftwarePolygonListGetPointer(&softwareRenderer->activePolys, p); DSGXSoftwareEdgeListClear(&softwareRenderer->activeEdges); - _preparePoly(renderer, verts, poly); + _preparePoly(renderer, softwareRenderer->verts, poly); int y; for (y = poly->minY; y <= poly->maxY; ++y) { struct DSGXSoftwareSpan span = { .poly = poly, .polyId = DSGXPolygonAttrsGetId(poly->polyParams), }; + size_t i; for (i = 0; i < DSGXSoftwareEdgeListSize(&softwareRenderer->activeEdges); ++i) { struct DSGXSoftwareEdge* edge = DSGXSoftwareEdgeListGetPointer(&softwareRenderer->activeEdges, i); if (edge->y1 < (y << 12)) { @@ -729,12 +738,7 @@ static void DSGXSoftwareRendererSetRAM(struct DSGXRenderer* renderer, struct DSG } } } -} - -static void DSGXSoftwareRendererDrawScanline(struct DSGXRenderer* renderer, int y) { - struct DSGXSoftwareRenderer* softwareRenderer = (struct DSGXSoftwareRenderer*) renderer; - UNUSED(softwareRenderer); - UNUSED(y); + softwareRenderer->flushPending = false; } static void DSGXSoftwareRendererGetScanline(struct DSGXRenderer* renderer, int y, const color_t** output) {