diff --git a/examples/graphics/gpu/geoshader/source/gpu.c b/examples/graphics/gpu/geoshader/source/gpu.c index abb8cdd..60b4b89 100644 --- a/examples/graphics/gpu/geoshader/source/gpu.c +++ b/examples/graphics/gpu/geoshader/source/gpu.c @@ -35,11 +35,12 @@ void gpuClearBuffers(u32 clearColor) void gpuFrameBegin(void) { - // Configure the viewport and the depth linear conversion function - GPU_SetViewport( + // Configure the output buffers, viewport and the depth linear conversion function + GPU_OutputBuffers(GPU_DEPTH24_EXT8, GPU_COLOR_RGBA8, (u32*)osConvertVirtToPhys((u32)depthBuf), (u32*)osConvertVirtToPhys((u32)colorBuf), - 0, 0, 240, 400); // The top screen is physically 240x400 pixels + 240, 400); // The top screen is physically 240x400 pixels + GPU_SetViewport(0, 0, 240, 400); GPU_DepthMap(-1.0f, 0.0f); // calculate the depth value from the Z coordinate in the following way: -1.0*z + 0.0 // Configure some boilerplate diff --git a/examples/graphics/gpu/simple_tri/source/gpu.c b/examples/graphics/gpu/simple_tri/source/gpu.c index abb8cdd..60b4b89 100644 --- a/examples/graphics/gpu/simple_tri/source/gpu.c +++ b/examples/graphics/gpu/simple_tri/source/gpu.c @@ -35,11 +35,12 @@ void gpuClearBuffers(u32 clearColor) void gpuFrameBegin(void) { - // Configure the viewport and the depth linear conversion function - GPU_SetViewport( + // Configure the output buffers, viewport and the depth linear conversion function + GPU_OutputBuffers(GPU_DEPTH24_EXT8, GPU_COLOR_RGBA8, (u32*)osConvertVirtToPhys((u32)depthBuf), (u32*)osConvertVirtToPhys((u32)colorBuf), - 0, 0, 240, 400); // The top screen is physically 240x400 pixels + 240, 400); // The top screen is physically 240x400 pixels + GPU_SetViewport(0, 0, 240, 400); GPU_DepthMap(-1.0f, 0.0f); // calculate the depth value from the Z coordinate in the following way: -1.0*z + 0.0 // Configure some boilerplate diff --git a/examples/graphics/gpu/textured_cube/source/gpu.c b/examples/graphics/gpu/textured_cube/source/gpu.c index abb8cdd..60b4b89 100644 --- a/examples/graphics/gpu/textured_cube/source/gpu.c +++ b/examples/graphics/gpu/textured_cube/source/gpu.c @@ -35,11 +35,12 @@ void gpuClearBuffers(u32 clearColor) void gpuFrameBegin(void) { - // Configure the viewport and the depth linear conversion function - GPU_SetViewport( + // Configure the output buffers, viewport and the depth linear conversion function + GPU_OutputBuffers(GPU_DEPTH24_EXT8, GPU_COLOR_RGBA8, (u32*)osConvertVirtToPhys((u32)depthBuf), (u32*)osConvertVirtToPhys((u32)colorBuf), - 0, 0, 240, 400); // The top screen is physically 240x400 pixels + 240, 400); // The top screen is physically 240x400 pixels + GPU_SetViewport(0, 0, 240, 400); GPU_DepthMap(-1.0f, 0.0f); // calculate the depth value from the Z coordinate in the following way: -1.0*z + 0.0 // Configure some boilerplate diff --git a/libctru/include/3ds/gpu/gpu.h b/libctru/include/3ds/gpu/gpu.h index 5a48103..829c5e3 100644 --- a/libctru/include/3ds/gpu/gpu.h +++ b/libctru/include/3ds/gpu/gpu.h @@ -50,6 +50,21 @@ typedef enum GPU_MIRRORED_REPEAT = 0x3, }GPU_TEXTURE_WRAP_PARAM; +typedef enum +{ + GPU_COLOR_RGBA8 = 0x00002, + GPU_COLOR_RGBA5551 = 0x20000, + GPU_COLOR_RGB565 = 0x30000, + GPU_COLOR_RGBA4 = 0x40000 +} GPU_COLOR_FORMAT; + +typedef enum +{ + GPU_DEPTH16 = 0x00000, + GPU_DEPTH24 = 0x00002, + GPU_DEPTH24_EXT8 = 0x00003 +} GPU_DEPTH_FORMAT; + typedef enum { GPU_TEXUNIT0 = 0x1, @@ -260,7 +275,8 @@ typedef enum{ void GPU_SetFloatUniform(GPU_SHADER_TYPE type, u32 startreg, u32* data, u32 numreg); -void GPU_SetViewport(u32* depthBuffer, u32* colorBuffer, u32 x, u32 y, u32 w, u32 h); +void GPU_OutputBuffers(GPU_DEPTH_FORMAT depth, GPU_COLOR_FORMAT color, u32* depthBuffer, u32* colorBuffer, u32 w, u32 h); +void GPU_SetViewport(u32 x, u32 y, u32 w, u32 h); void GPU_SetScissorTest(GPU_SCISSORMODE mode, u32 x, u32 y, u32 w, u32 h); diff --git a/libctru/source/gpu/gpu.c b/libctru/source/gpu/gpu.c index 723b65b..6664b6d 100644 --- a/libctru/source/gpu/gpu.c +++ b/libctru/source/gpu/gpu.c @@ -291,11 +291,10 @@ static u32 f32tof31(float f) } //takes PAs as arguments -void GPU_SetViewport(u32* depthBuffer, u32* colorBuffer, u32 x, u32 y, u32 w, u32 h) + +void GPU_OutputBuffers(GPU_DEPTH_FORMAT depth, GPU_COLOR_FORMAT color, u32* depthBuffer, u32* colorBuffer, u32 w, u32 h) { u32 param[0x4]; - float fw=(float)w; - float fh=(float)h; GPUCMD_AddWrite(GPUREG_0111, 0x00000001); GPUCMD_AddWrite(GPUREG_0110, 0x00000001); @@ -308,9 +307,23 @@ void GPU_SetViewport(u32* depthBuffer, u32* colorBuffer, u32 x, u32 y, u32 w, u3 GPUCMD_AddIncrementalWrites(GPUREG_DEPTHBUFFER_LOC, param, 0x00000003); GPUCMD_AddWrite(GPUREG_006E, f116e); - GPUCMD_AddWrite(GPUREG_DEPTHBUFFER_FORMAT, 0x00000003); //depth buffer format - GPUCMD_AddWrite(GPUREG_COLORBUFFER_FORMAT, 0x00000002); //color buffer format - GPUCMD_AddWrite(GPUREG_011B, 0x00000000); //? + GPUCMD_AddWrite(GPUREG_DEPTHBUFFER_FORMAT, depth); //depth buffer format + GPUCMD_AddWrite(GPUREG_COLORBUFFER_FORMAT, color); //color buffer format + GPUCMD_AddWrite(GPUREG_BLOCKMODE, 0x00000000); //block mode (0x0 = 8x8, 0x1 = 32x32) + + //enable depth buffer + param[0x0]=0x0000000F; + param[0x1]=0x0000000F; + param[0x2]=0x00000002; + param[0x3]=0x00000002; + GPUCMD_AddIncrementalWrites(GPUREG_0112, param, 0x00000004); +} + +void GPU_SetViewport(u32 x, u32 y, u32 w, u32 h) +{ + u32 param[0x4]; + float fw=(float)w; + float fh=(float)h; param[0x0]=f32tof24(fw/2); param[0x1]=f32tof31(2.0f / fw) << 1; @@ -324,13 +337,6 @@ void GPU_SetViewport(u32* depthBuffer, u32* colorBuffer, u32 x, u32 y, u32 w, u3 param[0x1]=0x00000000; param[0x2]=((h-1)<<16)|((w-1)&0xFFFF); GPUCMD_AddIncrementalWrites(GPUREG_SCISSORTEST_MODE, param, 0x00000003); - - //enable depth buffer - param[0x0]=0x0000000F; - param[0x1]=0x0000000F; - param[0x2]=0x00000002; - param[0x3]=0x00000002; - GPUCMD_AddIncrementalWrites(GPUREG_0112, param, 0x00000004); } void GPU_SetScissorTest(GPU_SCISSORMODE mode, u32 x, u32 y, u32 w, u32 h)