From a283a54bee5198b622af41827cd5c6a1e30df7c2 Mon Sep 17 00:00:00 2001 From: Themaister Date: Thu, 9 Aug 2012 22:33:32 +0200 Subject: [PATCH] Use calculated MVP directly in shader params. --- gfx/context/ps3_ctx.c | 31 ++++++++----------------------- gfx/context/sdl_ctx.c | 2 ++ gfx/gl.c | 8 ++++---- gfx/gl_common.h | 2 ++ gfx/shader_cg.c | 4 ++-- gfx/shader_cg.h | 3 ++- gfx/shader_glsl.c | 8 ++++++-- gfx/shader_glsl.h | 3 ++- 8 files changed, 28 insertions(+), 33 deletions(-) diff --git a/gfx/context/ps3_ctx.c b/gfx/context/ps3_ctx.c index 41e341e7e7..57d1d78fb7 100644 --- a/gfx/context/ps3_ctx.c +++ b/gfx/context/ps3_ctx.c @@ -356,34 +356,19 @@ const char *ps3_get_resolution_label(uint32_t resolution) void gfx_ctx_set_projection(gl_t *gl, const struct gl_ortho *ortho, bool allow_rotate) { - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); + // Calculate projection. + math_matrix proj; + matrix_ortho(&proj, ortho->left, ortho->right, + ortho->bottom, ortho->top, ortho->znear, ortho->zfar); if (allow_rotate) { - switch (gl->rotation) - { - case 90: - vertex_ptr = vertexes_90; - break; - case 180: - vertex_ptr = vertexes_180; - break; - case 270: - vertex_ptr = vertexes_270; - break; - case 0: - default: - vertex_ptr = default_vertex_ptr; - break; - } + math_matrix rot; + matrix_rotate_z(&rot, M_PI * gl->rotation / 180.0f); + matrix_multiply(&proj, &rot, &proj); } - glVertexPointer(2, GL_FLOAT, 0, vertex_ptr); - - glOrtho(ortho->left, ortho->right, ortho->bottom, ortho->top, ortho->znear, ortho->zfar); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); + gl->mvp = proj; } void gfx_ctx_set_aspect_ratio(void *data, unsigned aspectratio_index) diff --git a/gfx/context/sdl_ctx.c b/gfx/context/sdl_ctx.c index a8466f7d39..7b0fe608c4 100644 --- a/gfx/context/sdl_ctx.c +++ b/gfx/context/sdl_ctx.c @@ -466,6 +466,8 @@ void gfx_ctx_set_projection(gl_t *gl, const struct gl_ortho *ortho, bool allow_r // TODO: Explicitly setting matrix modes is not used for GLES 2.0. glMatrixMode(GL_MODELVIEW); glLoadIdentity(); + + gl->mvp = proj; } #endif diff --git a/gfx/gl.c b/gfx/gl.c index 36f83c299b..50467d3664 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -203,14 +203,14 @@ static inline void gl_shader_deinit(void) #endif } -static inline void gl_shader_set_proj_matrix(void) +static inline void gl_shader_set_proj_matrix(const math_matrix *mat) { #ifdef HAVE_CG - gl_cg_set_proj_matrix(); + gl_cg_set_proj_matrix(mat); #endif #ifdef HAVE_XML - gl_glsl_set_proj_matrix(); + gl_glsl_set_proj_matrix(mat); #endif } @@ -440,7 +440,7 @@ void gl_set_projection(gl_t *gl, struct gl_ortho *ortho, bool allow_rotate) #endif gfx_ctx_set_projection(gl, ortho, allow_rotate); - gl_shader_set_proj_matrix(); + gl_shader_set_proj_matrix(&gl->mvp); } void gl_set_viewport(gl_t *gl, unsigned width, unsigned height, bool force_full, bool allow_rotate) diff --git a/gfx/gl_common.h b/gfx/gl_common.h index 906f27adda..277ee37a4b 100644 --- a/gfx/gl_common.h +++ b/gfx/gl_common.h @@ -18,6 +18,7 @@ #include "../general.h" #include "fonts/fonts.h" +#include "math/matrix.h" #ifdef HAVE_CONFIG_H #include "../config.h" @@ -179,6 +180,7 @@ typedef struct gl unsigned last_height[TEXTURES]; unsigned tex_w, tex_h; GLfloat tex_coords[8]; + math_matrix mvp; #ifdef __CELLOS_LV2__ GLuint pbo; diff --git a/gfx/shader_cg.c b/gfx/shader_cg.c index e41bf117a9..825db7ad2f 100644 --- a/gfx/shader_cg.c +++ b/gfx/shader_cg.c @@ -149,10 +149,10 @@ static void gl_cg_reset_attrib(void) cg_attrib_index = 0; } -void gl_cg_set_proj_matrix(void) +void gl_cg_set_proj_matrix(const math_matrix *mat) { if (cg_active && prg[active_index].mvp) - cgGLSetStateMatrixParameter(prg[active_index].mvp, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY); + cgGLSetMatrixParameterfc(prg[active_index].mvp, mat->data); } #define set_param_2f(param, x, y) \ diff --git a/gfx/shader_cg.h b/gfx/shader_cg.h index 3af257e990..162013b9a7 100644 --- a/gfx/shader_cg.h +++ b/gfx/shader_cg.h @@ -19,6 +19,7 @@ #include "../boolean.h" #include "gl_common.h" +#include "math/matrix.h" #include bool gl_cg_init(const char *path); @@ -26,7 +27,7 @@ bool gl_cg_reinit(const char *path); void gl_cg_deinit(void); -void gl_cg_set_proj_matrix(void); +void gl_cg_set_proj_matrix(const math_matrix *mat); void gl_cg_set_params(unsigned width, unsigned height, unsigned tex_width, unsigned tex_height, diff --git a/gfx/shader_glsl.c b/gfx/shader_glsl.c index 9956d5d05c..b96db992fa 100644 --- a/gfx/shader_glsl.c +++ b/gfx/shader_glsl.c @@ -1225,8 +1225,12 @@ void gl_glsl_set_params(unsigned width, unsigned height, } } -void gl_glsl_set_proj_matrix(void) -{} +void gl_glsl_set_proj_matrix(const math_matrix *mat) +{ + // If we're using FF-based GL, this matrix + // will be implicitly passed to the shader. + (void)mat; +} void gl_glsl_use(unsigned index) { diff --git a/gfx/shader_glsl.h b/gfx/shader_glsl.h index f834e0e0cd..b0dba1b8bd 100644 --- a/gfx/shader_glsl.h +++ b/gfx/shader_glsl.h @@ -19,12 +19,13 @@ #include "../boolean.h" #include "gl_common.h" +#include "math/matrix.h" bool gl_glsl_init(const char *path); void gl_glsl_deinit(void); -void gl_glsl_set_proj_matrix(void); +void gl_glsl_set_proj_matrix(const math_matrix *mat); void gl_glsl_set_params(unsigned width, unsigned height, unsigned tex_width, unsigned tex_height,