From ee237be28567d0bd6d23f90d0f852e675687c778 Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Thu, 30 Jun 2011 20:33:50 +0100 Subject: [PATCH] matrix-mesa: move to _cogl_matrix namespace Instead of having everything in cogl-matrix-mesa.[ch] be in the _math namespace this now puts them in the _cogl_matrix namespace instead, in preparation for flattening cogl-matrix-mesa.[ch] into cogl-matrix.[ch]. Signed-off-by: Neil Roberts --- cogl/cogl-matrix-mesa.c | 46 +++++++++++++++++++------------------- cogl/cogl-matrix-mesa.h | 38 +++++++++++++++---------------- cogl/cogl-matrix-private.h | 2 +- cogl/cogl-matrix.c | 30 +++++++++---------------- 4 files changed, 53 insertions(+), 63 deletions(-) diff --git a/cogl/cogl-matrix-mesa.c b/cogl/cogl-matrix-mesa.c index 7ddeb7d1d..5703efd5d 100644 --- a/cogl/cogl-matrix-mesa.c +++ b/cogl/cogl-matrix-mesa.c @@ -58,10 +58,10 @@ * - instead of allocating matrix->m and matrix->inv using malloc, our * public CoglMatrix typedef is large enough to directly contain the * matrix, its inverse, a type and a set of flags. - * - instead of having a _math_matrix_analyse which updates the type, - * flags and inverse, we have _math_matrix_update_inverse which + * - instead of having a _cogl_matrix_analyse which updates the type, + * flags and inverse, we have _cogl_matrix_update_inverse which * essentially does the same thing (internally making use of - * _math_matrix_update_type_and_flags()) but with additional guards in + * _cogl_matrix_update_type_and_flags()) but with additional guards in * place to bail out when the inverse matrix is still valid. * - when initializing a matrix with the identity matrix we don't * immediately initialize the inverse matrix; rather we just set the @@ -290,7 +290,7 @@ matrix_multiply_array_with_flags (CoglMatrix *result, * otherwise. */ void -_math_matrix_multiply (CoglMatrix *result, +_cogl_matrix_multiply (CoglMatrix *result, const CoglMatrix *a, const CoglMatrix *b) { @@ -315,7 +315,7 @@ _math_matrix_multiply (CoglMatrix *result, * Calls matrix_multiply4x4() for the multiplication. */ void -_math_matrix_multiply_array (CoglMatrix *result, const float *array) +_cogl_matrix_multiply_array (CoglMatrix *result, const float *array) { result->flags |= (MAT_FLAG_GENERAL | MAT_DIRTY_TYPE | @@ -330,7 +330,7 @@ _math_matrix_multiply_array (CoglMatrix *result, const float *array) * * @m matrix array. * - * Called by _math_matrix_print() to print a matrix or its inverse. + * Called by _cogl_matrix_print() to print a matrix or its inverse. */ static void print_matrix_floats (const float m[16]) @@ -346,7 +346,7 @@ print_matrix_floats (const float m[16]) * @m pointer to the CoglMatrix structure. */ void -_math_matrix_print (const CoglMatrix *matrix) +_cogl_matrix_print (const CoglMatrix *matrix) { g_print ("Matrix type: %s, flags: %x\n", types[matrix->type], (int)matrix->flags); @@ -844,12 +844,12 @@ static inv_mat_func inv_mat_tab[7] = { * and copies the identity matrix into CoglMatrix::inv. */ gboolean -_math_matrix_update_inverse (CoglMatrix *matrix) +_cogl_matrix_update_inverse (CoglMatrix *matrix) { if (matrix->flags & MAT_DIRTY_FLAGS || matrix->flags & MAT_DIRTY_INVERSE) { - _math_matrix_update_type_and_flags (matrix); + _cogl_matrix_update_type_and_flags (matrix); if (inv_mat_tab[matrix->type](matrix)) matrix->flags &= ~MAT_FLAG_SINGULAR; @@ -877,7 +877,7 @@ _math_matrix_update_inverse (CoglMatrix *matrix) * Optimizations contributed by Rudolf Opalla (rudi@khm.de). */ void -_math_matrix_rotate (CoglMatrix *matrix, +_cogl_matrix_rotate (CoglMatrix *matrix, float angle, float x, float y, @@ -1078,7 +1078,7 @@ _math_matrix_rotate (CoglMatrix *matrix, * MAT_FLAG_PERSPECTIVE flag. */ void -_math_matrix_frustum (CoglMatrix *matrix, +_cogl_matrix_frustum (CoglMatrix *matrix, float left, float right, float bottom, @@ -1121,7 +1121,7 @@ _math_matrix_frustum (CoglMatrix *matrix, * MAT_FLAG_GENERAL_SCALE and MAT_FLAG_TRANSLATION flags. */ void -_math_matrix_ortho (CoglMatrix *matrix, +_cogl_matrix_ortho (CoglMatrix *matrix, float left, float right, float bottom, @@ -1172,7 +1172,7 @@ _math_matrix_ortho (CoglMatrix *matrix, * MAT_DIRTY_INVERSE dirty flags. */ void -_math_matrix_scale (CoglMatrix *matrix, float x, float y, float z) +_cogl_matrix_scale (CoglMatrix *matrix, float x, float y, float z) { float *m = (float *)matrix; m[0] *= x; m[4] *= y; m[8] *= z; @@ -1201,7 +1201,7 @@ _math_matrix_scale (CoglMatrix *matrix, float x, float y, float z) * dirty flags. */ void -_math_matrix_translate (CoglMatrix *matrix, float x, float y, float z) +_cogl_matrix_translate (CoglMatrix *matrix, float x, float y, float z) { float *m = (float *)matrix; m[12] = m[0] * x + m[4] * y + m[8] * z + m[12]; @@ -1219,7 +1219,7 @@ _math_matrix_translate (CoglMatrix *matrix, float x, float y, float z) * Transforms Normalized Device Coords to window/Z values. */ void -_math_matrix_viewport (CoglMatrix *matrix, +_cogl_matrix_viewport (CoglMatrix *matrix, float x, float y, float width, float height, float zNear, float zFar, float depthMax) @@ -1246,7 +1246,7 @@ _math_matrix_viewport (CoglMatrix *matrix, * doesn't initialize the inverse matrix, it just marks it dirty. */ void -_math_matrix_init_identity (CoglMatrix *matrix) +_cogl_matrix_init_identity (CoglMatrix *matrix) { memcpy (matrix, identity, 16 * sizeof (float)); @@ -1469,7 +1469,7 @@ analyse_from_flags (CoglMatrix *matrix) * then calls matrix_invert(). Finally clears the dirty flags. */ void -_math_matrix_update_type_and_flags (CoglMatrix *matrix) +_cogl_matrix_update_type_and_flags (CoglMatrix *matrix) { if (matrix->flags & MAT_DIRTY_TYPE) { @@ -1486,7 +1486,7 @@ _math_matrix_update_type_and_flags (CoglMatrix *matrix) * Test if the given matrix preserves vector lengths. */ gboolean -_math_matrix_is_length_preserving (const CoglMatrix *m) +_cogl_matrix_is_length_preserving (const CoglMatrix *m) { return TEST_MAT_FLAGS (m, MAT_FLAGS_LENGTH_PRESERVING); } @@ -1496,7 +1496,7 @@ _math_matrix_is_length_preserving (const CoglMatrix *m) * (or perhaps if the upper-left 3x3 is non-identity) */ gboolean -_math_matrix_has_rotation (const CoglMatrix *matrix) +_cogl_matrix_has_rotation (const CoglMatrix *matrix) { if (matrix->flags & (MAT_FLAG_GENERAL | MAT_FLAG_ROTATION | @@ -1508,13 +1508,13 @@ _math_matrix_has_rotation (const CoglMatrix *matrix) } gboolean -_math_matrix_is_general_scale (const CoglMatrix *matrix) +_cogl_matrix_is_general_scale (const CoglMatrix *matrix) { return (matrix->flags & MAT_FLAG_GENERAL_SCALE) ? TRUE : FALSE; } gboolean -_math_matrix_is_dirty (const CoglMatrix *matrix) +_cogl_matrix_is_dirty (const CoglMatrix *matrix) { return (matrix->flags & MAT_DIRTY_ALL) ? TRUE : FALSE; } @@ -1530,14 +1530,14 @@ _math_matrix_is_dirty (const CoglMatrix *matrix) * flags. */ void -_math_matrix_init_from_array (CoglMatrix *matrix, const float *array) +_cogl_matrix_init_from_array (CoglMatrix *matrix, const float *array) { memcpy (matrix, array, 16 * sizeof (float)); matrix->flags = (MAT_FLAG_GENERAL | MAT_DIRTY_ALL); } void -_math_matrix_init_from_quaternion (CoglMatrix *matrix, +_cogl_matrix_init_from_quaternion (CoglMatrix *matrix, CoglQuaternion *quaternion) { float qnorm = _COGL_QUATERNION_NORM (quaternion); diff --git a/cogl/cogl-matrix-mesa.h b/cogl/cogl-matrix-mesa.h index 751067f8d..d87688135 100644 --- a/cogl/cogl-matrix-mesa.h +++ b/cogl/cogl-matrix-mesa.h @@ -82,72 +82,72 @@ enum CoglMatrixType { } ; void -_math_matrix_multiply (CoglMatrix *result, +_cogl_matrix_multiply (CoglMatrix *result, const CoglMatrix *a, const CoglMatrix *b); void -_math_matrix_multiply_array (CoglMatrix *result, const float *b); +_cogl_matrix_multiply_array (CoglMatrix *result, const float *b); void -_math_matrix_init_from_array (CoglMatrix *matrix, const float *array); +_cogl_matrix_init_from_array (CoglMatrix *matrix, const float *array); void -_math_matrix_init_from_quaternion (CoglMatrix *matrix, +_cogl_matrix_init_from_quaternion (CoglMatrix *matrix, CoglQuaternion *quaternion); void -_math_matrix_translate (CoglMatrix *matrix, float x, float y, float z); +_cogl_matrix_translate (CoglMatrix *matrix, float x, float y, float z); void -_math_matrix_rotate (CoglMatrix *matrix, float angle, +_cogl_matrix_rotate (CoglMatrix *matrix, float angle, float x, float y, float z); void -_math_matrix_scale (CoglMatrix *matrix, float x, float y, float z); +_cogl_matrix_scale (CoglMatrix *matrix, float x, float y, float z); void -_math_matrix_ortho (CoglMatrix *matrix, +_cogl_matrix_ortho (CoglMatrix *matrix, float left, float right, float bottom, float top, float nearval, float farval); void -_math_matrix_frustum (CoglMatrix *matrix, +_cogl_matrix_frustum (CoglMatrix *matrix, float left, float right, float bottom, float top, float nearval, float farval); void -_math_matrix_viewport (CoglMatrix *matrix, +_cogl_matrix_viewport (CoglMatrix *matrix, float x, float y, float width, float height, float z_near, float z_far, float depth_max); void -_math_matrix_init_identity (CoglMatrix *matrix); +_cogl_matrix_init_identity (CoglMatrix *matrix); gboolean -_math_matrix_update_inverse (CoglMatrix *matrix); +_cogl_matrix_update_inverse (CoglMatrix *matrix); void -_math_matrix_update_type_and_flags (CoglMatrix *matrix); +_cogl_matrix_update_type_and_flags (CoglMatrix *matrix); void -_math_matrix_print (const CoglMatrix *matrix); +_cogl_matrix_print (const CoglMatrix *matrix); gboolean -_math_matrix_is_length_preserving (const CoglMatrix *matrix); +_cogl_matrix_is_length_preserving (const CoglMatrix *matrix); gboolean -_math_matrix_has_rotation (const CoglMatrix *matrix); +_cogl_matrix_has_rotation (const CoglMatrix *matrix); gboolean -_math_matrix_is_general_scale (const CoglMatrix *matrix); +_cogl_matrix_is_general_scale (const CoglMatrix *matrix); gboolean -_math_matrix_is_dirty (const CoglMatrix *matrix); +_cogl_matrix_is_dirty (const CoglMatrix *matrix); void -_math_transposef ( float to[16], const float from[16]); +_cogl_matrix_util_transposef ( float to[16], const float from[16]); #endif diff --git a/cogl/cogl-matrix-private.h b/cogl/cogl-matrix-private.h index 7414e5bea..1bdea7bb0 100644 --- a/cogl/cogl-matrix-private.h +++ b/cogl/cogl-matrix-private.h @@ -39,7 +39,7 @@ G_BEGIN_DECLS } void -_cogl_matrix_print (CoglMatrix *matrix); +_cogl_matrix_print (const CoglMatrix *matrix); G_END_DECLS diff --git a/cogl/cogl-matrix.c b/cogl/cogl-matrix.c index 6e45d1dbf..06c5fa1ed 100644 --- a/cogl/cogl-matrix.c +++ b/cogl/cogl-matrix.c @@ -51,16 +51,6 @@ COGL_GTYPE_DEFINE_BOXED ("Matrix", matrix, cogl_matrix_free); #endif -void -_cogl_matrix_print (CoglMatrix *matrix) -{ - float *m = (float *)matrix; - int y; - - for (y = 0; y < 4; y++) - g_print ("\t%6.4f %6.4f %6.4f %6.4f\n", m[y], m[4+y], m[8+y], m[12+y]); -} - void cogl_matrix_init_identity (CoglMatrix *matrix) { @@ -70,7 +60,7 @@ cogl_matrix_init_identity (CoglMatrix *matrix) matrix->zx = 0; matrix->zy = 0; matrix->zz = 1; matrix->zw = 0; matrix->wx = 0; matrix->wy = 0; matrix->wz = 0; matrix->ww = 1; #else - _math_matrix_init_identity (matrix); + _cogl_matrix_init_identity (matrix); #endif _COGL_MATRIX_DEBUG_PRINT (matrix); } @@ -79,7 +69,7 @@ void cogl_matrix_init_from_quaternion (CoglMatrix *matrix, CoglQuaternion *quaternion) { - _math_matrix_init_from_quaternion (matrix, quaternion); + _cogl_matrix_init_from_quaternion (matrix, quaternion); } void @@ -121,7 +111,7 @@ cogl_matrix_multiply (CoglMatrix *result, *result = r; #else - _math_matrix_multiply (result, a, b); + _cogl_matrix_multiply (result, a, b); #endif _COGL_MATRIX_DEBUG_PRINT (result); } @@ -165,7 +155,7 @@ cogl_matrix_rotate (CoglMatrix *matrix, cogl_matrix_multiply (&result, matrix, &rotation); *matrix = result; #else - _math_matrix_rotate (matrix, angle, x, y, z); + _cogl_matrix_rotate (matrix, angle, x, y, z); #endif _COGL_MATRIX_DEBUG_PRINT (matrix); } @@ -182,7 +172,7 @@ cogl_matrix_translate (CoglMatrix *matrix, matrix->zw = matrix->zx * x + matrix->zy * y + matrix->zz * z + matrix->zw; matrix->ww = matrix->wx * x + matrix->wy * y + matrix->wz * z + matrix->ww; #else - _math_matrix_translate (matrix, x, y, z); + _cogl_matrix_translate (matrix, x, y, z); #endif _COGL_MATRIX_DEBUG_PRINT (matrix); } @@ -199,7 +189,7 @@ cogl_matrix_scale (CoglMatrix *matrix, matrix->zx *= sx; matrix->zy *= sy; matrix->zz *= sz; matrix->wx *= sx; matrix->wy *= sy; matrix->wz *= sz; #else - _math_matrix_scale (matrix, sx, sy, sz); + _cogl_matrix_scale (matrix, sx, sy, sz); #endif _COGL_MATRIX_DEBUG_PRINT (matrix); } @@ -246,7 +236,7 @@ cogl_matrix_frustum (CoglMatrix *matrix, cogl_matrix_multiply (matrix, matrix, &frustum); #else - _math_matrix_frustum (matrix, left, right, bottom, top, z_near, z_far); + _cogl_matrix_frustum (matrix, left, right, bottom, top, z_near, z_far); #endif _COGL_MATRIX_DEBUG_PRINT (matrix); } @@ -308,7 +298,7 @@ cogl_matrix_ortho (CoglMatrix *matrix, cogl_matrix_multiply (matrix, matrix, &ortho); #else - _math_matrix_ortho (matrix, left, right, bottom, top, near_val, far_val); + _cogl_matrix_ortho (matrix, left, right, bottom, top, near_val, far_val); #endif _COGL_MATRIX_DEBUG_PRINT (matrix); } @@ -376,7 +366,7 @@ cogl_matrix_init_from_array (CoglMatrix *matrix, const float *array) #ifndef USE_MESA_MATRIX_API memcpy (matrix, array, sizeof (float) * 16); #else - _math_matrix_init_from_array (matrix, array); + _cogl_matrix_init_from_array (matrix, array); #endif _COGL_MATRIX_DEBUG_PRINT (matrix); } @@ -455,7 +445,7 @@ cogl_matrix_get_inverse (const CoglMatrix *matrix, CoglMatrix *inverse) cogl_matrix_init_identity (inverse); return FALSE; #else - if (_math_matrix_update_inverse ((CoglMatrix *)matrix)) + if (_cogl_matrix_update_inverse ((CoglMatrix *)matrix)) { cogl_matrix_init_from_array (inverse, matrix->inv); return TRUE;