diff --git a/libctru/include/3ds/gpu/gpu.h b/libctru/include/3ds/gpu/gpu.h index aaceb0a..16f5b8f 100644 --- a/libctru/include/3ds/gpu/gpu.h +++ b/libctru/include/3ds/gpu/gpu.h @@ -44,6 +44,26 @@ typedef enum GPU_GEQUAL = 7 }GPU_TESTFUNC; +typedef enum +{ + GPU_KEEP = 0, // keep destination value + GPU_AND_NOT = 1, // destination & ~source + GPU_XOR = 5, // destination ^ source + // 2 is the same as 1. Other values are too weird to even be usable. +} GPU_STENCILOP; + +typedef enum +{ + GPU_WRITE_RED = 0x01, + GPU_WRITE_GREEN = 0x02, + GPU_WRITE_BLUE = 0x04, + GPU_WRITE_ALPHA = 0x08, + GPU_WRITE_DEPTH = 0x10, + + GPU_WRITE_COLOR = 0x0F, + GPU_WRITE_ALL = 0x1F +} GPU_WRITEMASK; + typedef enum { GPU_BLEND_ADD = 0, @@ -144,8 +164,9 @@ void GPU_SetViewport(u32* depthBuffer, u32* colorBuffer, u32 x, u32 y, u32 w, u3 void GPU_DepthRange(float nearVal, float farVal); void GPU_SetAlphaTest(bool enable, GPU_TESTFUNC function, u8 ref); -void GPU_SetDepthTest(bool enable, GPU_TESTFUNC function, u8 ref); -void GPU_SetStencilTest(bool enable, GPU_TESTFUNC function, u8 ref); +void GPU_SetDepthTestAndWriteMask(bool enable, GPU_TESTFUNC function, GPU_WRITEMASK writemask); // GPU_WRITEMASK values can be ORed together +void GPU_SetStencilTest(bool enable, GPU_TESTFUNC function, u8 ref, u8 mask, u8 replace); +void GPU_SetStencilOp(GPU_STENCILOP sfail, GPU_STENCILOP dfail, GPU_STENCILOP pass); void GPU_SetFaceCulling(GPU_CULLMODE mode); // these two can't be used together @@ -154,6 +175,8 @@ void GPU_SetAlphaBlending(GPU_BLENDEQUATION colorEquation, GPU_BLENDEQUATION alp GPU_BLENDFACTOR alphaSrc, GPU_BLENDFACTOR alphaDst); void GPU_SetColorLogicOp(GPU_LOGICOP op); +void GPU_SetBlendingColor(u8 r, u8 g, u8 b, u8 a); + void GPU_SetAttributeBuffers(u8 totalAttributes, u32* baseAddress, u64 attributeFormats, u16 attributeMask, u64 attributePermutation, u8 numBuffers, u32 bufferOffsets[], u64 bufferPermutations[], u8 bufferNumAttributes[]); void GPU_SetTextureEnable(GPU_TEXUNIT units); // GPU_TEXUNITx values can be ORed together to enable multiple texture units diff --git a/libctru/source/gpu/gpu.c b/libctru/source/gpu/gpu.c index 835f1ff..96ad76e 100644 --- a/libctru/source/gpu/gpu.c +++ b/libctru/source/gpu/gpu.c @@ -294,23 +294,25 @@ void GPU_SetAlphaTest(bool enable, GPU_TESTFUNC function, u8 ref) GPUCMD_AddSingleParam(0x000F0104, (enable&1)|((function&7)<<4)|(ref<<8)); } -void GPU_SetStencilTest(bool enable, GPU_TESTFUNC function, u8 ref) +void GPU_SetStencilTest(bool enable, GPU_TESTFUNC function, u8 ref, u8 mask, u8 replace) { - GPUCMD_AddSingleParam(0x000F0105, (enable&1)|((function&7)<<4)|(ref<<8)); + GPUCMD_AddSingleParam(0x000F0105, (enable&1)|((function&7)<<4)|(replace<<8)|(ref<<16)|(mask<<24)); } -void GPU_SetDepthTest(bool enable, GPU_TESTFUNC function, u8 ref) +void GPU_SetStencilOp(GPU_STENCILOP sfail, GPU_STENCILOP dfail, GPU_STENCILOP pass) { - GPUCMD_AddSingleParam(0x000F0107, (enable&1)|((function&7)<<4)|(ref<<8)); + GPUCMD_AddSingleParam(0x000F0106, sfail | (dfail << 4) | (pass << 8)); +} + +void GPU_SetDepthTestAndWriteMask(bool enable, GPU_TESTFUNC function, GPU_WRITEMASK writemask) +{ + GPUCMD_AddSingleParam(0x000F0107, (enable&1)|((function&7)<<4)|(writemask<<8)); } void GPU_SetAlphaBlending(GPU_BLENDEQUATION colorEquation, GPU_BLENDEQUATION alphaEquation, GPU_BLENDFACTOR colorSrc, GPU_BLENDFACTOR colorDst, GPU_BLENDFACTOR alphaSrc, GPU_BLENDFACTOR alphaDst) { - // TODO: fixed color - // it is controlled by command 0103 but I haven't found were to place said command without freezing the GPU - GPUCMD_AddSingleParam(0x000F0101, colorEquation | (alphaEquation<<8) | (colorSrc<<16) | (colorDst<<20) | (alphaSrc<<24) | (alphaDst<<28)); GPUCMD_AddSingleParam(0x00020100, 0x00000100); } @@ -321,6 +323,11 @@ void GPU_SetColorLogicOp(GPU_LOGICOP op) GPUCMD_AddSingleParam(0x00020100, 0x00000000); } +void GPU_SetBlendingColor(u8 r, u8 g, u8 b, u8 a) +{ + GPUCMD_AddSingleParam(0x000F0103, r | (g << 8) | (b << 16) | (a << 24)); +} + void GPU_SetTextureEnable(GPU_TEXUNIT units) { GPUCMD_AddSingleParam(0x0002006F, units<<8); // enables texcoord outputs