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 <neil@linux.intel.com>
This commit is contained in:
Robert Bragg 2011-06-30 20:33:50 +01:00
parent 7b747cff01
commit ee237be285
4 changed files with 53 additions and 63 deletions

View File

@ -58,10 +58,10 @@
* - instead of allocating matrix->m and matrix->inv using malloc, our * - instead of allocating matrix->m and matrix->inv using malloc, our
* public CoglMatrix typedef is large enough to directly contain the * public CoglMatrix typedef is large enough to directly contain the
* matrix, its inverse, a type and a set of flags. * matrix, its inverse, a type and a set of flags.
* - instead of having a _math_matrix_analyse which updates the type, * - instead of having a _cogl_matrix_analyse which updates the type,
* flags and inverse, we have _math_matrix_update_inverse which * flags and inverse, we have _cogl_matrix_update_inverse which
* essentially does the same thing (internally making use of * 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. * place to bail out when the inverse matrix is still valid.
* - when initializing a matrix with the identity matrix we don't * - when initializing a matrix with the identity matrix we don't
* immediately initialize the inverse matrix; rather we just set the * immediately initialize the inverse matrix; rather we just set the
@ -290,7 +290,7 @@ matrix_multiply_array_with_flags (CoglMatrix *result,
* otherwise. * otherwise.
*/ */
void void
_math_matrix_multiply (CoglMatrix *result, _cogl_matrix_multiply (CoglMatrix *result,
const CoglMatrix *a, const CoglMatrix *a,
const CoglMatrix *b) const CoglMatrix *b)
{ {
@ -315,7 +315,7 @@ _math_matrix_multiply (CoglMatrix *result,
* Calls matrix_multiply4x4() for the multiplication. * Calls matrix_multiply4x4() for the multiplication.
*/ */
void void
_math_matrix_multiply_array (CoglMatrix *result, const float *array) _cogl_matrix_multiply_array (CoglMatrix *result, const float *array)
{ {
result->flags |= (MAT_FLAG_GENERAL | result->flags |= (MAT_FLAG_GENERAL |
MAT_DIRTY_TYPE | MAT_DIRTY_TYPE |
@ -330,7 +330,7 @@ _math_matrix_multiply_array (CoglMatrix *result, const float *array)
* *
* @m matrix 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 static void
print_matrix_floats (const float m[16]) print_matrix_floats (const float m[16])
@ -346,7 +346,7 @@ print_matrix_floats (const float m[16])
* @m pointer to the CoglMatrix structure. * @m pointer to the CoglMatrix structure.
*/ */
void void
_math_matrix_print (const CoglMatrix *matrix) _cogl_matrix_print (const CoglMatrix *matrix)
{ {
g_print ("Matrix type: %s, flags: %x\n", g_print ("Matrix type: %s, flags: %x\n",
types[matrix->type], (int)matrix->flags); 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. * and copies the identity matrix into CoglMatrix::inv.
*/ */
gboolean gboolean
_math_matrix_update_inverse (CoglMatrix *matrix) _cogl_matrix_update_inverse (CoglMatrix *matrix)
{ {
if (matrix->flags & MAT_DIRTY_FLAGS || if (matrix->flags & MAT_DIRTY_FLAGS ||
matrix->flags & MAT_DIRTY_INVERSE) 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)) if (inv_mat_tab[matrix->type](matrix))
matrix->flags &= ~MAT_FLAG_SINGULAR; matrix->flags &= ~MAT_FLAG_SINGULAR;
@ -877,7 +877,7 @@ _math_matrix_update_inverse (CoglMatrix *matrix)
* Optimizations contributed by Rudolf Opalla (rudi@khm.de). * Optimizations contributed by Rudolf Opalla (rudi@khm.de).
*/ */
void void
_math_matrix_rotate (CoglMatrix *matrix, _cogl_matrix_rotate (CoglMatrix *matrix,
float angle, float angle,
float x, float x,
float y, float y,
@ -1078,7 +1078,7 @@ _math_matrix_rotate (CoglMatrix *matrix,
* MAT_FLAG_PERSPECTIVE flag. * MAT_FLAG_PERSPECTIVE flag.
*/ */
void void
_math_matrix_frustum (CoglMatrix *matrix, _cogl_matrix_frustum (CoglMatrix *matrix,
float left, float left,
float right, float right,
float bottom, float bottom,
@ -1121,7 +1121,7 @@ _math_matrix_frustum (CoglMatrix *matrix,
* MAT_FLAG_GENERAL_SCALE and MAT_FLAG_TRANSLATION flags. * MAT_FLAG_GENERAL_SCALE and MAT_FLAG_TRANSLATION flags.
*/ */
void void
_math_matrix_ortho (CoglMatrix *matrix, _cogl_matrix_ortho (CoglMatrix *matrix,
float left, float left,
float right, float right,
float bottom, float bottom,
@ -1172,7 +1172,7 @@ _math_matrix_ortho (CoglMatrix *matrix,
* MAT_DIRTY_INVERSE dirty flags. * MAT_DIRTY_INVERSE dirty flags.
*/ */
void 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; float *m = (float *)matrix;
m[0] *= x; m[4] *= y; m[8] *= z; 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. * dirty flags.
*/ */
void 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; float *m = (float *)matrix;
m[12] = m[0] * x + m[4] * y + m[8] * z + m[12]; 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. * Transforms Normalized Device Coords to window/Z values.
*/ */
void void
_math_matrix_viewport (CoglMatrix *matrix, _cogl_matrix_viewport (CoglMatrix *matrix,
float x, float y, float x, float y,
float width, float height, float width, float height,
float zNear, float zFar, float depthMax) 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. * doesn't initialize the inverse matrix, it just marks it dirty.
*/ */
void void
_math_matrix_init_identity (CoglMatrix *matrix) _cogl_matrix_init_identity (CoglMatrix *matrix)
{ {
memcpy (matrix, identity, 16 * sizeof (float)); memcpy (matrix, identity, 16 * sizeof (float));
@ -1469,7 +1469,7 @@ analyse_from_flags (CoglMatrix *matrix)
* then calls matrix_invert(). Finally clears the dirty flags. * then calls matrix_invert(). Finally clears the dirty flags.
*/ */
void void
_math_matrix_update_type_and_flags (CoglMatrix *matrix) _cogl_matrix_update_type_and_flags (CoglMatrix *matrix)
{ {
if (matrix->flags & MAT_DIRTY_TYPE) 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. * Test if the given matrix preserves vector lengths.
*/ */
gboolean 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); 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) * (or perhaps if the upper-left 3x3 is non-identity)
*/ */
gboolean gboolean
_math_matrix_has_rotation (const CoglMatrix *matrix) _cogl_matrix_has_rotation (const CoglMatrix *matrix)
{ {
if (matrix->flags & (MAT_FLAG_GENERAL | if (matrix->flags & (MAT_FLAG_GENERAL |
MAT_FLAG_ROTATION | MAT_FLAG_ROTATION |
@ -1508,13 +1508,13 @@ _math_matrix_has_rotation (const CoglMatrix *matrix)
} }
gboolean 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; return (matrix->flags & MAT_FLAG_GENERAL_SCALE) ? TRUE : FALSE;
} }
gboolean gboolean
_math_matrix_is_dirty (const CoglMatrix *matrix) _cogl_matrix_is_dirty (const CoglMatrix *matrix)
{ {
return (matrix->flags & MAT_DIRTY_ALL) ? TRUE : FALSE; return (matrix->flags & MAT_DIRTY_ALL) ? TRUE : FALSE;
} }
@ -1530,14 +1530,14 @@ _math_matrix_is_dirty (const CoglMatrix *matrix)
* flags. * flags.
*/ */
void 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)); memcpy (matrix, array, 16 * sizeof (float));
matrix->flags = (MAT_FLAG_GENERAL | MAT_DIRTY_ALL); matrix->flags = (MAT_FLAG_GENERAL | MAT_DIRTY_ALL);
} }
void void
_math_matrix_init_from_quaternion (CoglMatrix *matrix, _cogl_matrix_init_from_quaternion (CoglMatrix *matrix,
CoglQuaternion *quaternion) CoglQuaternion *quaternion)
{ {
float qnorm = _COGL_QUATERNION_NORM (quaternion); float qnorm = _COGL_QUATERNION_NORM (quaternion);

View File

@ -82,72 +82,72 @@ enum CoglMatrixType {
} ; } ;
void void
_math_matrix_multiply (CoglMatrix *result, _cogl_matrix_multiply (CoglMatrix *result,
const CoglMatrix *a, const CoglMatrix *a,
const CoglMatrix *b); const CoglMatrix *b);
void void
_math_matrix_multiply_array (CoglMatrix *result, const float *b); _cogl_matrix_multiply_array (CoglMatrix *result, const float *b);
void void
_math_matrix_init_from_array (CoglMatrix *matrix, const float *array); _cogl_matrix_init_from_array (CoglMatrix *matrix, const float *array);
void void
_math_matrix_init_from_quaternion (CoglMatrix *matrix, _cogl_matrix_init_from_quaternion (CoglMatrix *matrix,
CoglQuaternion *quaternion); CoglQuaternion *quaternion);
void void
_math_matrix_translate (CoglMatrix *matrix, float x, float y, float z); _cogl_matrix_translate (CoglMatrix *matrix, float x, float y, float z);
void void
_math_matrix_rotate (CoglMatrix *matrix, float angle, _cogl_matrix_rotate (CoglMatrix *matrix, float angle,
float x, float y, float z); float x, float y, float z);
void void
_math_matrix_scale (CoglMatrix *matrix, float x, float y, float z); _cogl_matrix_scale (CoglMatrix *matrix, float x, float y, float z);
void void
_math_matrix_ortho (CoglMatrix *matrix, _cogl_matrix_ortho (CoglMatrix *matrix,
float left, float right, float left, float right,
float bottom, float top, float bottom, float top,
float nearval, float farval); float nearval, float farval);
void void
_math_matrix_frustum (CoglMatrix *matrix, _cogl_matrix_frustum (CoglMatrix *matrix,
float left, float right, float left, float right,
float bottom, float top, float bottom, float top,
float nearval, float farval); float nearval, float farval);
void void
_math_matrix_viewport (CoglMatrix *matrix, _cogl_matrix_viewport (CoglMatrix *matrix,
float x, float y, float width, float height, float x, float y, float width, float height,
float z_near, float z_far, float depth_max); float z_near, float z_far, float depth_max);
void void
_math_matrix_init_identity (CoglMatrix *matrix); _cogl_matrix_init_identity (CoglMatrix *matrix);
gboolean gboolean
_math_matrix_update_inverse (CoglMatrix *matrix); _cogl_matrix_update_inverse (CoglMatrix *matrix);
void void
_math_matrix_update_type_and_flags (CoglMatrix *matrix); _cogl_matrix_update_type_and_flags (CoglMatrix *matrix);
void void
_math_matrix_print (const CoglMatrix *matrix); _cogl_matrix_print (const CoglMatrix *matrix);
gboolean gboolean
_math_matrix_is_length_preserving (const CoglMatrix *matrix); _cogl_matrix_is_length_preserving (const CoglMatrix *matrix);
gboolean gboolean
_math_matrix_has_rotation (const CoglMatrix *matrix); _cogl_matrix_has_rotation (const CoglMatrix *matrix);
gboolean gboolean
_math_matrix_is_general_scale (const CoglMatrix *matrix); _cogl_matrix_is_general_scale (const CoglMatrix *matrix);
gboolean gboolean
_math_matrix_is_dirty (const CoglMatrix *matrix); _cogl_matrix_is_dirty (const CoglMatrix *matrix);
void void
_math_transposef ( float to[16], const float from[16]); _cogl_matrix_util_transposef ( float to[16], const float from[16]);
#endif #endif

View File

@ -39,7 +39,7 @@ G_BEGIN_DECLS
} }
void void
_cogl_matrix_print (CoglMatrix *matrix); _cogl_matrix_print (const CoglMatrix *matrix);
G_END_DECLS G_END_DECLS

View File

@ -51,16 +51,6 @@ COGL_GTYPE_DEFINE_BOXED ("Matrix", matrix,
cogl_matrix_free); cogl_matrix_free);
#endif #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 void
cogl_matrix_init_identity (CoglMatrix *matrix) 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->zx = 0; matrix->zy = 0; matrix->zz = 1; matrix->zw = 0;
matrix->wx = 0; matrix->wy = 0; matrix->wz = 0; matrix->ww = 1; matrix->wx = 0; matrix->wy = 0; matrix->wz = 0; matrix->ww = 1;
#else #else
_math_matrix_init_identity (matrix); _cogl_matrix_init_identity (matrix);
#endif #endif
_COGL_MATRIX_DEBUG_PRINT (matrix); _COGL_MATRIX_DEBUG_PRINT (matrix);
} }
@ -79,7 +69,7 @@ void
cogl_matrix_init_from_quaternion (CoglMatrix *matrix, cogl_matrix_init_from_quaternion (CoglMatrix *matrix,
CoglQuaternion *quaternion) CoglQuaternion *quaternion)
{ {
_math_matrix_init_from_quaternion (matrix, quaternion); _cogl_matrix_init_from_quaternion (matrix, quaternion);
} }
void void
@ -121,7 +111,7 @@ cogl_matrix_multiply (CoglMatrix *result,
*result = r; *result = r;
#else #else
_math_matrix_multiply (result, a, b); _cogl_matrix_multiply (result, a, b);
#endif #endif
_COGL_MATRIX_DEBUG_PRINT (result); _COGL_MATRIX_DEBUG_PRINT (result);
} }
@ -165,7 +155,7 @@ cogl_matrix_rotate (CoglMatrix *matrix,
cogl_matrix_multiply (&result, matrix, &rotation); cogl_matrix_multiply (&result, matrix, &rotation);
*matrix = result; *matrix = result;
#else #else
_math_matrix_rotate (matrix, angle, x, y, z); _cogl_matrix_rotate (matrix, angle, x, y, z);
#endif #endif
_COGL_MATRIX_DEBUG_PRINT (matrix); _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->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; matrix->ww = matrix->wx * x + matrix->wy * y + matrix->wz * z + matrix->ww;
#else #else
_math_matrix_translate (matrix, x, y, z); _cogl_matrix_translate (matrix, x, y, z);
#endif #endif
_COGL_MATRIX_DEBUG_PRINT (matrix); _COGL_MATRIX_DEBUG_PRINT (matrix);
} }
@ -199,7 +189,7 @@ cogl_matrix_scale (CoglMatrix *matrix,
matrix->zx *= sx; matrix->zy *= sy; matrix->zz *= sz; matrix->zx *= sx; matrix->zy *= sy; matrix->zz *= sz;
matrix->wx *= sx; matrix->wy *= sy; matrix->wz *= sz; matrix->wx *= sx; matrix->wy *= sy; matrix->wz *= sz;
#else #else
_math_matrix_scale (matrix, sx, sy, sz); _cogl_matrix_scale (matrix, sx, sy, sz);
#endif #endif
_COGL_MATRIX_DEBUG_PRINT (matrix); _COGL_MATRIX_DEBUG_PRINT (matrix);
} }
@ -246,7 +236,7 @@ cogl_matrix_frustum (CoglMatrix *matrix,
cogl_matrix_multiply (matrix, matrix, &frustum); cogl_matrix_multiply (matrix, matrix, &frustum);
#else #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 #endif
_COGL_MATRIX_DEBUG_PRINT (matrix); _COGL_MATRIX_DEBUG_PRINT (matrix);
} }
@ -308,7 +298,7 @@ cogl_matrix_ortho (CoglMatrix *matrix,
cogl_matrix_multiply (matrix, matrix, &ortho); cogl_matrix_multiply (matrix, matrix, &ortho);
#else #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 #endif
_COGL_MATRIX_DEBUG_PRINT (matrix); _COGL_MATRIX_DEBUG_PRINT (matrix);
} }
@ -376,7 +366,7 @@ cogl_matrix_init_from_array (CoglMatrix *matrix, const float *array)
#ifndef USE_MESA_MATRIX_API #ifndef USE_MESA_MATRIX_API
memcpy (matrix, array, sizeof (float) * 16); memcpy (matrix, array, sizeof (float) * 16);
#else #else
_math_matrix_init_from_array (matrix, array); _cogl_matrix_init_from_array (matrix, array);
#endif #endif
_COGL_MATRIX_DEBUG_PRINT (matrix); _COGL_MATRIX_DEBUG_PRINT (matrix);
} }
@ -455,7 +445,7 @@ cogl_matrix_get_inverse (const CoglMatrix *matrix, CoglMatrix *inverse)
cogl_matrix_init_identity (inverse); cogl_matrix_init_identity (inverse);
return FALSE; return FALSE;
#else #else
if (_math_matrix_update_inverse ((CoglMatrix *)matrix)) if (_cogl_matrix_update_inverse ((CoglMatrix *)matrix))
{ {
cogl_matrix_init_from_array (inverse, matrix->inv); cogl_matrix_init_from_array (inverse, matrix->inv);
return TRUE; return TRUE;