libctru  v2.4.1
shaderProgram.h
Go to the documentation of this file.
1 /**
2  * @file shaderProgram.h
3  * @brief Functions for working with shaders.
4  */
5 #pragma once
6 
7 #include <3ds/types.h>
8 #include <3ds/gpu/shbin.h>
9 
10 /// 24-bit float uniforms.
11 typedef struct
12 {
13  u32 id; ///< Uniform ID.
14  u32 data[3]; ///< Uniform data.
16 
17 /// Describes an instance of either a vertex or geometry shader.
18 typedef struct
19 {
20  DVLE_s* dvle; ///< Shader DVLE.
21  u16 boolUniforms; ///< Boolean uniforms.
22  u16 boolUniformMask; ///< Used boolean uniform mask.
23  u32 intUniforms[4]; ///< Integer uniforms.
24  float24Uniform_s* float24Uniforms; ///< 24-bit float uniforms.
25  u8 intUniformMask; ///< Used integer uniform mask.
26  u8 numFloat24Uniforms; ///< Float uniform count.
28 
29 /// Describes an instance of a full shader program.
30 typedef struct
31 {
32  shaderInstance_s* vertexShader; ///< Vertex shader.
33  shaderInstance_s* geometryShader; ///< Geometry shader.
34  u32 geoShaderInputPermutation[2]; ///< Geometry shader input permutation.
35  u8 geoShaderInputStride; ///< Geometry shader input stride.
37 
38 /**
39  * @brief Initializes a shader instance.
40  * @param si Shader instance to initialize.
41  * @param dvle DVLE to initialize the shader instance with.
42  */
44 
45 /**
46  * @brief Frees a shader instance.
47  * @param si Shader instance to free.
48  */
50 
51 /**
52  * @brief Sets a bool uniform of a shader.
53  * @param si Shader instance to use.
54  * @param id ID of the bool uniform.
55  * @param value Value to set.
56  */
58 
59 /**
60  * @brief Gets a bool uniform of a shader.
61  * @param si Shader instance to use.
62  * @param id ID of the bool uniform.
63  * @param value Pointer to output the value to.
64  */
65 Result shaderInstanceGetBool(shaderInstance_s* si, int id, bool* value);
66 
67 /**
68  * @brief Gets the location of a shader's uniform.
69  * @param si Shader instance to use.
70  * @param name Name of the uniform.
71  */
73 
74 /**
75  * @brief Initializes a shader program.
76  * @param sp Shader program to initialize.
77  */
79 
80 /**
81  * @brief Frees a shader program.
82  * @param sp Shader program to free.
83  */
85 
86 /**
87  * @brief Sets the vertex shader of a shader program.
88  * @param sp Shader program to use.
89  * @param dvle Vertex shader to set.
90  */
92 
93 /**
94  * @brief Sets the geometry shader of a shader program.
95  * @param sp Shader program to use.
96  * @param dvle Geometry shader to set.
97  * @param stride Input stride of the shader (pass 0 to match the number of outputs of the vertex shader).
98  */
100 
101 /**
102  * @brief Configures the permutation of the input attributes of the geometry shader of a shader program.
103  * @param sp Shader program to use.
104  * @param permutation Attribute permutation to use.
105  */
107 
108 /**
109  * @brief Configures the shader units to use the specified shader program.
110  * @param sp Shader program to use.
111  * @param sendVshCode When true, the vertex shader's code and operand descriptors are uploaded.
112  * @param sendGshCode When true, the geometry shader's code and operand descriptors are uploaded.
113  */
114 Result shaderProgramConfigure(shaderProgram_s* sp, bool sendVshCode, bool sendGshCode);
115 
116 /**
117  * @brief Same as shaderProgramConfigure, but always loading code/operand descriptors and uploading DVLE constants afterwards.
118  * @param sp Shader program to use.
119  */
Result shaderProgramUse(shaderProgram_s *sp)
Same as shaderProgramConfigure, but always loading code/operand descriptors and uploading DVLE consta...
Result shaderProgramSetVsh(shaderProgram_s *sp, DVLE_s *dvle)
Sets the vertex shader of a shader program.
Result shaderProgramInit(shaderProgram_s *sp)
Initializes a shader program.
Result shaderProgramFree(shaderProgram_s *sp)
Frees a shader program.
Result shaderProgramSetGshInputPermutation(shaderProgram_s *sp, u64 permutation)
Configures the permutation of the input attributes of the geometry shader of a shader program.
Result shaderInstanceFree(shaderInstance_s *si)
Frees a shader instance.
Result shaderInstanceInit(shaderInstance_s *si, DVLE_s *dvle)
Initializes a shader instance.
Result shaderProgramSetGsh(shaderProgram_s *sp, DVLE_s *dvle, u8 stride)
Sets the geometry shader of a shader program.
Result shaderInstanceGetBool(shaderInstance_s *si, int id, bool *value)
Gets a bool uniform of a shader.
Result shaderProgramConfigure(shaderProgram_s *sp, bool sendVshCode, bool sendGshCode)
Configures the shader units to use the specified shader program.
Result shaderInstanceSetBool(shaderInstance_s *si, int id, bool value)
Sets a bool uniform of a shader.
s8 shaderInstanceGetUniformLocation(shaderInstance_s *si, const char *name)
Gets the location of a shader's uniform.
Shader binary support.
DVLE data.
Definition: shbin.h:74
24-bit float uniforms.
Definition: shaderProgram.h:12
u32 id
Uniform ID.
Definition: shaderProgram.h:13
Describes an instance of either a vertex or geometry shader.
Definition: shaderProgram.h:19
DVLE_s * dvle
Shader DVLE.
Definition: shaderProgram.h:20
u16 boolUniformMask
Used boolean uniform mask.
Definition: shaderProgram.h:22
u8 intUniformMask
Used integer uniform mask.
Definition: shaderProgram.h:25
u16 boolUniforms
Boolean uniforms.
Definition: shaderProgram.h:21
u8 numFloat24Uniforms
Float uniform count.
Definition: shaderProgram.h:26
float24Uniform_s * float24Uniforms
24-bit float uniforms.
Definition: shaderProgram.h:24
Describes an instance of a full shader program.
Definition: shaderProgram.h:31
shaderInstance_s * vertexShader
Vertex shader.
Definition: shaderProgram.h:32
shaderInstance_s * geometryShader
Geometry shader.
Definition: shaderProgram.h:33
u8 geoShaderInputStride
Geometry shader input stride.
Definition: shaderProgram.h:35
Various system types.
uint64_t u64
64-bit unsigned integer
Definition: types.h:24
uint8_t u8
would be nice if newlib had this already
Definition: types.h:21
int8_t s8
8-bit signed integer
Definition: types.h:26
s32 Result
Function result.
Definition: types.h:42
uint16_t u16
16-bit unsigned integer
Definition: types.h:22
uint32_t u32
32-bit unsigned integer
Definition: types.h:23