#include <3ds/gpu/gx.h>
#include <3ds/gpu/gpu.h>
-#include <3ds/gpu/shdr.h>
+#include <3ds/gpu/shbin.h>
#include <3ds/sdmc.h>
--- /dev/null
+#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
typedef enum{
VERTEX_SHDR=0x0,
GEOMETRY_SHDR=0x1
-}SHDR_type;
+}DVLE_type;
typedef enum{
RESULT_POSITION = 0x0,
RESULT_TEXCOORD1 = 0x5,
RESULT_TEXCOORD2 = 0x6,
RESULT_VIEW = 0x8
-}SHDR_outType;
+}DVLE_outputAttribute_t;
typedef struct{
u32 codeSize;
}DVLE_uniformEntry_s;
typedef struct{
- SHDR_type type;
+ DVLE_type type;
u32 mainOffset, endmainOffset;
u32 constTableSize;
DVLE_constEntry_s* constTableData;
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);
#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;
--- /dev/null
+#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
#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)
return -1;
}
-void DVLP_SendCode(DVLP_s* dvlp, SHDR_type type)
+void DVLP_SendCode(DVLP_s* dvlp, DVLE_type type)
{
if(!dvlp)return;
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;