From 01961cbf5e4721940c155e9f181aff037217dbf0 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Fri, 4 Nov 2016 15:58:32 +0100 Subject: [PATCH] Turn matrix_4x4_identity into inline function --- libretro-common/gfx/math/matrix_4x4.c | 29 ---------------- libretro-common/include/gfx/math/matrix_4x4.h | 33 ++++++++++++++++++- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/libretro-common/gfx/math/matrix_4x4.c b/libretro-common/gfx/math/matrix_4x4.c index 2b03e987ef..9364bacda0 100644 --- a/libretro-common/gfx/math/matrix_4x4.c +++ b/libretro-common/gfx/math/matrix_4x4.c @@ -26,8 +26,6 @@ #include #include -#define MAT_ELEM_4X4(mat, row, column) ((mat).data[4 * (column) + (row)]) - void matrix_4x4_copy(math_matrix_4x4 *dst, const math_matrix_4x4 *src) { unsigned i, j; @@ -37,33 +35,6 @@ void matrix_4x4_copy(math_matrix_4x4 *dst, const math_matrix_4x4 *src) MAT_ELEM_4X4(*dst, i, j) = MAT_ELEM_4X4(*src, i, j); } -/* - * Sets mat to an identity matrix - */ -void matrix_4x4_identity(math_matrix_4x4 *mat) -{ - unsigned i; - - MAT_ELEM_4X4(*mat, 0, 1) = 0.0f; - MAT_ELEM_4X4(*mat, 0, 2) = 0.0f; - MAT_ELEM_4X4(*mat, 0, 3) = 0.0f; - - MAT_ELEM_4X4(*mat, 1, 0) = 0.0f; - MAT_ELEM_4X4(*mat, 1, 2) = 0.0f; - MAT_ELEM_4X4(*mat, 1, 3) = 0.0f; - - MAT_ELEM_4X4(*mat, 2, 0) = 0.0f; - MAT_ELEM_4X4(*mat, 2, 1) = 0.0f; - MAT_ELEM_4X4(*mat, 2, 3) = 0.0f; - - MAT_ELEM_4X4(*mat, 3, 0) = 0.0f; - MAT_ELEM_4X4(*mat, 3, 1) = 0.0f; - MAT_ELEM_4X4(*mat, 3, 2) = 0.0f; - - for (i = 0; i < 4; i++) - MAT_ELEM_4X4(*mat, i, i) = 1.0f; -} - /* * Sets out to the transposed matrix of in */ diff --git a/libretro-common/include/gfx/math/matrix_4x4.h b/libretro-common/include/gfx/math/matrix_4x4.h index 7bdece8b8b..f440128f40 100644 --- a/libretro-common/include/gfx/math/matrix_4x4.h +++ b/libretro-common/include/gfx/math/matrix_4x4.h @@ -23,18 +23,49 @@ #ifndef __LIBRETRO_SDK_GFX_MATH_MATRIX_4X4_H__ #define __LIBRETRO_SDK_GFX_MATH_MATRIX_4X4_H__ +#include + /* Column-major matrix (OpenGL-style). * Reimplements functionality from FF OpenGL pipeline to be able * to work on GLES 2.0 and modern GL variants. */ +#define MAT_ELEM_4X4(mat, row, column) ((mat).data[4 * (column) + (row)]) + + typedef struct math_matrix_4x4 { float data[16]; } math_matrix_4x4; +/* + * Sets mat to an identity matrix + */ +static INLINE void matrix_4x4_identity(math_matrix_4x4 *mat) +{ + unsigned i; + + MAT_ELEM_4X4(*mat, 0, 1) = 0.0f; + MAT_ELEM_4X4(*mat, 0, 2) = 0.0f; + MAT_ELEM_4X4(*mat, 0, 3) = 0.0f; + + MAT_ELEM_4X4(*mat, 1, 0) = 0.0f; + MAT_ELEM_4X4(*mat, 1, 2) = 0.0f; + MAT_ELEM_4X4(*mat, 1, 3) = 0.0f; + + MAT_ELEM_4X4(*mat, 2, 0) = 0.0f; + MAT_ELEM_4X4(*mat, 2, 1) = 0.0f; + MAT_ELEM_4X4(*mat, 2, 3) = 0.0f; + + MAT_ELEM_4X4(*mat, 3, 0) = 0.0f; + MAT_ELEM_4X4(*mat, 3, 1) = 0.0f; + MAT_ELEM_4X4(*mat, 3, 2) = 0.0f; + + for (i = 0; i < 4; i++) + MAT_ELEM_4X4(*mat, i, i) = 1.0f; +} + void matrix_4x4_copy(math_matrix_4x4 *dst, const math_matrix_4x4 *src); -void matrix_4x4_identity(math_matrix_4x4 *mat); void matrix_4x4_transpose(math_matrix_4x4 *out, const math_matrix_4x4 *in); void matrix_4x4_rotate_x(math_matrix_4x4 *mat, float rad);