mirror of https://github.com/mgba-emu/mgba.git
Fix OBJWIN blending modifications on BG modes 0 - 2
This commit is contained in:
parent
cff77a3a81
commit
58611facf1
|
@ -636,9 +636,12 @@ static void _composite(struct GBAVideoSoftwareRenderer* renderer, int offset, ui
|
||||||
#define BACKGROUND_DRAW_PIXEL_16 \
|
#define BACKGROUND_DRAW_PIXEL_16 \
|
||||||
pixelData = tileData & 0xF; \
|
pixelData = tileData & 0xF; \
|
||||||
current = renderer->row[outX]; \
|
current = renderer->row[outX]; \
|
||||||
if (tileData & 0xF && !(current & FLAG_FINALIZED)) { \
|
if (pixelData && !(current & FLAG_FINALIZED)) { \
|
||||||
if (!objwinSlowPath || !(current & FLAG_OBJWIN) != objwinOnly) { \
|
if (!objwinSlowPath) { \
|
||||||
_composite(renderer, outX, palette[pixelData | paletteData] | flags, current); \
|
_composite(renderer, outX, palette[pixelData | paletteData] | flags, current); \
|
||||||
|
} else if (objwinForceEnable || !(current & FLAG_OBJWIN) == objwinOnly) { \
|
||||||
|
color_t* currentPalette = (current & FLAG_OBJWIN) ? objwinPalette : palette; \
|
||||||
|
_composite(renderer, outX, currentPalette[pixelData | paletteData] | flags, current); \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
tileData >>= 4;
|
tileData >>= 4;
|
||||||
|
@ -647,8 +650,11 @@ static void _composite(struct GBAVideoSoftwareRenderer* renderer, int offset, ui
|
||||||
pixelData = tileData & 0xFF; \
|
pixelData = tileData & 0xFF; \
|
||||||
current = renderer->row[outX]; \
|
current = renderer->row[outX]; \
|
||||||
if (pixelData && !(current & FLAG_FINALIZED)) { \
|
if (pixelData && !(current & FLAG_FINALIZED)) { \
|
||||||
if (!objwinSlowPath || !(current & FLAG_OBJWIN) != objwinOnly) { \
|
if (!objwinSlowPath) { \
|
||||||
_composite(renderer, outX, palette[pixelData] | flags, current); \
|
_composite(renderer, outX, palette[pixelData] | flags, current); \
|
||||||
|
} else if (objwinForceEnable || !(current & FLAG_OBJWIN) == objwinOnly) { \
|
||||||
|
color_t* currentPalette = (current & FLAG_OBJWIN) ? objwinPalette : palette; \
|
||||||
|
_composite(renderer, outX, currentPalette[pixelData] | flags, current); \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
tileData >>= 8;
|
tileData >>= 8;
|
||||||
|
@ -787,23 +793,30 @@ static void _composite(struct GBAVideoSoftwareRenderer* renderer, int offset, ui
|
||||||
#define PREPARE_OBJWIN \
|
#define PREPARE_OBJWIN \
|
||||||
int objwinSlowPath = renderer->dispcnt.objwinEnable; \
|
int objwinSlowPath = renderer->dispcnt.objwinEnable; \
|
||||||
int objwinOnly = 0; \
|
int objwinOnly = 0; \
|
||||||
|
int objwinForceEnable = 0; \
|
||||||
|
color_t* objwinPalette; \
|
||||||
if (objwinSlowPath) { \
|
if (objwinSlowPath) { \
|
||||||
|
if (background->target1 && renderer->objwin.blendEnable && (renderer->blendEffect == BLEND_BRIGHTEN || renderer->blendEffect == BLEND_DARKEN)) { \
|
||||||
|
objwinPalette = renderer->variantPalette; \
|
||||||
|
} else { \
|
||||||
|
objwinPalette = renderer->normalPalette; \
|
||||||
|
} \
|
||||||
switch (background->index) { \
|
switch (background->index) { \
|
||||||
case 0: \
|
case 0: \
|
||||||
objwinSlowPath = renderer->objwin.bg0Enable != renderer->currentWindow.bg0Enable; \
|
objwinForceEnable = renderer->objwin.bg0Enable && renderer->currentWindow.bg0Enable; \
|
||||||
objwinOnly = renderer->objwin.bg0Enable; \
|
objwinOnly = !renderer->objwin.bg0Enable; \
|
||||||
break; \
|
break; \
|
||||||
case 1: \
|
case 1: \
|
||||||
objwinSlowPath = renderer->objwin.bg1Enable != renderer->currentWindow.bg1Enable; \
|
objwinForceEnable = renderer->objwin.bg1Enable && renderer->currentWindow.bg1Enable; \
|
||||||
objwinOnly = renderer->objwin.bg1Enable; \
|
objwinOnly = !renderer->objwin.bg1Enable; \
|
||||||
break; \
|
break; \
|
||||||
case 2: \
|
case 2: \
|
||||||
objwinSlowPath = renderer->objwin.bg2Enable != renderer->currentWindow.bg2Enable; \
|
objwinForceEnable = renderer->objwin.bg2Enable && renderer->currentWindow.bg2Enable; \
|
||||||
objwinOnly = renderer->objwin.bg2Enable; \
|
objwinOnly = !renderer->objwin.bg2Enable; \
|
||||||
break; \
|
break; \
|
||||||
case 3: \
|
case 3: \
|
||||||
objwinSlowPath = renderer->objwin.bg3Enable != renderer->currentWindow.bg3Enable; \
|
objwinForceEnable = renderer->objwin.bg3Enable && renderer->currentWindow.bg3Enable; \
|
||||||
objwinOnly = renderer->objwin.bg3Enable; \
|
objwinOnly = !renderer->objwin.bg3Enable; \
|
||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
@ -812,7 +825,6 @@ static void _drawBackgroundMode0(struct GBAVideoSoftwareRenderer* renderer, stru
|
||||||
int inX = renderer->start + background->x;
|
int inX = renderer->start + background->x;
|
||||||
int inY = y + background->y;
|
int inY = y + background->y;
|
||||||
union GBATextMapData mapData;
|
union GBATextMapData mapData;
|
||||||
PREPARE_OBJWIN;
|
|
||||||
|
|
||||||
unsigned yBase = inY & 0xF8;
|
unsigned yBase = inY & 0xF8;
|
||||||
if (background->size == 2) {
|
if (background->size == 2) {
|
||||||
|
@ -837,6 +849,7 @@ static void _drawBackgroundMode0(struct GBAVideoSoftwareRenderer* renderer, stru
|
||||||
if (variant) {
|
if (variant) {
|
||||||
palette = renderer->variantPalette;
|
palette = renderer->variantPalette;
|
||||||
}
|
}
|
||||||
|
PREPARE_OBJWIN;
|
||||||
|
|
||||||
int outX = renderer->start;
|
int outX = renderer->start;
|
||||||
int tileX = 0;
|
int tileX = 0;
|
||||||
|
@ -956,7 +969,12 @@ static void _drawBackgroundMode0(struct GBAVideoSoftwareRenderer* renderer, stru
|
||||||
int flags = (background->priority << OFFSET_PRIORITY) | FLAG_IS_BACKGROUND; \
|
int flags = (background->priority << OFFSET_PRIORITY) | FLAG_IS_BACKGROUND; \
|
||||||
flags |= FLAG_TARGET_1 * (background->target1 && renderer->blendEffect == BLEND_ALPHA); \
|
flags |= FLAG_TARGET_1 * (background->target1 && renderer->blendEffect == BLEND_ALPHA); \
|
||||||
flags |= FLAG_TARGET_2 * background->target2; \
|
flags |= FLAG_TARGET_2 * background->target2; \
|
||||||
int variant = background->target1 && renderer->currentWindow.blendEnable && (renderer->blendEffect == BLEND_BRIGHTEN || renderer->blendEffect == BLEND_DARKEN);
|
int variant = background->target1 && renderer->currentWindow.blendEnable && (renderer->blendEffect == BLEND_BRIGHTEN || renderer->blendEffect == BLEND_DARKEN); \
|
||||||
|
color_t* palette = renderer->normalPalette; \
|
||||||
|
if (variant) { \
|
||||||
|
palette = renderer->variantPalette; \
|
||||||
|
} \
|
||||||
|
PREPARE_OBJWIN;
|
||||||
|
|
||||||
#define BACKGROUND_BITMAP_ITERATE(W, H) \
|
#define BACKGROUND_BITMAP_ITERATE(W, H) \
|
||||||
x += background->dx; \
|
x += background->dx; \
|
||||||
|
@ -973,7 +991,6 @@ static void _drawBackgroundMode2(struct GBAVideoSoftwareRenderer* renderer, stru
|
||||||
int sizeAdjusted = 0x8000 << background->size;
|
int sizeAdjusted = 0x8000 << background->size;
|
||||||
|
|
||||||
BACKGROUND_BITMAP_INIT;
|
BACKGROUND_BITMAP_INIT;
|
||||||
PREPARE_OBJWIN;
|
|
||||||
|
|
||||||
uint32_t screenBase = background->screenBase;
|
uint32_t screenBase = background->screenBase;
|
||||||
uint32_t charBase = background->charBase;
|
uint32_t charBase = background->charBase;
|
||||||
|
@ -998,11 +1015,12 @@ static void _drawBackgroundMode2(struct GBAVideoSoftwareRenderer* renderer, stru
|
||||||
tileData = ((uint8_t*)renderer->d.vram)[charBase + (mapData << 6) + ((localY & 0x700) >> 5) + ((localX & 0x700) >> 8)];
|
tileData = ((uint8_t*)renderer->d.vram)[charBase + (mapData << 6) + ((localY & 0x700) >> 5) + ((localX & 0x700) >> 8)];
|
||||||
|
|
||||||
uint32_t current = renderer->row[outX];
|
uint32_t current = renderer->row[outX];
|
||||||
if (tileData && !(current & FLAG_FINALIZED) && (!objwinSlowPath || !(current & FLAG_OBJWIN) != objwinOnly)) {
|
if (tileData && !(current & FLAG_FINALIZED)) {
|
||||||
if (!variant) {
|
if (!objwinSlowPath) {
|
||||||
_composite(renderer, outX, renderer->normalPalette[tileData] | flags, current);
|
_composite(renderer, outX, palette[tileData] | flags, current);
|
||||||
} else {
|
} else if (objwinForceEnable || !(current & FLAG_OBJWIN) == objwinOnly) {
|
||||||
_composite(renderer, outX, renderer->variantPalette[tileData] | flags, current);
|
color_t* currentPalette = (current & FLAG_OBJWIN) ? objwinPalette : palette;
|
||||||
|
_composite(renderer, outX, currentPalette[tileData] | flags, current);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1010,7 +1028,6 @@ static void _drawBackgroundMode2(struct GBAVideoSoftwareRenderer* renderer, stru
|
||||||
|
|
||||||
static void _drawBackgroundMode3(struct GBAVideoSoftwareRenderer* renderer, struct GBAVideoSoftwareBackground* background, int unused) {
|
static void _drawBackgroundMode3(struct GBAVideoSoftwareRenderer* renderer, struct GBAVideoSoftwareBackground* background, int unused) {
|
||||||
BACKGROUND_BITMAP_INIT;
|
BACKGROUND_BITMAP_INIT;
|
||||||
PREPARE_OBJWIN;
|
|
||||||
|
|
||||||
uint16_t color;
|
uint16_t color;
|
||||||
uint32_t color32;
|
uint32_t color32;
|
||||||
|
@ -1040,7 +1057,6 @@ static void _drawBackgroundMode3(struct GBAVideoSoftwareRenderer* renderer, stru
|
||||||
|
|
||||||
static void _drawBackgroundMode4(struct GBAVideoSoftwareRenderer* renderer, struct GBAVideoSoftwareBackground* background, int unused) {
|
static void _drawBackgroundMode4(struct GBAVideoSoftwareRenderer* renderer, struct GBAVideoSoftwareBackground* background, int unused) {
|
||||||
BACKGROUND_BITMAP_INIT;
|
BACKGROUND_BITMAP_INIT;
|
||||||
PREPARE_OBJWIN;
|
|
||||||
|
|
||||||
uint16_t color;
|
uint16_t color;
|
||||||
uint32_t offset = 0;
|
uint32_t offset = 0;
|
||||||
|
@ -1067,7 +1083,6 @@ static void _drawBackgroundMode4(struct GBAVideoSoftwareRenderer* renderer, stru
|
||||||
|
|
||||||
static void _drawBackgroundMode5(struct GBAVideoSoftwareRenderer* renderer, struct GBAVideoSoftwareBackground* background, int unused) {
|
static void _drawBackgroundMode5(struct GBAVideoSoftwareRenderer* renderer, struct GBAVideoSoftwareBackground* background, int unused) {
|
||||||
BACKGROUND_BITMAP_INIT;
|
BACKGROUND_BITMAP_INIT;
|
||||||
PREPARE_OBJWIN;
|
|
||||||
|
|
||||||
uint32_t color;
|
uint32_t color;
|
||||||
uint32_t offset = 0;
|
uint32_t offset = 0;
|
||||||
|
|
Loading…
Reference in New Issue