all repos — mgba @ 5ecd28cdc66b4c16bf228bf0717e65453bf6bf4e

mGBA Game Boy Advance Emulator

GBA Video: Fix palette when being initialized mid-frame
Vicki Pfau vi@endrift.com
Sat, 05 Dec 2020 18:41:44 -0800
commit

5ecd28cdc66b4c16bf228bf0717e65453bf6bf4e

parent

6a7e80c969740a73dcc0b7b41786bf71844aedea

2 files changed, 7 insertions(+), 8 deletions(-)

jump to
M include/mgba/internal/gba/renderers/gl.hinclude/mgba/internal/gba/renderers/gl.h

@@ -152,7 +152,7 @@

GLuint paletteTex; uint16_t shadowPalette[GBA_VIDEO_VERTICAL_PIXELS][512]; int nextPalette; - int lastPalette; + int paletteDirtyScanlines; bool paletteDirty; GLuint vramTex;
M src/gba/renderers/gl.csrc/gba/renderers/gl.c

@@ -931,7 +931,7 @@ glRenderer->firstY = -1;

glRenderer->dispcnt = 0x0080; glRenderer->mosaic = 0; glRenderer->nextPalette = 0; - glRenderer->lastPalette = GBA_VIDEO_VERTICAL_PIXELS - 1; + glRenderer->paletteDirtyScanlines = GBA_VIDEO_VERTICAL_PIXELS; memset(glRenderer->shadowRegs, 0, sizeof(glRenderer->shadowRegs)); glRenderer->regsDirty = 0xFFFFFFFFFFFEULL;

@@ -965,11 +965,7 @@ int r = M_R5(value);

int g = M_G5(value) << 1; g |= g >> 5; int b = M_B5(value); - if (glRenderer->nextPalette) { - glRenderer->lastPalette = glRenderer->nextPalette - 1; - } else { - glRenderer->lastPalette = GBA_VIDEO_VERTICAL_PIXELS - 1; - } + glRenderer->paletteDirtyScanlines = GBA_VIDEO_VERTICAL_PIXELS; glRenderer->shadowPalette[glRenderer->nextPalette][address >> 1] = (r << 11) | (g << 5) | b; }

@@ -1376,7 +1372,10 @@ glRenderer->nextPalette = 0;

} if (glRenderer->paletteDirty) { memcpy(glRenderer->shadowPalette[glRenderer->nextPalette], glRenderer->shadowPalette[oldPalette], sizeof(glRenderer->shadowPalette[0])); - if (glRenderer->nextPalette == glRenderer->lastPalette) { + if (glRenderer->paletteDirtyScanlines > 0) { + --glRenderer->paletteDirtyScanlines; + } + if (!glRenderer->paletteDirtyScanlines) { glRenderer->paletteDirty = false; glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, glRenderer->paletteTex);