1 /*---------------------------------------------------------------------------*
2 Copyright (C) Nintendo. All rights reserved.
3
4 These coded instructions, statements, and computer programs contain
5 proprietary information of Nintendo of America Inc. and/or Nintendo
6 Company Ltd., and are protected by Federal copyright law. They may
7 not be disclosed to third parties or copied or duplicated in any form,
8 in whole or in part, without the prior written consent of Nintendo.
9 *---------------------------------------------------------------------------*/
10
11 #ifndef _DEMO_GFX_SHADER_H_
12 #define _DEMO_GFX_SHADER_H_
13
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17
18 /// @addtogroup demoShader
19 /// @{
20
21 /// \brief The structure for vertex/pixel samplers
22 ///
23 /// Each member map to each sampler number.
24 ///
25 typedef struct _DEMOGfxSamplers
26 {
27 /// Current number of sampler
28 u32 count;
29
30 /// The locations in the shader.
31 u32 location[GX2_MAX_SAMPLERS];
32 } DEMOGfxSamplers;
33
34
35 /// \brief The structure for vertex uniforms
36 ///
37 /// Each member map to each uniform number.
38 ///
39 typedef struct _DEMOGfxUniformsVS
40 {
41 /// Current number of uniforms
42 u32 count;
43
44 /// The locations in the vertex shader.
45 u32 location[GX2_MAX_VS_UNIFORM_VARS];
46 } DEMOGfxUniformsVS;
47
48
49 /// \brief The structure for pixel uniforms
50 ///
51 /// Each member map to each uniform number.
52 ///
53 typedef struct _DEMOGfxUniformsPS
54 {
55 /// Current number of uniforms
56 u32 count;
57
58 /// The locations in the pixel shader.
59 u32 location[GX2_MAX_PS_UNIFORM_VARS];
60 } DEMOGfxUniformsPS;
61
62 /// \brief The structure for vertex uniform blocks
63 ///
64 /// Each member map to each uniform number.
65 ///
66 typedef struct _DEMOGfxUniformBlocks
67 {
68 /// Current number of uniform blocks
69 u32 count;
70
71 /// The locations in the shader.
72 u32 location[GX2_MAX_UNIFORM_BLOCKS];
73
74 /// The size of uniform blocks
75 u32 size[GX2_MAX_UNIFORM_BLOCKS];
76
77 } DEMOGfxUniformBlocks;
78
79 /// \brief The structure for shader data
80 ///
81 /// Includes members to setup shader
82 ///
83 typedef struct _DEMOGfxShader
84 {
85 /// Current number of attributes
86 u32 attribCount;
87
88 /// The attribute streams are used to bind the variables used by the vertex shader with the fetch shader.
89 GX2AttribStream attribs[GX2_MAX_ATTRIB_BUFFERS];
90
91 /// The structure holds vertex shader samplers locations
92 DEMOGfxSamplers samplersVS;
93
94 /// The structure holds pixel shader samplers locations
95 DEMOGfxSamplers samplersPS;
96
97 /// The structure holds geometry shader samplers locations
98 DEMOGfxSamplers samplersGS;
99
100 /// The structure holds vertex shader uniforms locations
101 DEMOGfxUniformsVS uniformsVS;
102
103 /// The structure holds pixel shader uniforms locations
104 DEMOGfxUniformsPS uniformsPS;
105
106 // GS is UB only
107
108 /// The structure holds vertex shader uniform blocks location and size
109 DEMOGfxUniformBlocks uniformBlocksVS;
110
111 /// The structure holds pixel shader uniform blocks location and size
112 DEMOGfxUniformBlocks uniformBlocksPS;
113
114 /// The structure holds geometry shader uniform blocks location and size
115 DEMOGfxUniformBlocks uniformBlocksGS;
116
117 /// The vertex shader structure pointers which are loaded from the GSH file
118 GX2VertexShader *pVertexShader;
119
120 /// The pixel shader structure pointers which are loaded from the GSH file
121 GX2PixelShader *pPixelShader;
122
123 /// The geometry shader structure pointers which are loaded from the GSH file
124 GX2GeometryShader *pGeometryShader;
125
126 /// The fetch shader which is based on the specified attribute stream list.
127 GX2FetchShader fetchShader;
128
129 /// An aligned, user-allocated buffer for the fetch shader binary code.
130 void * pFetchShaderBuffer;
131 } DEMOGfxShader;
132
133 //
134 // Functions
135 //
136
137 /// \brief Checks number of shader location
138 ///
139 /// \param location number of shader location
140 /// \return result (TRUE or FALSE)
141 ///
DEMOGfxCheckShaderLocation(u32 location)142 inline BOOL DEMOGfxCheckShaderLocation(u32 location)
143 {
144 if(location == (u32)(-1))
145 {
146 OSReport("Warning: Could not find the correct location.\n");
147 return FALSE;
148 }
149
150 return TRUE;
151 }
152
153 /// \brief Loads shaders from file buffer (.gsh)
154 ///
155 /// \param pShader Pointer to DEMOGfxShader structure
156 /// \param index Index of shader in the file buffer
157 /// \param pData Pointer to the file buffer
158 /// \return result (TRUE or FALSE)
159 ///
160 BOOL DEMOGfxLoadShaders(DEMOGfxShader *pShader, u32 index, const void *pData);
161
162 /// \brief Sets attribute members to DEMOGfxShader structure and initializes stream
163 ///
164 /// \param pShader Pointer to DEMOGfxShader structure
165 /// \param name Pointer to name of attribute (for example, a_position, a_color etc.)
166 /// \param bufferIndex Index of attribute buffer
167 /// \param offset Offset value for attribute data
168 /// \param format Attribute format
169 /// \return result (TRUE or FALSE)
170 ///
171 BOOL DEMOGfxInitShaderAttribute(DEMOGfxShader *pShader, const char *name,
172 u32 bufferIndex, u32 offset, GX2AttribFormat format);
173
174 /// \brief Gets vertex shader sampler location and sets to DEMOGfxShader structure
175 ///
176 /// \param pShader Pointer to DEMOGfxShader structure
177 /// \param name Pointer to name of sampler (for example, s_texture)
178 /// \return result (TRUE or FALSE)
179 ///
180 BOOL DEMOGfxGetVertexShaderSamplerLocation(DEMOGfxShader *pShader, const char *name);
181
182 /// \brief Gets pixel shader sampler location and sets to DEMOGfxShader structure
183 ///
184 /// \param pShader Pointer to DEMOGfxShader structure
185 /// \param name Pointer to name of sampler (for example, s_texture)
186 /// \return result (TRUE or FALSE)
187 ///
188 BOOL DEMOGfxGetPixelShaderSamplerLocation(DEMOGfxShader *pShader, const char *name);
189
190 /// \brief Gets geometry shader sampler location and sets to DEMOGfxShader structure
191 ///
192 /// \param pShader Pointer to DEMOGfxShader structure
193 /// \param name Pointer to name of sampler (for example, s_texture)
194 /// \return result (TRUE or FALSE)
195 ///
196 BOOL DEMOGfxGetGeometryShaderSamplerLocation(DEMOGfxShader *pShader, const char *name);
197
198 /// \brief Gets vertex shader uniform location and sets to DEMOGfxShader structure
199 ///
200 /// \param pShader Pointer to DEMOGfxShader structure
201 /// \param name Pointer to name of uniform (for example, u_scale)
202 /// \return result (TRUE or FALSE)
203 ///
204 BOOL DEMOGfxGetVertexShaderUniformLocation(DEMOGfxShader *pShader, const char *name);
205
206 /// \brief Gets pixel shader uniform location and sets to DEMOGfxShader structure
207 ///
208 /// \param pShader Pointer to DEMOGfxShader structure
209 /// \param name Pointer to name of uniform (for example, u_scale)
210 /// \return result (TRUE or FALSE)
211 ///
212 BOOL DEMOGfxGetPixelShaderUniformLocation(DEMOGfxShader *pShader, const char *name);
213
214 /// \brief Gets vertex shader uniform block location and sets to DEMOGfxShader structure
215 ///
216 /// \param pShader Pointer to DEMOGfxShader structure
217 /// \param name Pointer to name of uniform block (for example, ub_staticBlock)
218 /// \return result (TRUE or FALSE)
219 ///
220 BOOL DEMOGfxGetVertexShaderUniformBlockLocation(DEMOGfxShader *pShader, const char *name);
221
222 /// \brief Gets pixel shader uniform block location and sets to DEMOGfxShader structure
223 ///
224 /// \param pShader Pointer to DEMOGfxShader structure
225 /// \param name Pointer to name of uniform block (for example, ub_dynamicBlock)
226 /// \return result (TRUE or FALSE)
227 ///
228 BOOL DEMOGfxGetPixelShaderUniformBlockLocation(DEMOGfxShader *pShader, const char *name);
229
230 /// \brief Gets geometry shader uniform block location and sets to DEMOGfxShader structure
231 ///
232 /// \param pShader Pointer to DEMOGfxShader structure
233 /// \param name Pointer to name of uniform block (for example, ub_dynamicBlock)
234 /// \return result (TRUE or FALSE)
235 ///
236 BOOL DEMOGfxGetGeometryShaderUniformBlockLocation(DEMOGfxShader *pShader, const char *name);
237
238 /// \brief Sets fetch shader with attrib stream data to DEMOGfxShader structure
239 ///
240 /// \param pShader Pointer to DEMOGfxShader structure
241 ///
242 BOOL DEMOGfxInitFetchShader(DEMOGfxShader *pShader);
243
244 /// \brief Free shaders (Vertex, Pixel, Geometry and Fetch shader )
245 ///
246 /// \param pShader Pointer to DEMOGfxShader structure
247 ///
248 BOOL DEMOGfxFreeShaders(DEMOGfxShader *pShader);
249
250 /// @}
251
252 #ifdef __cplusplus
253 }
254 #endif
255
256 #endif // _DEMO_GFX_SHADER_H_
257