Skip to content

Commit 41a7cf4

Browse files
committed
shaders: rename public APIs for matrix management
To make clear that these functions are to be called only when implementing shaders in the client code, rename them to have a "ogx_shader" prefix. Also use the "_gx" or "_gl" suffix to indicate whether they expect the matrix to be in the GX or OpenGL format.
1 parent f837fe9 commit 41a7cf4

File tree

5 files changed

+37
-15
lines changed

5 files changed

+37
-15
lines changed

examples/sdl2/opengl20/opengx_shaders.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static void gl2gears_setup_draw(GLuint program, const OgxDrawData *draw_data,
3636
glGetUniformfv(program, data->mat_color_loc, colorf);
3737
float light_dir[4];
3838
glGetUniformfv(program, data->light_pos_loc, light_dir);
39-
ogx_set_mvp_matrix(m);
39+
ogx_shader_set_mvp_gl(m);
4040

4141
Mtx normalm;
4242
ogx_matrix_gl_to_mtx(normal_matrix, normalm);
@@ -80,7 +80,7 @@ static void cube_tex_setup_draw(GLuint program, const OgxDrawData *draw_data,
8080
glGetUniformfv(program, data->mvp_loc, m);
8181
GLint texture_unit;
8282
glGetUniformiv(program, data->tex_sampler_loc, &texture_unit);
83-
ogx_set_mvp_matrix(m);
83+
ogx_shader_set_mvp_gl(m);
8484

8585
uint8_t tex_map = GX_TEXMAP0;
8686
uint8_t tex_coord = GX_TEXCOORD0;

src/gc_gl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ static void get_projection_info(const Mtx44 matrix, u8 *type, float *near, float
124124
}
125125
}
126126

127-
void ogx_set_projection_gx(const Mtx44 matrix)
127+
void _ogx_set_projection(const Mtx44 matrix)
128128
{
129129
/* OpenGL's projection matrix transform the scene into a clip space where
130130
* all the coordinates lie in the range [-1, 1]. Nintendo's GX, however,
@@ -154,7 +154,7 @@ void ogx_set_projection_gx(const Mtx44 matrix)
154154

155155
static inline void update_projection_matrix()
156156
{
157-
ogx_set_projection_gx(glparamstate.projection_matrix);
157+
_ogx_set_projection(glparamstate.projection_matrix);
158158
}
159159

160160
static inline void update_normal_matrix()

src/opengx.h

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,19 +176,15 @@ void ogx_shader_setup_attribute_array(int index, uint8_t gx_attr,
176176
const OgxDrawData *draw_data);
177177
void *ogx_shader_get_data(GLuint shader);
178178

179-
void ogx_set_projection_gx(const Mtx44 matrix);
180-
static inline void ogx_set_projection_gl(const GLfloat *matrix)
179+
void ogx_shader_set_projection_gx(const Mtx44 matrix);
180+
static inline void ogx_shader_set_projection_gl(const GLfloat *matrix)
181181
{
182182
Mtx44 m;
183183
for (int i = 0; i < 16; i++) {
184184
m[i % 4][i / 4] = matrix[i];
185185
}
186-
ogx_set_projection_gx(m);
186+
ogx_shader_set_projection_gx(m);
187187
}
188-
/* Many OpenGL 2.0+ apps pass a uniform with the model-view-projection matrix
189-
* to the vertex shader. This function decomposes it into MV and projection
190-
* matrices, and uploads them separately to GX. */
191-
void ogx_set_mvp_matrix(const GLfloat *matrix);
192188

193189
static inline void ogx_matrix_gl_to_mtx(const GLfloat *matrix, Mtx m)
194190
{
@@ -199,6 +195,19 @@ static inline void ogx_matrix_gl_to_mtx(const GLfloat *matrix, Mtx m)
199195
}
200196
}
201197

198+
void ogx_shader_set_modelview_gx(const Mtx matrix);
199+
static inline void ogx_shader_set_modelview_gl(const GLfloat *matrix)
200+
{
201+
Mtx m;
202+
ogx_matrix_gl_to_mtx(matrix, m);
203+
ogx_shader_set_modelview_gx(m);
204+
}
205+
206+
/* Many OpenGL 2.0+ apps pass a uniform with the model-view-projection matrix
207+
* to the vertex shader. This function decomposes it into MV and projection
208+
* matrices, and uploads them separately to GX. */
209+
void ogx_shader_set_mvp_gl(const GLfloat *matrix);
210+
202211
#ifdef __cplusplus
203212
} // extern C
204213
#endif

src/shader_api.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2929
POSSIBILITY OF SUCH DAMAGE.
3030
*****************************************************************************/
3131

32+
#define BUILDING_SHADER_CODE
3233
#include "debug.h"
3334
#include "opengx.h"
3435
#include "shader.h"
@@ -44,7 +45,18 @@ static void scale_matrix(const GLfloat *matrix, float divisor, float *out)
4445
out[i] = matrix[i] / divisor;
4546
}
4647

47-
void ogx_set_mvp_matrix(const GLfloat *matrix)
48+
void ogx_shader_set_projection_gx(const Mtx44 matrix)
49+
{
50+
_ogx_set_projection(matrix);
51+
}
52+
53+
void ogx_shader_set_modelview_gx(const Mtx matrix)
54+
{
55+
GX_LoadPosMtxImm((void*)matrix, GX_PNMTX0);
56+
GX_SetCurrentMtx(GX_PNMTX0);
57+
}
58+
59+
void ogx_shader_set_mvp_gl(const GLfloat *matrix)
4860
{
4961
Mtx44 proj;
5062
Mtx mv;
@@ -95,9 +107,8 @@ void ogx_set_mvp_matrix(const GLfloat *matrix)
95107
mv[row][col] = matrix[col * 4 + row];
96108
}
97109
}
98-
ogx_set_projection_gx(proj);
99-
GX_LoadPosMtxImm(mv, GX_PNMTX0);
100-
GX_SetCurrentMtx(GX_PNMTX0);
110+
ogx_shader_set_projection_gx(proj);
111+
ogx_shader_set_modelview_gx(mv);
101112

102113
/* In the unlikely case that some fixed-pipeline drawing happens, we mark
103114
* the matrices as dirty so that they'd be reconfigured when needed. */

src/utils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,8 @@ void _ogx_setup_2D_projection(void);
351351
/* Set the OpenGL 3D modelview and projection matrices */
352352
void _ogx_setup_3D_projection(void);
353353

354+
void _ogx_set_projection(const Mtx44 matrix);
355+
354356
bool _ogx_setup_render_stages(void);
355357
void _ogx_update_vertex_array_readers(OgxDrawMode mode);
356358

0 commit comments

Comments
 (0)