From a41dac3e3a813ee53c98a9d38fd2f2ede6c91e56 Mon Sep 17 00:00:00 2001 From: fincs Date: Sun, 2 Apr 2017 17:14:49 +0200 Subject: [PATCH] Add C3D_EarlyDepthTest() {currently unusable due to glitchy rendering} --- include/c3d/effect.h | 1 + source/base.c | 1 + source/effect.c | 16 ++++++++++++---- source/internal.h | 4 +++- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/include/c3d/effect.h b/include/c3d/effect.h index b128921..26e3617 100644 --- a/include/c3d/effect.h +++ b/include/c3d/effect.h @@ -6,6 +6,7 @@ void C3D_CullFace(GPU_CULLMODE mode); void C3D_StencilTest(bool enable, GPU_TESTFUNC function, int ref, int inputMask, int writeMask); void C3D_StencilOp(GPU_STENCILOP sfail, GPU_STENCILOP dfail, GPU_STENCILOP pass); void C3D_BlendingColor(u32 color); +void C3D_EarlyDepthTest(bool enable, GPU_EARLYDEPTHFUNC function, u32 ref); void C3D_DepthTest(bool enable, GPU_TESTFUNC function, GPU_WRITEMASK writemask); void C3D_AlphaTest(bool enable, GPU_TESTFUNC function, int ref); void C3D_AlphaBlend(GPU_BLENDEQUATION colorEq, GPU_BLENDEQUATION alphaEq, GPU_BLENDFACTOR srcClr, GPU_BLENDFACTOR dstClr, GPU_BLENDFACTOR srcAlpha, GPU_BLENDFACTOR dstAlpha); diff --git a/source/base.c b/source/base.c index 2371e28..dfb2c12 100644 --- a/source/base.c +++ b/source/base.c @@ -104,6 +104,7 @@ bool C3D_Init(size_t cmdBufSize) C3D_StencilTest(false, GPU_ALWAYS, 0x00, 0xFF, 0x00); C3D_StencilOp(GPU_STENCIL_KEEP, GPU_STENCIL_KEEP, GPU_STENCIL_KEEP); C3D_BlendingColor(0); + C3D_EarlyDepthTest(false, GPU_EARLYDEPTH_GREATER, 0); C3D_DepthTest(true, GPU_GREATER, GPU_WRITE_ALL); C3D_AlphaTest(false, GPU_ALWAYS, 0x00); C3D_AlphaBlend(GPU_BLEND_ADD, GPU_BLEND_ADD, GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA); diff --git a/source/effect.c b/source/effect.c index 038f5f6..7142afe 100644 --- a/source/effect.c +++ b/source/effect.c @@ -39,6 +39,14 @@ void C3D_BlendingColor(u32 color) e->blendClr = color; } +void C3D_EarlyDepthTest(bool enable, GPU_EARLYDEPTHFUNC function, u32 ref) +{ + C3D_Effect* e = getEffect(); + e->earlyDepth = enable; + e->earlyDepthFunc = function; + e->earlyDepthRef = ref; +} + void C3D_DepthTest(bool enable, GPU_TESTFUNC function, GPU_WRITEMASK writemask) { C3D_Effect* e = getEffect(); @@ -90,8 +98,8 @@ void C3Di_EffectBind(C3D_Effect* e) GPUCMD_AddWrite(GPUREG_LOGIC_OP, e->clrLogicOp); GPUCMD_AddMaskedWrite(GPUREG_COLOR_OPERATION, 7, e->fragOpMode); GPUCMD_AddWrite(GPUREG_FRAGOP_SHADOW, e->fragOpShadow); - - // Disable early depth test? - GPUCMD_AddMaskedWrite(GPUREG_EARLYDEPTH_TEST1, 1, 0); - GPUCMD_AddWrite(GPUREG_EARLYDEPTH_TEST2, 0); + GPUCMD_AddMaskedWrite(GPUREG_EARLYDEPTH_TEST1, 1, e->earlyDepth ? 1 : 0); + GPUCMD_AddWrite(GPUREG_EARLYDEPTH_TEST2, e->earlyDepth ? 1 : 0); + GPUCMD_AddMaskedWrite(GPUREG_EARLYDEPTH_FUNC, 1, e->earlyDepthFunc); + GPUCMD_AddMaskedWrite(GPUREG_EARLYDEPTH_DATA, 0x7, e->earlyDepthRef); } diff --git a/source/internal.h b/source/internal.h index 60aeb5a..e9321ac 100644 --- a/source/internal.h +++ b/source/internal.h @@ -14,7 +14,9 @@ typedef struct u32 fragOpShadow; u32 zScale, zOffset; GPU_CULLMODE cullMode; - bool zBuffer; + bool zBuffer, earlyDepth; + GPU_EARLYDEPTHFUNC earlyDepthFunc; + u32 earlyDepthRef; u32 alphaTest; u32 stencilMode, stencilOp;