]> Chaos Git - corbenik/ctrulib.git/commitdiff
GPU: Added code to manipulate the combiner buffer.
authorSubv <subv2112@gmail.com>
Sat, 22 Aug 2015 15:53:52 +0000 (10:53 -0500)
committerSubv <subv2112@gmail.com>
Sat, 22 Aug 2015 16:28:30 +0000 (11:28 -0500)
You can set an initial color value with GPUREG_TEXENV_BUFFER_COLOR, then use GPU_SetCombinerBufferWrite with GPU_TEV_BUFFER_WRITE_CONFIG to allow/disallow the TEV stages to write their color outputs to the buffer.

You can retrieve the previous buffer color using GPU_PREVIOUS_BUFFER as color source in the TEV config.

libctru/include/3ds/gpu/gpu.h
libctru/include/3ds/gpu/registers.h
libctru/source/gpu/gpu.c

index 8370721af67f84ad5710f1ec2372a9feb9aff48d..b58cf8944de58efdf69119394fddd85c35386531 100644 (file)
@@ -33,6 +33,9 @@ void GPUCMD_Finalize();
 #define GPU_TEXTURE_WRAP_S(v) (((v)&0x3)<<12) //takes a GPU_TEXTURE_WRAP_PARAM
 #define GPU_TEXTURE_WRAP_T(v) (((v)&0x3)<<8) //takes a GPU_TEXTURE_WRAP_PARAM
 
+// Combiner buffer write config
+#define GPU_TEV_BUFFER_WRITE_CONFIG(stage0, stage1, stage2, stage3) (stage0 | (stage1 << 1) | (stage2 << 2) | (stage3 << 3))
+
 typedef enum
 {
        GPU_NEAREST = 0x0,
@@ -184,6 +187,7 @@ typedef enum{
        GPU_TEXTURE1 = 0x04,
        GPU_TEXTURE2 = 0x05,
        GPU_TEXTURE3 = 0x06,
+       GPU_PREVIOUS_BUFFER = 0x0D,
        GPU_CONSTANT = 0x0E,
        GPU_PREVIOUS = 0x0F,
 }GPU_TEVSRC;
@@ -262,6 +266,8 @@ void GPU_SetDepthTestAndWriteMask(bool enable, GPU_TESTFUNC function, GPU_WRITEM
 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);
+// Only the first four tev stages can write to the combiner buffer, use GPU_TEV_BUFFER_WRITE_CONFIG to build the parameters
+void GPU_SetCombinerBufferWrite(u8 rgb_config, u8 alpha_config);
 
 // these two can't be used together
 void GPU_SetAlphaBlending(GPU_BLENDEQUATION colorEquation, GPU_BLENDEQUATION alphaEquation, 
@@ -281,7 +287,7 @@ void GPU_SetTexture(GPU_TEXUNIT unit, u32* data, u16 width, u16 height, u32 para
 /**
  * @param borderColor The color used for the border when using the @ref GPU_CLAMP_TO_BORDER wrap mode
  */
- void GPU_SetTextureBorderColor(GPU_TEXUNIT unit,u32 borderColor);
+void GPU_SetTextureBorderColor(GPU_TEXUNIT unit,u32 borderColor);
 void GPU_SetTexEnv(u8 id, u16 rgbSources, u16 alphaSources, u16 rgbOperands, u16 alphaOperands, GPU_COMBINEFUNC rgbCombine, GPU_COMBINEFUNC alphaCombine, u32 constantColor);
 
 void GPU_DrawArray(GPU_Primitive_t primitive, u32 n);
index b08fa2bf999031ad6f29739bf465ae8204ea2b17..aebc4af2fe53e7519f090635e93650251158073c 100644 (file)
 #define GPUREG_00DD 0x00DD\r
 #define GPUREG_00DE 0x00DE\r
 #define GPUREG_00DF 0x00DF\r
-#define GPUREG_00E0 0x00E0\r
+#define GPUREG_TEXENV_BUFFER_CONFIG 0x00E0\r
 #define GPUREG_00E1 0x00E1\r
 #define GPUREG_00E2 0x00E2\r
 #define GPUREG_00E3 0x00E3\r
 #define GPUREG_TEXENV5_CONFIG2 0x00FA\r
 #define GPUREG_TEXENV5_CONFIG3 0x00FB\r
 #define GPUREG_TEXENV5_CONFIG4 0x00FC\r
-#define GPUREG_00FD 0x00FD\r
+#define GPUREG_TEXENV_BUFFER_COLOR 0x00FD\r
 #define GPUREG_00FE 0x00FE\r
 #define GPUREG_00FF 0x00FF\r
 #define GPUREG_COLOROUTPUT_CONFIG 0x0100\r
index 49d580946ea42a48585cf869eebb9e28d36cc3e7..b50717cc96406a8a66b1f0cb0f8d02640dd1240b 100644 (file)
@@ -463,6 +463,11 @@ void GPU_SetFaceCulling(GPU_CULLMODE mode)
        GPUCMD_AddWrite(GPUREG_FACECULLING_CONFIG, mode&0x3); 
 }
 
+void GPU_SetCombinerBufferWrite(u8 rgb_config, u8 alpha_config)
+{
+    GPUCMD_AddMaskedWrite(GPUREG_TEXENV_BUFFER_CONFIG, 0x2, (rgb_config << 8) | (alpha_config << 12));
+}
+
 const u8 GPU_TEVID[]={0xC0,0xC8,0xD0,0xD8,0xF0,0xF8};
 
 void GPU_SetTexEnv(u8 id, u16 rgbSources, u16 alphaSources, u16 rgbOperands, u16 alphaOperands, GPU_COMBINEFUNC rgbCombine, GPU_COMBINEFUNC alphaCombine, u32 constantColor)