]> Chaos Git - corbenik/ctrulib.git/commitdiff
started work on shaderProgram
authorsmea <smealum@gmail.com>
Sat, 3 Jan 2015 01:15:44 +0000 (17:15 -0800)
committersmea <smealum@gmail.com>
Sat, 3 Jan 2015 01:15:44 +0000 (17:15 -0800)
libctru/include/3ds.h
libctru/include/3ds/gpu/shaderProgram.h [new file with mode: 0644]
libctru/include/3ds/gpu/shbin.h [moved from libctru/include/3ds/gpu/shdr.h with 88% similarity]
libctru/source/gpu/gpu.c
libctru/source/gpu/shaderProgram.c [new file with mode: 0644]
libctru/source/gpu/shbin.c [moved from libctru/source/gpu/shdr.c with 97% similarity]

index 17132558b784c2f7c7d30ef66b74c60368363465..83e6d05fab3b9c354c5e0f953dfda4a65700ced5 100644 (file)
@@ -34,7 +34,7 @@ extern "C" {
 
 #include <3ds/gpu/gx.h>
 #include <3ds/gpu/gpu.h>
-#include <3ds/gpu/shdr.h>
+#include <3ds/gpu/shbin.h>
 
 #include <3ds/sdmc.h>
 
diff --git a/libctru/include/3ds/gpu/shaderProgram.h b/libctru/include/3ds/gpu/shaderProgram.h
new file mode 100644 (file)
index 0000000..e5f2cba
--- /dev/null
@@ -0,0 +1,29 @@
+#pragma once\r
+\r
+#include <3ds/types.h>\r
+#include <3ds/gpu/shbin.h>\r
+\r
+// this structure describes an instance of either a vertex or geometry shader\r
+typedef struct\r
+{\r
+       DVLE_s* dvle;\r
+       u16 boolUniforms;\r
+}shaderInstance_s;\r
+\r
+// this structure describes an instance of a full shader program\r
+typedef struct\r
+{\r
+       shaderInstance_s* vertexShader;\r
+       shaderInstance_s* geometryShader;\r
+}shaderProgram_s;\r
+\r
+Result shaderInstanceInit(shaderInstance_s* si, DVLE_s* dvle);\r
+Result shaderInstanceFree(shaderInstance_s* si);\r
+Result shaderInstanceSetBool(shaderInstance_s* si, int id, bool value);\r
+Result shaderInstanceGetBool(shaderInstance_s* si, int id, bool* value);\r
+\r
+Result shaderProgramInit(shaderProgram_s* sp);\r
+Result shaderProgramFree(shaderProgram_s* sp);\r
+Result shaderProgramSetVsh(shaderProgram_s* sp, DVLE_s* dvle);\r
+Result shaderProgramSetGsh(shaderProgram_s* sp, DVLE_s* dvle);\r
+Result shaderProgramUse(shaderProgram_s* sp);\r
similarity index 88%
rename from libctru/include/3ds/gpu/shdr.h
rename to libctru/include/3ds/gpu/shbin.h
index ecfe41f16dd2ce4a0240047f274c216600032b50..89cbde951a1327c95e1d30bd2c6ad2fb0dca1d56 100644 (file)
@@ -3,7 +3,7 @@
 typedef enum{
        VERTEX_SHDR=0x0,
        GEOMETRY_SHDR=0x1
-}SHDR_type;
+}DVLE_type;
 
 typedef enum{
        RESULT_POSITION = 0x0,
@@ -14,7 +14,7 @@ typedef enum{
        RESULT_TEXCOORD1 = 0x5,
        RESULT_TEXCOORD2 = 0x6,
        RESULT_VIEW = 0x8
-}SHDR_outType;
+}DVLE_outputAttribute_t;
 
 typedef struct{
        u32 codeSize;
@@ -42,7 +42,7 @@ typedef struct{
 }DVLE_uniformEntry_s;
 
 typedef struct{
-       SHDR_type type;
+       DVLE_type type;
        u32 mainOffset, endmainOffset;
        u32 constTableSize;
        DVLE_constEntry_s* constTableData;
@@ -59,14 +59,13 @@ typedef struct{
        DVLE_s* DVLE;
 }DVLB_s;
 
-
 DVLB_s* SHDR_ParseSHBIN(u32* shbinData, u32 shbinSize);
 void SHDR_UseProgram(DVLB_s* dvlb, u8 id);
 void SHDR_FreeDVLB(DVLB_s* dvlb);
 s8 SHDR_GetUniformRegister(DVLB_s* dvlb, const char* name, u8 programID);
 
-void DVLP_SendCode(DVLP_s* dvlp, SHDR_type type);
-void DVLP_SendOpDesc(DVLP_s* dvlp, SHDR_type type);
+void DVLP_SendCode(DVLP_s* dvlp, DVLE_type type);
+void DVLP_SendOpDesc(DVLP_s* dvlp, DVLE_type type);
 
 void DVLE_SendOutmap(DVLE_s* dvle);
 void DVLE_SendConstants(DVLE_s* dvle);
index 11703cb0a365a6b29bf17c8f8655a08149030f47..ba36fe1dd3eb3cb1f6c576a50bc8cdb1fcfbb3d5 100644 (file)
@@ -7,7 +7,7 @@
 #include <3ds/types.h>
 #include <3ds/gpu/gpu.h>
 #include <3ds/gpu/gx.h>
-#include <3ds/gpu/shdr.h>
+#include <3ds/gpu/shbin.h>
 
 u32* gpuCmdBuf;
 u32 gpuCmdBufSize;
diff --git a/libctru/source/gpu/shaderProgram.c b/libctru/source/gpu/shaderProgram.c
new file mode 100644 (file)
index 0000000..5a28802
--- /dev/null
@@ -0,0 +1,108 @@
+#include <stdlib.h>\r
+#include <3ds/types.h>\r
+#include <3ds/gpu/shaderProgram.h>\r
+\r
+Result shaderInstanceInit(shaderInstance_s* si, DVLE_s* dvle)\r
+{\r
+       if(!si || !dvle)return -1;\r
+\r
+       si->dvle = dvle;\r
+       si->boolUniforms = 0xFFFF;\r
+\r
+       return 0;\r
+}\r
+\r
+Result shaderInstanceFree(shaderInstance_s* si)\r
+{\r
+       if(!si)return -1;\r
+\r
+       free(si);\r
+\r
+       return 0;\r
+}\r
+\r
+Result shaderInstanceSetBool(shaderInstance_s* si, int id, bool value)\r
+{\r
+       if(!si)return -1;\r
+       if(id<0 || id>15)return -2;\r
+\r
+       si->boolUniforms &= ~(1<<id);\r
+       si->boolUniforms |= (!value)<<id;\r
+\r
+       return 0;\r
+}\r
+\r
+Result shaderInstanceGetBool(shaderInstance_s* si, int id, bool* value)\r
+{\r
+       if(!si)return -1;\r
+       if(id<0 || id>15)return -2;\r
+       if(!value)return -3;\r
+\r
+       *value = !((si->boolUniforms>>id)&1);\r
+\r
+       return 0;\r
+}\r
+\r
+Result shaderProgramInit(shaderProgram_s* sp)\r
+{\r
+       if(!sp)return -1;\r
+\r
+       sp->vertexShader = NULL;\r
+       sp->geometryShader = NULL;\r
+\r
+       return 0;\r
+}\r
+\r
+Result shaderProgramFree(shaderProgram_s* sp)\r
+{\r
+       if(!sp)return -1;\r
+\r
+       shaderInstanceFree(sp->vertexShader);\r
+       shaderInstanceFree(sp->geometryShader);\r
+\r
+       free(sp);\r
+\r
+       return 0;\r
+}\r
+\r
+Result shaderProgramSetVsh(shaderProgram_s* sp, DVLE_s* dvle)\r
+{\r
+       if(!sp || !dvle)return -1;\r
+       if(dvle->type != VERTEX_SHDR)return -2;\r
+\r
+       if(sp->vertexShader)shaderInstanceFree(sp->vertexShader);\r
+\r
+       sp->vertexShader = (shaderInstance_s*)malloc(sizeof(shaderInstance_s));\r
+       if(!sp->vertexShader)return -3;\r
+\r
+       return shaderInstanceInit(sp->vertexShader, dvle);\r
+}\r
+\r
+Result shaderProgramSetGsh(shaderProgram_s* sp, DVLE_s* dvle)\r
+{\r
+       if(!sp || !dvle)return -1;\r
+       if(dvle->type != GEOMETRY_SHDR)return -2;\r
+\r
+       if(sp->geometryShader)shaderInstanceFree(sp->geometryShader);\r
+\r
+       sp->geometryShader = (shaderInstance_s*)malloc(sizeof(shaderInstance_s));\r
+       if(!sp->geometryShader)return -3;\r
+\r
+       return shaderInstanceInit(sp->geometryShader, dvle);\r
+}\r
+\r
+Result shaderProgramUse(shaderProgram_s* sp)\r
+{\r
+       if(!sp)return -1;\r
+\r
+       if(!sp->vertexShader)return -2;\r
+\r
+       if(!sp->geometryShader)\r
+       {\r
+               // only deal with vertex shader\r
+       }else{\r
+               // setup both vertex and geometry shader\r
+       }\r
+\r
+       return 0;\r
+}\r
similarity index 97%
rename from libctru/source/gpu/shdr.c
rename to libctru/source/gpu/shbin.c
index f79fbcd4cd956f0fda4d8054d409f3960198d86f..e825f85eab154913ab66050575de03105f78a9a7 100644 (file)
@@ -6,7 +6,7 @@
 #include <string.h>
 #include <3ds/types.h>
 #include <3ds/gpu/gpu.h>
-#include <3ds/gpu/shdr.h>
+#include <3ds/gpu/shbin.h>
 
 //please don't feed this an invalid SHBIN
 DVLB_s* SHDR_ParseSHBIN(u32* shbinData, u32 shbinSize)
@@ -73,7 +73,7 @@ s8 SHDR_GetUniformRegister(DVLB_s* dvlb, const char* name, u8 programID)
        return -1;
 }
 
-void DVLP_SendCode(DVLP_s* dvlp, SHDR_type type)
+void DVLP_SendCode(DVLP_s* dvlp, DVLE_type type)
 {
        if(!dvlp)return;
 
@@ -87,7 +87,7 @@ void DVLP_SendCode(DVLP_s* dvlp, SHDR_type type)
        GPUCMD_AddWrite(GPUREG_VSH_CODETRANSFER_END+regOffset, 0x00000001);
 }
 
-void DVLP_SendOpDesc(DVLP_s* dvlp, SHDR_type type)
+void DVLP_SendOpDesc(DVLP_s* dvlp, DVLE_type type)
 {
        if(!dvlp)return;