From 6e9cd355a5c78c65d20e6b502573d3c17ff8af5d Mon Sep 17 00:00:00 2001 From: StapleButter Date: Tue, 11 Nov 2014 00:12:31 +0100 Subject: [PATCH] Scissor test. (if calling SetScissorTest right after SetViewport, call FinishDrawing inbetween) --- libctru/include/3ds/gpu/gpu.h | 11 +++++++++++ libctru/source/gpu/gpu.c | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/libctru/include/3ds/gpu/gpu.h b/libctru/include/3ds/gpu/gpu.h index c865867..5700d93 100644 --- a/libctru/include/3ds/gpu/gpu.h +++ b/libctru/include/3ds/gpu/gpu.h @@ -65,6 +65,15 @@ typedef enum GPU_GEQUAL = 7 }GPU_TESTFUNC; +typedef enum +{ + GPU_SCISSOR_DISABLE = 0, // disable scissor test + GPU_SCISSOR_INVERT = 1, // exclude pixels inside the scissor box + // 2 is the same as 0 + GPU_SCISSOR_NORMAL = 3, // exclude pixels outside of the scissor box + +} GPU_SCISSORMODE; + typedef enum { GPU_KEEP = 0, // keep destination value @@ -183,6 +192,8 @@ void GPU_SetUniform(u32 startreg, u32* data, u32 numreg); void GPU_SetViewport(u32* depthBuffer, u32* colorBuffer, u32 x, u32 y, u32 w, u32 h); +void GPU_SetScissorTest(GPU_SCISSORMODE mode, u32 x, u32 y, u32 w, u32 h); + void GPU_DepthRange(float nearVal, float farVal); void GPU_SetAlphaTest(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 diff --git a/libctru/source/gpu/gpu.c b/libctru/source/gpu/gpu.c index 8bfde8b..c83a9aa 100644 --- a/libctru/source/gpu/gpu.c +++ b/libctru/source/gpu/gpu.c @@ -304,6 +304,16 @@ void GPU_SetViewport(u32* depthBuffer, u32* colorBuffer, u32 x, u32 y, u32 w, u3 GPUCMD_Add(0x800F0112, param, 0x00000004); } +void GPU_SetScissorTest(GPU_SCISSORMODE mode, u32 x, u32 y, u32 w, u32 h) +{ + u32 param[3]; + + param[0x0] = mode; + param[0x1] = (y<<16)|(x&0xFFFF); + param[0x2] = ((h-1)<<16)|((w-1)&0xFFFF); + GPUCMD_Add(0x800F0065, param, 0x00000003); +} + void GPU_DepthRange(float nearVal, float farVal) { GPUCMD_AddSingleParam(0x000F006D, 0x00000001); //?