From d24691e810846bc0762068b02a7dd49650ea475e Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 26 Oct 2014 02:32:10 +0100 Subject: [PATCH] Convert math/matrix.c to math/matrix_4x4.c --- Makefile.common | 2 +- frontend/menu/disp/lakka.c | 28 ++--- frontend/menu/disp/xmb.c | 10 +- gfx/gl.c | 8 +- gfx/gl_common.h | 4 +- gfx/shader/shader_context.h | 4 +- gfx/shader/shader_gl_cg.c | 2 +- gfx/shader/shader_glsl.c | 2 +- gfx/shader/shader_hlsl.c | 2 +- gfx/shader/shader_null.c | 4 +- griffin/griffin.c | 2 +- .../gfx/math/{matrix.c => matrix_4x4.c} | 110 +++++++++--------- .../gfx/math/{matrix.h => matrix_4x4.h} | 26 ++--- 13 files changed, 103 insertions(+), 101 deletions(-) rename libretro-sdk/gfx/math/{matrix.c => matrix_4x4.c} (51%) rename libretro-sdk/include/gfx/math/{matrix.h => matrix_4x4.h} (69%) diff --git a/Makefile.common b/Makefile.common index 922d32353a..e71ce546e1 100644 --- a/Makefile.common +++ b/Makefile.common @@ -365,7 +365,7 @@ ifeq ($(HAVE_OPENGL), 1) gfx/context/gfx_null_ctx.o \ gfx/fonts/gl_font.o \ gfx/fonts/gl_raster_font.o \ - libretro-sdk/gfx/math/matrix.o \ + libretro-sdk/gfx/math/matrix_4x4.o \ gfx/state_tracker.o \ libretro-sdk/glsym/rglgen.o diff --git a/frontend/menu/disp/lakka.c b/frontend/menu/disp/lakka.c index 512f4993b3..9cd9f16a80 100644 --- a/frontend/menu/disp/lakka.c +++ b/frontend/menu/disp/lakka.c @@ -203,7 +203,7 @@ static void lakka_draw_icon(lakka_handle_t *lakka, float scale_factor) { struct gl_coords coords; - math_matrix mymat, mrot; + math_matrix_4x4 mymat, mrot; if (!lakka) return; @@ -242,12 +242,12 @@ static void lakka_draw_icon(lakka_handle_t *lakka, coords.color = color; glBindTexture(GL_TEXTURE_2D, texture); - matrix_rotate_z(&mrot, rotation); - matrix_multiply(&mymat, &mrot, &gl->mvp_no_rot); + matrix_4x4_rotate_z(&mrot, rotation); + matrix_4x4_multiply(&mymat, &mrot, &gl->mvp_no_rot); - math_matrix mscal; - matrix_scale(&mscal, scale_factor, scale_factor, 1); - matrix_multiply(&mymat, &mscal, &mymat); + math_matrix_4x4 mscal; + matrix_4x4_scale(&mscal, scale_factor, scale_factor, 1); + matrix_4x4_multiply(&mymat, &mscal, &mymat); gl->shader->set_coords(&coords); gl->shader->set_mvp(gl, &mymat); @@ -527,15 +527,15 @@ static void lakka_draw_fbo(lakka_handle_t *lakka) coords.color = gl->white_color_ptr; glBindTexture(GL_TEXTURE_2D, lakka->fbo_color); - math_matrix mymat; - - math_matrix mrot; - matrix_rotate_z(&mrot, 0); - matrix_multiply(&mymat, &mrot, &gl->mvp_no_rot); - + math_matrix_4x4 mymat; + math_matrix_4x4 mrot; math_matrix mscal; - matrix_scale(&mscal, lakka->global_scale, lakka->global_scale, 1); - matrix_multiply(&mymat, &mscal, &mymat); + + matrix_4x4_rotate_z(&mrot, 0); + matrix_4x4_multiply(&mymat, &mrot, &gl->mvp_no_rot); + + matrix_4x4_scale(&mscal, lakka->global_scale, lakka->global_scale, 1); + matrix_4x4_multiply(&mymat, &mscal, &mymat); gl->shader->set_coords(&coords); gl->shader->set_mvp(gl, &mymat); diff --git a/frontend/menu/disp/xmb.c b/frontend/menu/disp/xmb.c index fabec14592..d76015a4ac 100644 --- a/frontend/menu/disp/xmb.c +++ b/frontend/menu/disp/xmb.c @@ -133,7 +133,7 @@ static void xmb_draw_icon(GLuint texture, float x, float y, float alpha, float rotation, float scale_factor) { struct gl_coords coords; - math_matrix mymat, mrot, mscal; + math_matrix_4x4 mymat, mrot, mscal; xmb_handle_t *xmb = (xmb_handle_t*)driver.menu->userdata; if (!xmb) @@ -173,11 +173,11 @@ static void xmb_draw_icon(GLuint texture, float x, float y, coords.color = color; glBindTexture(GL_TEXTURE_2D, texture); - matrix_rotate_z(&mrot, rotation); - matrix_multiply(&mymat, &mrot, &gl->mvp_no_rot); + matrix_4x4_rotate_z(&mrot, rotation); + matrix_4x4_multiply(&mymat, &mrot, &gl->mvp_no_rot); - matrix_scale(&mscal, scale_factor, scale_factor, 1); - matrix_multiply(&mymat, &mscal, &mymat); + matrix_4x4_scale(&mscal, scale_factor, scale_factor, 1); + matrix_4x4_multiply(&mymat, &mscal, &mymat); gl->shader->set_coords(&coords); gl->shader->set_mvp(gl, &mymat); diff --git a/gfx/gl.c b/gfx/gl.c index 2d43428c6b..3e3f58c49f 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -759,10 +759,10 @@ static bool gl_init_hw_render(gl_t *gl, unsigned width, unsigned height) static void gl_set_projection(gl_t *gl, struct gl_ortho *ortho, bool allow_rotate) { - math_matrix rot; + math_matrix_4x4 rot; /* Calculate projection. */ - matrix_ortho(&gl->mvp_no_rot, ortho->left, ortho->right, + matrix_4x4_ortho(&gl->mvp_no_rot, ortho->left, ortho->right, ortho->bottom, ortho->top, ortho->znear, ortho->zfar); if (!allow_rotate) @@ -771,8 +771,8 @@ static void gl_set_projection(gl_t *gl, struct gl_ortho *ortho, bool allow_rotat return; } - matrix_rotate_z(&rot, M_PI * gl->rotation / 180.0f); - matrix_multiply(&gl->mvp, &rot, &gl->mvp_no_rot); + matrix_4x4_rotate_z(&rot, M_PI * gl->rotation / 180.0f); + matrix_4x4_multiply(&gl->mvp, &rot, &gl->mvp_no_rot); } void gl_set_viewport(gl_t *gl, unsigned width, diff --git a/gfx/gl_common.h b/gfx/gl_common.h index 75476978d8..7b8aaa0542 100644 --- a/gfx/gl_common.h +++ b/gfx/gl_common.h @@ -18,7 +18,7 @@ #include "../general.h" #include "fonts/fonts.h" -#include +#include #include "gfx_context.h" #include #include "fonts/gl_font.h" @@ -222,7 +222,7 @@ typedef struct gl unsigned last_width[MAX_TEXTURES]; unsigned last_height[MAX_TEXTURES]; unsigned tex_w, tex_h; - math_matrix mvp, mvp_no_rot; + math_matrix_4x4 mvp, mvp_no_rot; struct gl_coords coords; const GLfloat *vertex_ptr; diff --git a/gfx/shader/shader_context.h b/gfx/shader/shader_context.h index 0867af51b0..21912ea3ce 100644 --- a/gfx/shader/shader_context.h +++ b/gfx/shader/shader_context.h @@ -24,7 +24,7 @@ #endif #include "../gfx_context.h" -#include +#include typedef struct shader_backend { @@ -44,7 +44,7 @@ typedef struct shader_backend enum gfx_wrap_type (*wrap_type)(unsigned index); void (*shader_scale)(unsigned index, struct gfx_fbo_scale *scale); bool (*set_coords)(const void *data); - bool (*set_mvp)(void *data, const math_matrix *mat); + bool (*set_mvp)(void *data, const math_matrix_4x4 *mat); unsigned (*get_prev_textures)(void); bool (*mipmap_input)(unsigned index); diff --git a/gfx/shader/shader_gl_cg.c b/gfx/shader/shader_gl_cg.c index 07458af7e1..82f6c3f3ca 100644 --- a/gfx/shader/shader_gl_cg.c +++ b/gfx/shader/shader_gl_cg.c @@ -166,7 +166,7 @@ static void gl_cg_reset_attrib(void) cg_attrib_idx = 0; } -static bool gl_cg_set_mvp(void *data, const math_matrix *mat) +static bool gl_cg_set_mvp(void *data, const math_matrix_4x4 *mat) { (void)data; if (cg_active && prg[active_idx].mvp) diff --git a/gfx/shader/shader_glsl.c b/gfx/shader/shader_glsl.c index 21fe1c74af..b5d834cf32 100644 --- a/gfx/shader/shader_glsl.c +++ b/gfx/shader/shader_glsl.c @@ -1056,7 +1056,7 @@ static void gl_glsl_set_params(void *data, unsigned width, unsigned height, } } -static bool gl_glsl_set_mvp(void *data, const math_matrix *mat) +static bool gl_glsl_set_mvp(void *data, const math_matrix_4x4 *mat) { (void)data; if (!glsl_enable || !glsl_shader->modern) diff --git a/gfx/shader/shader_hlsl.c b/gfx/shader/shader_hlsl.c index 6689a0c6b0..297bfe0562 100644 --- a/gfx/shader/shader_hlsl.c +++ b/gfx/shader/shader_hlsl.c @@ -412,7 +412,7 @@ static void hlsl_shader_scale(unsigned idx, struct gfx_fbo_scale *scale) scale->valid = false; } -static bool hlsl_set_mvp(void *data, const math_matrix *mat) +static bool hlsl_set_mvp(void *data, const math_matrix_4x4 *mat) { d3d_video_t *d3d = (d3d_video_t*)data; LPDIRECT3DDEVICE d3d_device_ptr = (LPDIRECT3DDEVICE)d3d->dev; diff --git a/gfx/shader/shader_null.c b/gfx/shader/shader_null.c index 4a2a083237..036cb6ba4f 100644 --- a/gfx/shader/shader_null.c +++ b/gfx/shader/shader_null.c @@ -21,7 +21,7 @@ #include #include "../state_tracker.h" #include "../../dynamic.h" -#include +#include #ifdef HAVE_CONFIG_H #include "../../config.h" @@ -48,7 +48,7 @@ static void shader_null_set_params(void *data, unsigned width, unsigned height, { } -static bool shader_null_set_mvp(void *data, const math_matrix *mat) +static bool shader_null_set_mvp(void *data, const math_matrix_4x4 *mat) { #ifdef HAVE_OPENGL #ifndef NO_GL_FF_MATRIX diff --git a/griffin/griffin.c b/griffin/griffin.c index 8df9fbc417..7889dfa189 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -173,7 +173,7 @@ VIDEO DRIVER ============================================================ */ #if defined(HAVE_OPENGL) -#include "../libretro-sdk/gfx/math/matrix.c" +#include "../libretro-sdk/gfx/math/matrix_4x4.c" #elif defined(GEKKO) #ifdef HW_RVL #include "../wii/vi_encoder.c" diff --git a/libretro-sdk/gfx/math/matrix.c b/libretro-sdk/gfx/math/matrix_4x4.c similarity index 51% rename from libretro-sdk/gfx/math/matrix.c rename to libretro-sdk/gfx/math/matrix_4x4.c index 0f02b1d605..caefc30092 100644 --- a/libretro-sdk/gfx/math/matrix.c +++ b/libretro-sdk/gfx/math/matrix_4x4.c @@ -20,122 +20,125 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include +#include #include #include -void matrix_identity(math_matrix *mat) +void matrix_4x4_identity(math_matrix_4x4 *mat) { unsigned i; memset(mat, 0, sizeof(*mat)); for (i = 0; i < 4; i++) - MAT_ELEM(*mat, i, i) = 1.0f; + MAT_ELEM_4X4(*mat, i, i) = 1.0f; } -void matrix_transpose(math_matrix *out, const math_matrix *in) +void matrix_4x4_transpose(math_matrix_4x4 *out, const math_matrix_4x4 *in) { unsigned i, j; - math_matrix mat; + math_matrix_4x4 mat; + for (i = 0; i < 4; i++) for (j = 0; j < 4; j++) - MAT_ELEM(mat, j, i) = MAT_ELEM(*in, i, j); + MAT_ELEM_4X4(mat, j, i) = MAT_ELEM_4X4(*in, i, j); *out = mat; } -void matrix_rotate_x(math_matrix *mat, float rad) +void matrix_4x4_rotate_x(math_matrix_4x4 *mat, float rad) { float cosine = cosf(rad); float sine = sinf(rad); - matrix_identity(mat); + matrix_4x4_identity(mat); - MAT_ELEM(*mat, 1, 1) = cosine; - MAT_ELEM(*mat, 2, 2) = cosine; - MAT_ELEM(*mat, 1, 2) = -sine; - MAT_ELEM(*mat, 2, 1) = sine; + MAT_ELEM_4X4(*mat, 1, 1) = cosine; + MAT_ELEM_4X4(*mat, 2, 2) = cosine; + MAT_ELEM_4X4(*mat, 1, 2) = -sine; + MAT_ELEM_4X4(*mat, 2, 1) = sine; } -void matrix_rotate_y(math_matrix *mat, float rad) +void matrix_4x4_rotate_y(math_matrix_4x4 *mat, float rad) { float cosine = cosf(rad); float sine = sinf(rad); - matrix_identity(mat); + matrix_4x4_identity(mat); - MAT_ELEM(*mat, 0, 0) = cosine; - MAT_ELEM(*mat, 2, 2) = cosine; - MAT_ELEM(*mat, 0, 2) = -sine; - MAT_ELEM(*mat, 2, 0) = sine; + MAT_ELEM_4X4(*mat, 0, 0) = cosine; + MAT_ELEM_4X4(*mat, 2, 2) = cosine; + MAT_ELEM_4X4(*mat, 0, 2) = -sine; + MAT_ELEM_4X4(*mat, 2, 0) = sine; } -void matrix_rotate_z(math_matrix *mat, float rad) +void matrix_4x4_rotate_z(math_matrix_4x4 *mat, float rad) { float cosine = cosf(rad); float sine = sinf(rad); - matrix_identity(mat); + matrix_4x4_identity(mat); - MAT_ELEM(*mat, 0, 0) = cosine; - MAT_ELEM(*mat, 1, 1) = cosine; - MAT_ELEM(*mat, 0, 1) = -sine; - MAT_ELEM(*mat, 1, 0) = sine; + MAT_ELEM_4X4(*mat, 0, 0) = cosine; + MAT_ELEM_4X4(*mat, 1, 1) = cosine; + MAT_ELEM_4X4(*mat, 0, 1) = -sine; + MAT_ELEM_4X4(*mat, 1, 0) = sine; } -void matrix_ortho(math_matrix *mat, +void matrix_4x4_ortho(math_matrix_4x4 *mat, float left, float right, float bottom, float top, float znear, float zfar) { - matrix_identity(mat); + matrix_4x4_identity(mat); float tx = -(right + left) / (right - left); float ty = -(top + bottom) / (top - bottom); float tz = -(zfar + znear) / (zfar - znear); - MAT_ELEM(*mat, 0, 0) = 2.0f / (right - left); - MAT_ELEM(*mat, 1, 1) = 2.0f / (top - bottom); - MAT_ELEM(*mat, 2, 2) = -2.0f / (zfar - znear); - MAT_ELEM(*mat, 0, 3) = tx; - MAT_ELEM(*mat, 1, 3) = ty; - MAT_ELEM(*mat, 2, 3) = tz; + MAT_ELEM_4X4(*mat, 0, 0) = 2.0f / (right - left); + MAT_ELEM_4X4(*mat, 1, 1) = 2.0f / (top - bottom); + MAT_ELEM_4X4(*mat, 2, 2) = -2.0f / (zfar - znear); + MAT_ELEM_4X4(*mat, 0, 3) = tx; + MAT_ELEM_4X4(*mat, 1, 3) = ty; + MAT_ELEM_4X4(*mat, 2, 3) = tz; } -void matrix_scale(math_matrix *out, float x, float y, +void matrix_4x4_scale(math_matrix_4x4 *out, float x, float y, float z) { memset(out, 0, sizeof(*out)); - MAT_ELEM(*out, 0, 0) = x; - MAT_ELEM(*out, 1, 1) = y; - MAT_ELEM(*out, 2, 2) = z; - MAT_ELEM(*out, 3, 3) = 1.0f; + MAT_ELEM_4X4(*out, 0, 0) = x; + MAT_ELEM_4X4(*out, 1, 1) = y; + MAT_ELEM_4X4(*out, 2, 2) = z; + MAT_ELEM_4X4(*out, 3, 3) = 1.0f; } -void matrix_translate(math_matrix *out, float x, +void matrix_4x4_translate(math_matrix_4x4 *out, float x, float y, float z) { - matrix_identity(out); - MAT_ELEM(*out, 0, 3) = x; - MAT_ELEM(*out, 1, 3) = y; - MAT_ELEM(*out, 2, 3) = z; + matrix_4x4_identity(out); + MAT_ELEM_4X4(*out, 0, 3) = x; + MAT_ELEM_4X4(*out, 1, 3) = y; + MAT_ELEM_4X4(*out, 2, 3) = z; } -void matrix_projection(math_matrix *out, float znear, +void matrix_4x4_projection(math_matrix_4x4 *out, float znear, float zfar) { memset(out, 0, sizeof(*out)); - MAT_ELEM(*out, 0, 0) = znear; - MAT_ELEM(*out, 1, 1) = zfar; - MAT_ELEM(*out, 2, 2) = (zfar + znear) / (zfar - znear); - MAT_ELEM(*out, 2, 3) = -2.0f * zfar * znear / (zfar - znear); - MAT_ELEM(*out, 3, 2) = -1.0f; + MAT_ELEM_4X4(*out, 0, 0) = znear; + MAT_ELEM_4X4(*out, 1, 1) = zfar; + MAT_ELEM_4X4(*out, 2, 2) = (zfar + znear) / (zfar - znear); + MAT_ELEM_4X4(*out, 2, 3) = -2.0f * zfar * znear / (zfar - znear); + MAT_ELEM_4X4(*out, 3, 2) = -1.0f; } -void matrix_multiply(math_matrix *out, - const math_matrix *a, const math_matrix *b) +void matrix_4x4_multiply( + math_matrix_4x4 *out, + const math_matrix_4x4 *a, + const math_matrix_4x4 *b) { unsigned r, c, k; - math_matrix mat; + math_matrix_4x4 mat; for (r = 0; r < 4; r++) { @@ -143,11 +146,10 @@ void matrix_multiply(math_matrix *out, { float dot = 0.0f; for (k = 0; k < 4; k++) - dot += MAT_ELEM(*a, r, k) * MAT_ELEM(*b, k, c); - MAT_ELEM(mat, r, c) = dot; + dot += MAT_ELEM_4X4(*a, r, k) * MAT_ELEM_4X4(*b, k, c); + MAT_ELEM_4X4(mat, r, c) = dot; } } *out = mat; } - diff --git a/libretro-sdk/include/gfx/math/matrix.h b/libretro-sdk/include/gfx/math/matrix_4x4.h similarity index 69% rename from libretro-sdk/include/gfx/math/matrix.h rename to libretro-sdk/include/gfx/math/matrix_4x4.h index ceea1d6760..59e4b21989 100644 --- a/libretro-sdk/include/gfx/math/matrix.h +++ b/libretro-sdk/include/gfx/math/matrix_4x4.h @@ -28,30 +28,30 @@ * to work on GLES 2.0 and modern GL variants. */ -typedef struct math_matrix +typedef struct math_matrix_4x4 { float data[16]; -} math_matrix; +} math_matrix_4x4; -#define MAT_ELEM(mat, r, c) ((mat).data[4 * (c) + (r)]) +#define MAT_ELEM_4X4(mat, r, c) ((mat).data[4 * (c) + (r)]) -void matrix_identity(math_matrix *mat); -void matrix_transpose(math_matrix *out, const math_matrix *in); +void matrix_4x4_identity(math_matrix_4x4 *mat); +void matrix_4x4_transpose(math_matrix_4x4 *out, const math_matrix_4x4 *in); -void matrix_rotate_x(math_matrix *mat, float rad); -void matrix_rotate_y(math_matrix *mat, float rad); -void matrix_rotate_z(math_matrix *mat, float rad); +void matrix_4x4_rotate_x(math_matrix_4x4 *mat, float rad); +void matrix_4x4_rotate_y(math_matrix_4x4 *mat, float rad); +void matrix_4x4_rotate_z(math_matrix_4x4 *mat, float rad); -void matrix_ortho(math_matrix *mat, +void matrix_4x4_ortho(math_matrix_4x4 *mat, float left, float right, float bottom, float top, float znear, float zfar); -void matrix_multiply(math_matrix *out, const math_matrix *a, const math_matrix *b); +void matrix_4x4_multiply(math_matrix_4x4 *out, const math_matrix_4x4 *a, const math_matrix_4x4 *b); -void matrix_scale(math_matrix *out, float x, float y, float z); -void matrix_translate(math_matrix *out, float x, float y, float z); -void matrix_projection(math_matrix *out, float znear, float zfar); +void matrix_4x4_scale(math_matrix_4x4 *out, float x, float y, float z); +void matrix_4x4_translate(math_matrix_4x4 *out, float x, float y, float z); +void matrix_4x4_projection(math_matrix_4x4 *out, float znear, float zfar); #endif