DS GX: Add color modulation
Vicki Pfau vi@endrift.com
Fri, 03 Mar 2017 18:37:48 -0800
3 files changed,
24 insertions(+),
1 deletions(-)
M
include/mgba/internal/ds/gx.h
→
include/mgba/internal/ds/gx.h
@@ -47,6 +47,16 @@ DECL_BITS(DSGXTexParams, Format, 26, 3);
DECL_BIT(DSGXTexParams, 0Transparent, 29); DECL_BITS(DSGXTexParams, CoordTfMode, 30, 2); +DECL_BITFIELD(DSGXPolygonAttrs, uint32_t); +DECL_BIT(DSGXPolygonAttrs, Light0, 0); +DECL_BIT(DSGXPolygonAttrs, Light1, 1); +DECL_BIT(DSGXPolygonAttrs, Light2, 2); +DECL_BIT(DSGXPolygonAttrs, Light3, 3); +DECL_BITS(DSGXPolygonAttrs, Mode, 4, 2); +DECL_BIT(DSGXPolygonAttrs, FrontFace, 6); +DECL_BIT(DSGXPolygonAttrs, BackFace, 7); +// TODO + enum DSGXCommand { DS_GX_CMD_NOP = 0, DS_GX_CMD_MTX_MODE = 0x10,
M
include/mgba/internal/ds/gx/software.h
→
include/mgba/internal/ds/gx/software.h
@@ -20,6 +20,7 @@ struct DSGXPolygon* poly;
uint16_t* texBase; uint16_t* palBase; int texFormat; + int blendFormat; int texW; int texH; };
M
src/ds/gx/software.c
→
src/ds/gx/software.c
@@ -109,9 +109,20 @@ if (DSGXTexParamsIs0Transparent(poly->poly->texParams) && !texel) {
return FLAG_UNWRITTEN; } uint8_t r, g, b; + unsigned wr, wg, wb; texel = poly->palBase[texel]; _expandColor(texel, &r, &g, &b); - return _finishColor(r, g, b); + switch (poly->blendFormat) { + case 1: + default: + // TODO: Alpha + return _finishColor(r, g, b); + 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); + } } static int _edgeSort(const void* a, const void* b) {@@ -285,6 +296,7 @@ struct DSGXSoftwarePolygon* poly = DSGXSoftwarePolygonListAppend(&softwareRenderer->activePolys);
struct DSGXSoftwareEdge* edge = DSGXSoftwareEdgeListAppend(&softwareRenderer->activeEdges); poly->poly = &polys[i]; poly->texFormat = DSGXTexParamsGetFormat(poly->poly->texParams); + poly->blendFormat = DSGXPolygonAttrsGetMode(poly->poly->polyParams); poly->texW = 8 << DSGXTexParamsGetSSize(poly->poly->texParams); poly->texH = 8 << DSGXTexParamsGetTSize(poly->poly->texParams); switch (poly->texFormat) {