]> Chaos Git - corbenik/ctrulib.git/commitdiff
GPU : added buffer setup commands to GPU_SetViewport
authorsmea <smealum@gmail.com>
Wed, 12 Mar 2014 19:11:34 +0000 (20:11 +0100)
committersmea <smealum@gmail.com>
Wed, 12 Mar 2014 19:11:34 +0000 (20:11 +0100)
gpu/source/main.c
libctru/include/ctr/GPU.h
libctru/source/GPU.c

index d52148244bbc381dbc45a603808b8fe49252c336..073db12687e49d5536dd38c4c091090cb7f3dfce 100644 (file)
@@ -114,7 +114,13 @@ int main()
                        GSPGPU_WriteHWRegs(NULL, 0x202A04, &regData, 4);
 
                        GPUCMD_SetBuffer(gpuCmd, gpuCmdSize, 0);
-                       GPUCMD_AddSingleParam(0x0008025E, 0x00000000);
+
+                               //depth buffer in VRAM, color buffer in FCRAM (gspHeap)
+                               //(no real reasoning behind this configuration)
+                               GPU_SetViewport((u32*)0x18000000,(u32*)0x20000000,0,0,240*2,400);
+                               SHDR_UseProgram(shader, 0);
+                               GPUCMD_AddSingleParam(0x0008025E, 0x00000000);
+
                        GPUCMD_Finalize();
                        GPUCMD_Run(gxCmdBuf);
 
index 47189b7792a9378f370293ec10d769d898e9bc94..1a9e3b6ae54fbe229174a3ab722772e65fab7e9f 100644 (file)
@@ -11,6 +11,6 @@ void GPUCMD_AddSingleParam(u32 cmd, u32 param);
 void GPUCMD_Finalize();
 
 void GPU_SetUniform(u32 startreg, u32* data, u32 numreg);
-void GPU_SetViewport(u32 x, u32 y, float w, float h);
+void GPU_SetViewport(u32* depthBuffer, u32* colorBuffer, u32 x, u32 y, u32 w, u32 h);
 
 #endif
index 08019bda21cf92cb380f05e1ba5106b8e5dd1aed..e7af93908459bc6ab40b9ba7d91c3964b424eece 100644 (file)
@@ -222,7 +222,7 @@ u32 computeInvValue(u32 val)
        u32 tmp3=*((u32*)&fval);
        tmp1=(tmp3<<9)>>9;
        tmp2=tmp3&(~0x80000000);
-       if(tmp3&(~0x80000000))
+       if(tmp2)
        {
                tmp1=(tmp3<<9)>>9;
                int tmp=((tmp3<<1)>>24)-0x40;
@@ -233,15 +233,38 @@ u32 computeInvValue(u32 val)
        return (tmp1|(tmp2<<23)|(tmp3<<30))<<1;
 }
 
-void GPU_SetViewport(u32 x, u32 y, float w, float h)
+//takes PAs as arguments
+void GPU_SetViewport(u32* depthBuffer, u32* colorBuffer, u32 x, u32 y, u32 w, u32 h)
 {
        u32 param[0x4];
+       float fw=(float)w;
+       float fh=(float)h;
 
-       param[0x0]=f32tof24(w/2);
-       param[0x1]=computeInvValue(w);
-       param[0x2]=f32tof24(h/2);
-       param[0x3]=computeInvValue(h);
+       GPUCMD_AddSingleParam(0x000F0111, 0x00000001);
+       GPUCMD_AddSingleParam(0x000F0110, 0x00000001);
+
+       u32 f116e=0x01000000|(((h-1)&0xFFF)<<12)|(w&0xFFF);
+
+       param[0x0]=((u32)depthBuffer)>>3;
+       param[0x1]=((u32)colorBuffer)>>3;
+       param[0x2]=f116e;
+       GPUCMD_Add(0x800F011C, param, 0x00000003);
+
+       GPUCMD_AddSingleParam(0x000F006E, f116e);
+       GPUCMD_AddSingleParam(0x000F0116, 0x00000003); //?
+       GPUCMD_AddSingleParam(0x000F0117, 0x00000002); //?
+       GPUCMD_AddSingleParam(0x000F011B, 0x00000000); //?
+
+       param[0x0]=f32tof24(fw/2);
+       param[0x1]=computeInvValue(fw);
+       param[0x2]=f32tof24(fh/2);
+       param[0x3]=computeInvValue(fh);
        GPUCMD_Add(0x800F0041, param, 0x00000004);
 
        GPUCMD_AddSingleParam(0x000F0068, (y<<16)|(x&0xFFFF));
+
+       param[0x0]=0x00000000;
+       param[0x1]=0x00000000;
+       param[0x2]=((h-1)<<16)|((w-1)&0xFFFF);
+       GPUCMD_Add(0x800F0065, param, 0x00000003);
 }