all repos — mgba @ 32f63d7d93af8407268520df093c258bd02b3d7e

mGBA Game Boy Advance Emulator

DS GX: Start work on alpha
Vicki Pfau vi@endrift.com
Fri, 03 Mar 2017 19:33:09 -0800
commit

32f63d7d93af8407268520df093c258bd02b3d7e

parent

61ef3501c115bbaaced8f9c78685243ed4f31881

2 files changed, 27 insertions(+), 17 deletions(-)

jump to
M src/ds/gx/software.csrc/ds/gx/software.c

@@ -28,12 +28,13 @@ *g = ((c15 >> 4) & 0x3E) | 1;

*b = ((c15 >> 9) & 0x3E) | 1; } -static color_t _finishColor(uint8_t r, uint8_t g, uint8_t b) { +static color_t _finishColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a) { #ifndef COLOR_16_BIT - color_t rgb = (r << 2) & 0xF8; - rgb |= (g << 10) & 0xF800; - rgb |= (b << 18) & 0xF80000; - return rgb; + color_t rgba = (r << 2) & 0xF8; + rgba |= (g << 10) & 0xF800; + rgba |= (b << 18) & 0xF80000; + rgba |= (a << 27) & 0xF8000000; + return rgba; #else #error Unsupported color depth #endif

@@ -75,12 +76,17 @@ t &= poly->texH - 1;

} uint16_t texelCoord = s + t * poly->texW; + uint8_t a = 0x1F; switch (poly->texFormat) { case 0: default: - return _finishColor(ep->cr, ep->cg, ep->cb); + return _finishColor(ep->cr, ep->cg, ep->cb, 0x1F); case 1: - return _finishColor(0, 0, 0x3F); + texel = ((uint8_t*) poly->texBase)[texelCoord]; + a = (texel >> 5) & 0x7; + a = (a << 2) + (a >> 1); + texel &= 0x1F; + break; case 2: texel = ((uint8_t*) poly->texBase)[texelCoord >> 2]; if (texelCoord & 0x3) {

@@ -99,14 +105,17 @@ case 4:

texel = ((uint8_t*) poly->texBase)[texelCoord]; break; case 5: - return _finishColor(0x3F, 0, 0x3F); + return _finishColor(0x3F, 0, 0x3F, 0x1F); case 6: - return _finishColor(0x3F, 0x3F, 0); + texel = ((uint8_t*) poly->texBase)[texelCoord]; + a = (texel >> 3) & 0x1F; + texel &= 0x7; + break; case 7: - return _finishColor(0x3F, 0x3F, 0x3F); + return _finishColor(0x3F, 0x3F, 0x3F, 0x1F); } if (DSGXTexParamsIs0Transparent(poly->poly->texParams) && !texel) { - return FLAG_UNWRITTEN; + return 0; } uint8_t r, g, b; unsigned wr, wg, wb;

@@ -116,12 +125,12 @@ switch (poly->blendFormat) {

case 1: default: // TODO: Alpha - return _finishColor(r, g, b); + return _finishColor(r, g, b, a); case 0: wr = ((r + 1) * (ep->cr + 1) - 1) >> 6; wg = ((g + 1) * (ep->cg + 1) - 1) >> 6; wb = ((b + 1) * (ep->cb + 1) - 1) >> 6; - return _finishColor(wr, wg, wb); + return _finishColor(wr, wg, wb, a); } }

@@ -447,7 +456,7 @@ for (i = 0; i < DS_VIDEO_HORIZONTAL_PIXELS; ++i) {

struct DSGXSoftwareSpan* span = NULL; struct DSGXSoftwareEndpoint ep; int32_t depth = INT32_MAX; - scanline[i] = FLAG_UNWRITTEN; + scanline[i] = 0; if (i >= nextSpanX) { size_t nextSpanId = DSGXSoftwareSpanListSize(&softwareRenderer->activeSpans); span = DSGXSoftwareSpanListGetPointer(&softwareRenderer->activeSpans, nextSpanId - 1);

@@ -466,7 +475,8 @@ while (span && i > (span->ep[0].x >> 12)) {

if (i <= (span->ep[1].x >> 12)) { _lerpEndpoint(span, &ep, i); color_t color = _lookupColor(&ep, span->poly); - if (color != FLAG_UNWRITTEN) { + if (color & 0xF8000000) { + // TODO: Alpha if (softwareRenderer->wSort) { if (ep.w < depth) { depth = ep.w;
M src/ds/renderers/software.csrc/ds/renderers/software.c

@@ -391,8 +391,8 @@ flags |= FLAG_TARGET_2 * softwareRenderer->bg[0].target2;

flags |= FLAG_TARGET_1 * (softwareRenderer->bg[0].target1 && softwareRenderer->blendEffect == BLEND_ALPHA && GBAWindowControlIsBlendEnable(softwareRenderer->currentWindow.packed)); int x; for (x = softwareRenderer->start; x < softwareRenderer->end; ++x) { - if ((scanline[x] & FLAG_UNWRITTEN) != FLAG_UNWRITTEN) { - _compositeBlendNoObjwin(softwareRenderer, &softwareRenderer->row[x], scanline[x] | flags, softwareRenderer->row[x]); + if (scanline[x] & 0xF8000000) { + _compositeBlendNoObjwin(softwareRenderer, &softwareRenderer->row[x], (scanline[x] & 0x00FFFFFF) | flags, softwareRenderer->row[x]); } } } else {