started work on shaderProgram
This commit is contained in:
parent
28fee06006
commit
cd05cc45ff
@ -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>
|
||||
|
||||
|
29
libctru/include/3ds/gpu/shaderProgram.h
Normal file
29
libctru/include/3ds/gpu/shaderProgram.h
Normal file
@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <3ds/types.h>
|
||||
#include <3ds/gpu/shbin.h>
|
||||
|
||||
// this structure describes an instance of either a vertex or geometry shader
|
||||
typedef struct
|
||||
{
|
||||
DVLE_s* dvle;
|
||||
u16 boolUniforms;
|
||||
}shaderInstance_s;
|
||||
|
||||
// this structure describes an instance of a full shader program
|
||||
typedef struct
|
||||
{
|
||||
shaderInstance_s* vertexShader;
|
||||
shaderInstance_s* geometryShader;
|
||||
}shaderProgram_s;
|
||||
|
||||
Result shaderInstanceInit(shaderInstance_s* si, DVLE_s* dvle);
|
||||
Result shaderInstanceFree(shaderInstance_s* si);
|
||||
Result shaderInstanceSetBool(shaderInstance_s* si, int id, bool value);
|
||||
Result shaderInstanceGetBool(shaderInstance_s* si, int id, bool* value);
|
||||
|
||||
Result shaderProgramInit(shaderProgram_s* sp);
|
||||
Result shaderProgramFree(shaderProgram_s* sp);
|
||||
Result shaderProgramSetVsh(shaderProgram_s* sp, DVLE_s* dvle);
|
||||
Result shaderProgramSetGsh(shaderProgram_s* sp, DVLE_s* dvle);
|
||||
Result shaderProgramUse(shaderProgram_s* sp);
|
@ -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);
|
@ -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;
|
||||
|
108
libctru/source/gpu/shaderProgram.c
Normal file
108
libctru/source/gpu/shaderProgram.c
Normal file
@ -0,0 +1,108 @@
|
||||
#include <stdlib.h>
|
||||
#include <3ds/types.h>
|
||||
#include <3ds/gpu/shaderProgram.h>
|
||||
|
||||
Result shaderInstanceInit(shaderInstance_s* si, DVLE_s* dvle)
|
||||
{
|
||||
if(!si || !dvle)return -1;
|
||||
|
||||
si->dvle = dvle;
|
||||
si->boolUniforms = 0xFFFF;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Result shaderInstanceFree(shaderInstance_s* si)
|
||||
{
|
||||
if(!si)return -1;
|
||||
|
||||
free(si);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Result shaderInstanceSetBool(shaderInstance_s* si, int id, bool value)
|
||||
{
|
||||
if(!si)return -1;
|
||||
if(id<0 || id>15)return -2;
|
||||
|
||||
si->boolUniforms &= ~(1<<id);
|
||||
si->boolUniforms |= (!value)<<id;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Result shaderInstanceGetBool(shaderInstance_s* si, int id, bool* value)
|
||||
{
|
||||
if(!si)return -1;
|
||||
if(id<0 || id>15)return -2;
|
||||
if(!value)return -3;
|
||||
|
||||
*value = !((si->boolUniforms>>id)&1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Result shaderProgramInit(shaderProgram_s* sp)
|
||||
{
|
||||
if(!sp)return -1;
|
||||
|
||||
sp->vertexShader = NULL;
|
||||
sp->geometryShader = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Result shaderProgramFree(shaderProgram_s* sp)
|
||||
{
|
||||
if(!sp)return -1;
|
||||
|
||||
shaderInstanceFree(sp->vertexShader);
|
||||
shaderInstanceFree(sp->geometryShader);
|
||||
|
||||
free(sp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Result shaderProgramSetVsh(shaderProgram_s* sp, DVLE_s* dvle)
|
||||
{
|
||||
if(!sp || !dvle)return -1;
|
||||
if(dvle->type != VERTEX_SHDR)return -2;
|
||||
|
||||
if(sp->vertexShader)shaderInstanceFree(sp->vertexShader);
|
||||
|
||||
sp->vertexShader = (shaderInstance_s*)malloc(sizeof(shaderInstance_s));
|
||||
if(!sp->vertexShader)return -3;
|
||||
|
||||
return shaderInstanceInit(sp->vertexShader, dvle);
|
||||
}
|
||||
|
||||
Result shaderProgramSetGsh(shaderProgram_s* sp, DVLE_s* dvle)
|
||||
{
|
||||
if(!sp || !dvle)return -1;
|
||||
if(dvle->type != GEOMETRY_SHDR)return -2;
|
||||
|
||||
if(sp->geometryShader)shaderInstanceFree(sp->geometryShader);
|
||||
|
||||
sp->geometryShader = (shaderInstance_s*)malloc(sizeof(shaderInstance_s));
|
||||
if(!sp->geometryShader)return -3;
|
||||
|
||||
return shaderInstanceInit(sp->geometryShader, dvle);
|
||||
}
|
||||
|
||||
Result shaderProgramUse(shaderProgram_s* sp)
|
||||
{
|
||||
if(!sp)return -1;
|
||||
|
||||
if(!sp->vertexShader)return -2;
|
||||
|
||||
if(!sp->geometryShader)
|
||||
{
|
||||
// only deal with vertex shader
|
||||
}else{
|
||||
// setup both vertex and geometry shader
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user