mirror of https://github.com/mgba-emu/mgba.git
DS GX: Start work on alpha
This commit is contained in:
parent
61ef3501c1
commit
32f63d7d93
|
@ -28,12 +28,13 @@ static void _expandColor(uint16_t c15, uint8_t* r, uint8_t* g, uint8_t* b) {
|
||||||
*b = ((c15 >> 9) & 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
|
#ifndef COLOR_16_BIT
|
||||||
color_t rgb = (r << 2) & 0xF8;
|
color_t rgba = (r << 2) & 0xF8;
|
||||||
rgb |= (g << 10) & 0xF800;
|
rgba |= (g << 10) & 0xF800;
|
||||||
rgb |= (b << 18) & 0xF80000;
|
rgba |= (b << 18) & 0xF80000;
|
||||||
return rgb;
|
rgba |= (a << 27) & 0xF8000000;
|
||||||
|
return rgba;
|
||||||
#else
|
#else
|
||||||
#error Unsupported color depth
|
#error Unsupported color depth
|
||||||
#endif
|
#endif
|
||||||
|
@ -75,12 +76,17 @@ static color_t _lookupColor(struct DSGXSoftwareEndpoint* ep, struct DSGXSoftware
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t texelCoord = s + t * poly->texW;
|
uint16_t texelCoord = s + t * poly->texW;
|
||||||
|
uint8_t a = 0x1F;
|
||||||
switch (poly->texFormat) {
|
switch (poly->texFormat) {
|
||||||
case 0:
|
case 0:
|
||||||
default:
|
default:
|
||||||
return _finishColor(ep->cr, ep->cg, ep->cb);
|
return _finishColor(ep->cr, ep->cg, ep->cb, 0x1F);
|
||||||
case 1:
|
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:
|
case 2:
|
||||||
texel = ((uint8_t*) poly->texBase)[texelCoord >> 2];
|
texel = ((uint8_t*) poly->texBase)[texelCoord >> 2];
|
||||||
if (texelCoord & 0x3) {
|
if (texelCoord & 0x3) {
|
||||||
|
@ -99,14 +105,17 @@ static color_t _lookupColor(struct DSGXSoftwareEndpoint* ep, struct DSGXSoftware
|
||||||
texel = ((uint8_t*) poly->texBase)[texelCoord];
|
texel = ((uint8_t*) poly->texBase)[texelCoord];
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
return _finishColor(0x3F, 0, 0x3F);
|
return _finishColor(0x3F, 0, 0x3F, 0x1F);
|
||||||
case 6:
|
case 6:
|
||||||
return _finishColor(0x3F, 0x3F, 0);
|
texel = ((uint8_t*) poly->texBase)[texelCoord];
|
||||||
|
a = (texel >> 3) & 0x1F;
|
||||||
|
texel &= 0x7;
|
||||||
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
return _finishColor(0x3F, 0x3F, 0x3F);
|
return _finishColor(0x3F, 0x3F, 0x3F, 0x1F);
|
||||||
}
|
}
|
||||||
if (DSGXTexParamsIs0Transparent(poly->poly->texParams) && !texel) {
|
if (DSGXTexParamsIs0Transparent(poly->poly->texParams) && !texel) {
|
||||||
return FLAG_UNWRITTEN;
|
return 0;
|
||||||
}
|
}
|
||||||
uint8_t r, g, b;
|
uint8_t r, g, b;
|
||||||
unsigned wr, wg, wb;
|
unsigned wr, wg, wb;
|
||||||
|
@ -116,12 +125,12 @@ static color_t _lookupColor(struct DSGXSoftwareEndpoint* ep, struct DSGXSoftware
|
||||||
case 1:
|
case 1:
|
||||||
default:
|
default:
|
||||||
// TODO: Alpha
|
// TODO: Alpha
|
||||||
return _finishColor(r, g, b);
|
return _finishColor(r, g, b, a);
|
||||||
case 0:
|
case 0:
|
||||||
wr = ((r + 1) * (ep->cr + 1) - 1) >> 6;
|
wr = ((r + 1) * (ep->cr + 1) - 1) >> 6;
|
||||||
wg = ((g + 1) * (ep->cg + 1) - 1) >> 6;
|
wg = ((g + 1) * (ep->cg + 1) - 1) >> 6;
|
||||||
wb = ((b + 1) * (ep->cb + 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 @@ static void DSGXSoftwareRendererDrawScanline(struct DSGXRenderer* renderer, int
|
||||||
struct DSGXSoftwareSpan* span = NULL;
|
struct DSGXSoftwareSpan* span = NULL;
|
||||||
struct DSGXSoftwareEndpoint ep;
|
struct DSGXSoftwareEndpoint ep;
|
||||||
int32_t depth = INT32_MAX;
|
int32_t depth = INT32_MAX;
|
||||||
scanline[i] = FLAG_UNWRITTEN;
|
scanline[i] = 0;
|
||||||
if (i >= nextSpanX) {
|
if (i >= nextSpanX) {
|
||||||
size_t nextSpanId = DSGXSoftwareSpanListSize(&softwareRenderer->activeSpans);
|
size_t nextSpanId = DSGXSoftwareSpanListSize(&softwareRenderer->activeSpans);
|
||||||
span = DSGXSoftwareSpanListGetPointer(&softwareRenderer->activeSpans, nextSpanId - 1);
|
span = DSGXSoftwareSpanListGetPointer(&softwareRenderer->activeSpans, nextSpanId - 1);
|
||||||
|
@ -466,7 +475,8 @@ static void DSGXSoftwareRendererDrawScanline(struct DSGXRenderer* renderer, int
|
||||||
if (i <= (span->ep[1].x >> 12)) {
|
if (i <= (span->ep[1].x >> 12)) {
|
||||||
_lerpEndpoint(span, &ep, i);
|
_lerpEndpoint(span, &ep, i);
|
||||||
color_t color = _lookupColor(&ep, span->poly);
|
color_t color = _lookupColor(&ep, span->poly);
|
||||||
if (color != FLAG_UNWRITTEN) {
|
if (color & 0xF8000000) {
|
||||||
|
// TODO: Alpha
|
||||||
if (softwareRenderer->wSort) {
|
if (softwareRenderer->wSort) {
|
||||||
if (ep.w < depth) {
|
if (ep.w < depth) {
|
||||||
depth = ep.w;
|
depth = ep.w;
|
||||||
|
|
|
@ -391,8 +391,8 @@ static void DSVideoSoftwareRendererDrawGBAScanline(struct GBAVideoRenderer* rend
|
||||||
flags |= FLAG_TARGET_1 * (softwareRenderer->bg[0].target1 && softwareRenderer->blendEffect == BLEND_ALPHA && GBAWindowControlIsBlendEnable(softwareRenderer->currentWindow.packed));
|
flags |= FLAG_TARGET_1 * (softwareRenderer->bg[0].target1 && softwareRenderer->blendEffect == BLEND_ALPHA && GBAWindowControlIsBlendEnable(softwareRenderer->currentWindow.packed));
|
||||||
int x;
|
int x;
|
||||||
for (x = softwareRenderer->start; x < softwareRenderer->end; ++x) {
|
for (x = softwareRenderer->start; x < softwareRenderer->end; ++x) {
|
||||||
if ((scanline[x] & FLAG_UNWRITTEN) != FLAG_UNWRITTEN) {
|
if (scanline[x] & 0xF8000000) {
|
||||||
_compositeBlendNoObjwin(softwareRenderer, &softwareRenderer->row[x], scanline[x] | flags, softwareRenderer->row[x]);
|
_compositeBlendNoObjwin(softwareRenderer, &softwareRenderer->row[x], (scanline[x] & 0x00FFFFFF) | flags, softwareRenderer->row[x]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue