all repos — mgba @ 40b00e7927990c1b8976572dfb8baecf824f7d03

mGBA Game Boy Advance Emulator

Refactor some code to enable compositing code to be shared
Jeffrey Pfau jeffrey@endrift.com
Wed, 24 Apr 2013 00:50:17 -0700
commit

40b00e7927990c1b8976572dfb8baecf824f7d03

parent

0d7657e845987841ada3f4490e7d2f3181dbc189

2 files changed, 23 insertions(+), 9 deletions(-)

jump to
M src/gba/renderers/video-software.csrc/gba/renderers/video-software.c

@@ -16,7 +16,8 @@ static void GBAVideoSoftwareRendererUpdateDISPCNT(struct GBAVideoSoftwareRenderer* renderer);

static void GBAVideoSoftwareRendererWriteBGCNT(struct GBAVideoSoftwareRenderer* renderer, struct GBAVideoSoftwareBackground* bg, uint16_t value); static void GBAVideoSoftwareRendererWriteBLDCNT(struct GBAVideoSoftwareRenderer* renderer, uint16_t value); -static void _drawBackgroundMode0(struct GBAVideoSoftwareRenderer* renderer, struct GBAVideoSoftwareBackground* background, uint16_t* output, int y); +static void _composite(struct GBAVideoSoftwareRenderer* renderer, int offset, int entry, struct PixelFlags flags); +static void _drawBackgroundMode0(struct GBAVideoSoftwareRenderer* renderer, struct GBAVideoSoftwareBackground* background, int y); static void _updatePalettes(struct GBAVideoSoftwareRenderer* renderer); static inline uint16_t _brighten(uint16_t color, int y);

@@ -182,10 +183,11 @@ return;

} memset(softwareRenderer->flags, 0, sizeof(softwareRenderer->flags)); + softwareRenderer->row = row; for (int i = 0; i < 4; ++i) { if (softwareRenderer->sortedBg[i]->enabled) { - _drawBackgroundMode0(softwareRenderer, softwareRenderer->sortedBg[i], row, y); + _drawBackgroundMode0(softwareRenderer, softwareRenderer->sortedBg[i], y); } } }

@@ -263,8 +265,16 @@ _updatePalettes(renderer);

} } +static void _composite(struct GBAVideoSoftwareRenderer* renderer, int offset, int entry, struct PixelFlags flags) { + if (renderer->blendEffect == BLEND_NONE || !flags.target1) { + renderer->row[offset] = renderer->d.palette[entry]; + } else if (renderer->blendEffect == BLEND_BRIGHTEN || renderer->blendEffect == BLEND_DARKEN) { + renderer->row[offset] = renderer->variantPalette[entry]; + } + renderer->flags[offset].finalized = 1; +} -static void _drawBackgroundMode0(struct GBAVideoSoftwareRenderer* renderer, struct GBAVideoSoftwareBackground* background, uint16_t* output, int y) { +static void _drawBackgroundMode0(struct GBAVideoSoftwareRenderer* renderer, struct GBAVideoSoftwareBackground* background, int y) { int start = 0; int end = VIDEO_HORIZONTAL_PIXELS; int inX = start + background->x;

@@ -297,12 +307,12 @@ charBase = ((background->charBase + (mapData.tile << 5)) >> 1) + ((inY & 0x7) << 1) + (((outX + inX) >> 2) & 1);

uint16_t tileData = renderer->d.vram[charBase]; tileData >>= ((outX + inX) & 0x3) << 2; if (tileData & 0xF) { - if (renderer->blendEffect == BLEND_NONE || !background->target1) { - output[outX] = renderer->d.palette[(tileData & 0xF) | (mapData.palette << 4)]; - } else if (renderer->blendEffect == BLEND_BRIGHTEN || renderer->blendEffect == BLEND_DARKEN) { - output[outX] = renderer->variantPalette[(tileData & 0xF) | (mapData.palette << 4)]; - } - renderer->flags[outX].finalized = 1; + struct PixelFlags flags = { + .finalized = 1, + .target1 = background->target1, + .target2 = background->target2 + }; + _composite(renderer, outX, (tileData & 0xF) | (mapData.palette << 4), flags); } } }
M src/gba/renderers/video-software.hsrc/gba/renderers/video-software.h

@@ -38,6 +38,8 @@ };

struct PixelFlags { unsigned finalized : 1; + unsigned target1 : 1; + unsigned target2 : 1; }; struct GBAVideoSoftwareRenderer {

@@ -62,6 +64,8 @@ uint16_t bldy;

struct GBAVideoSoftwareBackground bg[4]; struct GBAVideoSoftwareBackground* sortedBg[4]; + + uint16_t* row; pthread_mutex_t mutex; pthread_cond_t cond;