all repos — mgba @ ea1f87d745a4b686ecb0b74a2303a71a5a27dda2

mGBA Game Boy Advance Emulator

GBA Video: Fix edge case with sprite blend modes and semitransparency
Jeffrey Pfau jeffrey@endrift.com
Wed, 16 Sep 2015 20:27:42 -0700
commit

ea1f87d745a4b686ecb0b74a2303a71a5a27dda2

parent

b5a34c9fe772ad08dfb04dc0eac7e1b3ef3dc6d8

M CHANGESCHANGES

@@ -12,6 +12,7 @@ - GBA Audio: Fix 8-bit writes to audio channel 3 and 4 registers

- GBA Audio: Fix audio channels being silenced at the wrong time - VFS: Fix return values of VFileFILE.read and .write - Util: Fix PowerPC PNG read/write pixel order + - GBA Video: Fix edge case with sprite blend modes and semitransparency Misc: - Qt: Window size command line options are now supported - Qt: Increase usability of key mapper
M src/gba/renderers/software-mode0.csrc/gba/renderers/software-mode0.c

@@ -473,10 +473,6 @@ flags |= FLAG_TARGET_2 * background->target2;

int objwinFlags = FLAG_TARGET_1 * (background->target1 && renderer->blendEffect == BLEND_ALPHA && GBAWindowControlIsBlendEnable(renderer->objwin.packed)); objwinFlags |= flags; flags |= FLAG_TARGET_1 * (background->target1 && renderer->blendEffect == BLEND_ALPHA && GBAWindowControlIsBlendEnable(renderer->currentWindow.packed)); - if (renderer->blda == 0x10 && renderer->bldb == 0) { - flags &= ~(FLAG_TARGET_1 | FLAG_TARGET_2); - objwinFlags &= ~(FLAG_TARGET_1 | FLAG_TARGET_2); \ - } uint32_t screenBase; uint32_t charBase;
M src/gba/renderers/software-obj.csrc/gba/renderers/software-obj.c

@@ -126,7 +126,7 @@ target2 |= renderer->bg[0].target2 << (renderer->bg[0].priority);

target2 |= renderer->bg[1].target2 << (renderer->bg[1].priority); target2 |= renderer->bg[2].target2 << (renderer->bg[2].priority); target2 |= renderer->bg[3].target2 << (renderer->bg[3].priority); - if (GBAObjAttributesCGetPriority(sprite->c) < target2) { + if ((1 << GBAObjAttributesCGetPriority(sprite->c)) < target2) { variant = 0; } }
M src/gba/renderers/software-private.hsrc/gba/renderers/software-private.h

@@ -42,7 +42,7 @@ if (color >= current) {

if (current & FLAG_TARGET_1 && color & FLAG_TARGET_2) { color = _mix(renderer->blda, current, renderer->bldb, color); } else { - color = current & 0x00FFFFFF; + color = current & (0x00FFFFFF | FLAG_TARGET_1); } } else { color = (color & ~FLAG_TARGET_2) | (current & FLAG_OBJWIN);

@@ -55,7 +55,7 @@ if (color >= current) {

if (current & FLAG_TARGET_1 && color & FLAG_TARGET_2) { color = _mix(renderer->blda, current, renderer->bldb, color); } else { - color = current & 0x00FFFFFF; + color = current & (0x00FFFFFF | FLAG_TARGET_1); } } else { color = color & ~FLAG_TARGET_2;

@@ -67,16 +67,20 @@ static inline void _compositeNoBlendObjwin(struct GBAVideoSoftwareRenderer* renderer, uint32_t* pixel, uint32_t color,

uint32_t current) { UNUSED(renderer); if (color < current) { - *pixel = color | (current & FLAG_OBJWIN); + color |= (current & FLAG_OBJWIN); + } else { + color = current & (0x00FFFFFF | FLAG_TARGET_1); } + *pixel = color; } static inline void _compositeNoBlendNoObjwin(struct GBAVideoSoftwareRenderer* renderer, uint32_t* pixel, uint32_t color, uint32_t current) { UNUSED(renderer); - if (color < current) { - *pixel = color; + if (color >= current) { + color = current & (0x00FFFFFF | FLAG_TARGET_1); } + *pixel = color; } #define COMPOSITE_16_OBJWIN(BLEND) \

@@ -180,10 +184,6 @@ GBAWindowControlIsBlendEnable(renderer->objwin.packed)); \

objwinFlags |= flags; \ flags |= FLAG_TARGET_1 * (background->target1 && renderer->blendEffect == BLEND_ALPHA && \ GBAWindowControlIsBlendEnable(renderer->currentWindow.packed)); \ - if (renderer->blda == 0x10 && renderer->bldb == 0) { \ - flags &= ~(FLAG_TARGET_1 | FLAG_TARGET_2); \ - objwinFlags &= ~(FLAG_TARGET_1 | FLAG_TARGET_2); \ - } \ int variant = background->target1 && GBAWindowControlIsBlendEnable(renderer->currentWindow.packed) && \ (renderer->blendEffect == BLEND_BRIGHTEN || renderer->blendEffect == BLEND_DARKEN); \ color_t* palette = renderer->normalPalette; \
M src/gba/renderers/video-software.csrc/gba/renderers/video-software.c

@@ -523,7 +523,7 @@

if (softwareRenderer->target2Bd) { x = 0; for (w = 0; w < softwareRenderer->nWindows; ++w) { - uint32_t backdrop = FLAG_UNWRITTEN; + uint32_t backdrop = FLAG_UNWRITTEN; if (!softwareRenderer->target1Bd || softwareRenderer->blendEffect == BLEND_NONE || softwareRenderer->blendEffect == BLEND_ALPHA || !GBAWindowControlIsBlendEnable(softwareRenderer->windows[w].control.packed)) { backdrop |= softwareRenderer->normalPalette[0]; } else {

@@ -532,8 +532,32 @@ }

int end = softwareRenderer->windows[w].endX; for (; x < end; ++x) { uint32_t color = softwareRenderer->row[x]; - if (color & FLAG_TARGET_1) { + if (color & FLAG_TARGET_1 && color & FLAG_UNWRITTEN) { softwareRenderer->row[x] = _mix(softwareRenderer->bldb, backdrop, softwareRenderer->blda, color); + } + } + } + } + if (softwareRenderer->target1Obj && (softwareRenderer->blendEffect == BLEND_DARKEN || softwareRenderer->blendEffect == BLEND_BRIGHTEN)) { + x = 0; + for (w = 0; w < softwareRenderer->nWindows; ++w) { + if (!GBAWindowControlIsBlendEnable(softwareRenderer->windows[w].control.packed)) { + continue; + } + int end = softwareRenderer->windows[w].endX; + if (softwareRenderer->blendEffect == BLEND_DARKEN) { + for (; x < end; ++x) { + uint32_t color = softwareRenderer->row[x]; + if (color & FLAG_TARGET_1 && !(color & FLAG_UNWRITTEN)) { + softwareRenderer->row[x] = _darken(color, softwareRenderer->bldy); + } + } + } else if (softwareRenderer->blendEffect == BLEND_BRIGHTEN) { + for (; x < end; ++x) { + uint32_t color = softwareRenderer->row[x]; + if (color & FLAG_TARGET_1 && !(color & FLAG_UNWRITTEN)) { + softwareRenderer->row[x] = _brighten(color, softwareRenderer->bldy); + } } } }