[mutter/gbsneto/graphene-matrix: 79/104] cogl/matrix: Make CoglMatrix a typedef to graphene_matrix_t




commit e110e5d34c2b9934c626074b0247ee51a6c0cf72
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Tue Sep 22 09:29:02 2020 -0300

    cogl/matrix: Make CoglMatrix a typedef to graphene_matrix_t
    
    After the previous commit, the only field in the CoglMatrix structure is
    a graphene_matrix_t. That means that CoglMatrix is effectively a graphene
    matrix now, and the CoglMatrix struct isn't that much useful anymore.
    
    Remove the CoglMatrix structure and make the CoglMatrix type a typedef to
    graphene_matrix_t.
    
    https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439

 cogl/cogl/cogl-matrix.c | 60 ++++++++++++++++++++++++-------------------------
 cogl/cogl/cogl-matrix.h | 28 -----------------------
 cogl/cogl/cogl-types.h  |  3 ++-
 3 files changed, 32 insertions(+), 59 deletions(-)
---
diff --git a/cogl/cogl/cogl-matrix.c b/cogl/cogl/cogl-matrix.c
index 10caf69bd3..b7056ffe64 100644
--- a/cogl/cogl/cogl-matrix.c
+++ b/cogl/cogl/cogl-matrix.c
@@ -52,14 +52,14 @@ cogl_matrix_multiply (CoglMatrix *result,
                      const CoglMatrix *a,
                      const CoglMatrix *b)
 {
-  graphene_matrix_multiply (&b->m, &a->m, &result->m);
+  graphene_matrix_multiply (b, a, result);
   _COGL_MATRIX_DEBUG_PRINT (result);
 }
 
 void
 _cogl_matrix_prefix_print (const char *prefix, const CoglMatrix *matrix)
 {
-  graphene_matrix_print (&matrix->m);
+  graphene_matrix_print (matrix);
 }
 
 /*
@@ -94,7 +94,7 @@ calculate_inverse (const CoglMatrix *matrix,
   float pivot = G_MAXFLOAT;
   float scale;
 
-  graphene_matrix_init_from_matrix (&m, &matrix->m);
+  graphene_matrix_init_from_matrix (&m, matrix);
 
   pivot = MIN (pivot, graphene_matrix_get_value (&m, 0, 0));
   pivot = MIN (pivot, graphene_matrix_get_value (&m, 1, 1));
@@ -107,12 +107,12 @@ calculate_inverse (const CoglMatrix *matrix,
   /* Float precision is a limiting factor */
   graphene_matrix_multiply (&m, &scaled, &m);
 
-  invertible = graphene_matrix_inverse (&m, &inverse->m);
+  invertible = graphene_matrix_inverse (&m, inverse);
 
   if (invertible)
-    graphene_matrix_multiply (&scaled, &inverse->m, &inverse->m);
+    graphene_matrix_multiply (&scaled, inverse, inverse);
   else
-    graphene_matrix_init_identity (&inverse->m);
+    graphene_matrix_init_identity (inverse);
 
   return invertible;
 }
@@ -135,7 +135,7 @@ cogl_matrix_rotate (CoglMatrix *matrix,
 
   graphene_vec3_init (&axis, x, y, z);
   graphene_matrix_init_rotate (&rotation, angle, &axis);
-  graphene_matrix_multiply (&rotation, &matrix->m, &matrix->m);
+  graphene_matrix_multiply (&rotation, matrix, matrix);
 
   _COGL_MATRIX_DEBUG_PRINT (matrix);
 }
@@ -165,7 +165,7 @@ cogl_matrix_frustum (CoglMatrix *matrix,
                                 left, right,
                                 bottom, top,
                                 z_near, z_far);
-  graphene_matrix_multiply (&frustum, &matrix->m, &matrix->m);
+  graphene_matrix_multiply (&frustum, matrix, matrix);
 
   _COGL_MATRIX_DEBUG_PRINT (matrix);
 }
@@ -204,7 +204,7 @@ cogl_matrix_orthographic (CoglMatrix *matrix,
                               left, right,
                               top, bottom,
                               near, far);
-  graphene_matrix_multiply (&ortho, &matrix->m, &matrix->m);
+  graphene_matrix_multiply (&ortho, matrix, matrix);
 
   _COGL_MATRIX_DEBUG_PRINT (matrix);
 }
@@ -218,7 +218,7 @@ cogl_matrix_scale (CoglMatrix *matrix,
   graphene_matrix_t scale;
 
   graphene_matrix_init_scale (&scale, sx, sy, sz);
-  graphene_matrix_multiply (&scale, &matrix->m, &matrix->m);
+  graphene_matrix_multiply (&scale, matrix, matrix);
 
   _COGL_MATRIX_DEBUG_PRINT (matrix);
 }
@@ -233,7 +233,7 @@ cogl_matrix_translate (CoglMatrix *matrix,
 
   graphene_matrix_init_translate (&translation,
                                   &GRAPHENE_POINT3D_INIT (x, y, z));
-  graphene_matrix_multiply (&translation, &matrix->m, &matrix->m);
+  graphene_matrix_multiply (&translation, matrix, matrix);
 
   _COGL_MATRIX_DEBUG_PRINT (matrix);
 }
@@ -241,7 +241,7 @@ cogl_matrix_translate (CoglMatrix *matrix,
 void
 cogl_matrix_init_identity (CoglMatrix *matrix)
 {
-  graphene_matrix_init_identity (&matrix->m);
+  graphene_matrix_init_identity (matrix);
   _COGL_MATRIX_DEBUG_PRINT (matrix);
 }
 
@@ -251,7 +251,7 @@ cogl_matrix_init_translation (CoglMatrix *matrix,
                               float       ty,
                               float       tz)
 {
-  graphene_matrix_init_translate (&matrix->m, &GRAPHENE_POINT3D_INIT (tx, ty, tz));
+  graphene_matrix_init_translate (matrix, &GRAPHENE_POINT3D_INIT (tx, ty, tz));
   _COGL_MATRIX_DEBUG_PRINT (matrix);
 }
 
@@ -268,7 +268,7 @@ cogl_matrix_init_translation (CoglMatrix *matrix,
 static void
 _cogl_matrix_init_from_array (CoglMatrix *matrix, const float *array)
 {
-  graphene_matrix_init_from_float (&matrix->m, array);
+  graphene_matrix_init_from_float (matrix, array);
 }
 
 void
@@ -289,15 +289,15 @@ void
 _cogl_matrix_init_from_matrix_without_inverse (CoglMatrix *matrix,
                                                const CoglMatrix *src)
 {
-  graphene_matrix_init_from_matrix (&matrix->m, &src->m);
+  graphene_matrix_init_from_matrix (matrix, src);
 }
 
 void
 cogl_matrix_init_from_euler (CoglMatrix *matrix,
                              const graphene_euler_t *euler)
 {
-  graphene_matrix_init_identity (&matrix->m);
-  graphene_matrix_rotate_euler (&matrix->m, euler);
+  graphene_matrix_init_identity (matrix);
+  graphene_matrix_rotate_euler (matrix, euler);
 }
 
 void
@@ -366,7 +366,7 @@ cogl_matrix_equal (const void *v1, const void *v2)
   g_return_val_if_fail (v1 != NULL, FALSE);
   g_return_val_if_fail (v2 != NULL, FALSE);
 
-  return graphene_matrix_equal_fast (&a->m, &b->m);
+  return graphene_matrix_equal_fast (a, b);
 }
 
 CoglMatrix *
@@ -388,7 +388,7 @@ void
 cogl_matrix_to_float (const CoglMatrix *matrix,
                       float            *out_array)
 {
-  graphene_matrix_to_float (&matrix->m, out_array);
+  graphene_matrix_to_float (matrix, out_array);
 }
 
 float
@@ -396,7 +396,7 @@ cogl_matrix_get_value (const CoglMatrix *matrix,
                        unsigned int      row,
                        unsigned int      column)
 {
-  return graphene_matrix_get_value (&matrix->m, column, row);
+  return graphene_matrix_get_value (matrix, column, row);
 }
 
 void
@@ -409,7 +409,7 @@ cogl_matrix_transform_point (const CoglMatrix *matrix,
   graphene_vec4_t p;
 
   graphene_vec4_init (&p, *x, *y, *z, *w);
-  graphene_matrix_transform_vec4 (&matrix->m, &p, &p);
+  graphene_matrix_transform_vec4 (matrix, &p, &p);
 
   *x = graphene_vec4_get_x (&p);
   *y = graphene_vec4_get_y (&p);
@@ -446,7 +446,7 @@ init_matrix_rows (const CoglMatrix *matrix,
   graphene_matrix_t m;
   unsigned int i;
 
-  graphene_matrix_transpose (&matrix->m, &m);
+  graphene_matrix_transpose (matrix, &m);
 
   for (i = 0; i < n_rows; i++)
     graphene_matrix_get_row (&m, i, &rows[i]);
@@ -651,7 +651,7 @@ cogl_matrix_project_points (const CoglMatrix *matrix,
 gboolean
 cogl_matrix_is_identity (const CoglMatrix *matrix)
 {
-  return graphene_matrix_is_identity (&matrix->m);
+  return graphene_matrix_is_identity (matrix);
 }
 
 void
@@ -675,7 +675,7 @@ cogl_matrix_look_at (CoglMatrix *matrix,
   graphene_vec3_init (&center, object_x, object_y, object_z);
   graphene_vec3_init (&up, world_up_x, world_up_y, world_up_z);
 
-  graphene_matrix_init_look_at (&look_at.m, &eye, &center, &up);
+  graphene_matrix_init_look_at (&look_at, &eye, &center, &up);
 
   cogl_matrix_multiply (matrix, matrix, &look_at);
 }
@@ -684,10 +684,10 @@ void
 cogl_matrix_transpose (CoglMatrix *matrix)
 {
   /* We don't need to do anything if the matrix is the identity matrix */
-  if (graphene_matrix_is_identity (&matrix->m))
+  if (graphene_matrix_is_identity (matrix))
     return;
 
-  graphene_matrix_transpose (&matrix->m, &matrix->m);
+  graphene_matrix_transpose (matrix, matrix);
 }
 
 GType
@@ -704,7 +704,7 @@ cogl_matrix_skew_xy (CoglMatrix *matrix,
 
   graphene_matrix_init_identity (&skew);
   graphene_matrix_skew_xy (&skew, factor);
-  graphene_matrix_multiply (&skew, &matrix->m, &matrix->m);
+  graphene_matrix_multiply (&skew, matrix, matrix);
 
   _COGL_MATRIX_DEBUG_PRINT (matrix);
 }
@@ -717,7 +717,7 @@ cogl_matrix_skew_xz (CoglMatrix *matrix,
 
   graphene_matrix_init_identity (&skew);
   graphene_matrix_skew_xz (&skew, factor);
-  graphene_matrix_multiply (&skew, &matrix->m, &matrix->m);
+  graphene_matrix_multiply (&skew, matrix, matrix);
 
   _COGL_MATRIX_DEBUG_PRINT (matrix);
 }
@@ -730,7 +730,7 @@ cogl_matrix_skew_yz (CoglMatrix *matrix,
 
   graphene_matrix_init_identity (&skew);
   graphene_matrix_skew_yz (&skew, factor);
-  graphene_matrix_multiply (&skew, &matrix->m, &matrix->m);
+  graphene_matrix_multiply (&skew, matrix, matrix);
 
   _COGL_MATRIX_DEBUG_PRINT (matrix);
 }
@@ -738,5 +738,5 @@ cogl_matrix_skew_yz (CoglMatrix *matrix,
 const graphene_matrix_t *
 cogl_matrix_get_graphene_matrix (const CoglMatrix *matrix)
 {
-  return &matrix->m;
+  return matrix;
 }
diff --git a/cogl/cogl/cogl-matrix.h b/cogl/cogl/cogl-matrix.h
index 33344c5817..d18ad674d9 100644
--- a/cogl/cogl/cogl-matrix.h
+++ b/cogl/cogl/cogl-matrix.h
@@ -56,34 +56,6 @@ G_BEGIN_DECLS
  * be used for direct manipulation of these matrices.
  */
 
-/**
- * CoglMatrix:
- *
- * A CoglMatrix holds a 4x4 transform matrix. It uses #graphene_matrix_t
- * internally which means it is compatible with what OpenGL expects.
- *
- * A CoglMatrix can represent transforms such as, rotations, scaling,
- * translation, sheering, and linear projections. You can combine these
- * transforms by multiplying multiple matrices in the order you want them
- * applied.
- *
- * The transformation of a vertex (x, y, z, w) by a CoglMatrix is given by:
- *
- * |[
- *   x_new = xx * x + xy * y + xz * z + xw * w
- *   y_new = yx * x + yy * y + yz * z + yw * w
- *   z_new = zx * x + zy * y + zz * z + zw * w
- *   w_new = wx * x + wy * y + wz * z + ww * w
- * ]|
- *
- * Where w is normally 1
- */
-struct _CoglMatrix
-{
-  /*< private >*/
-  graphene_matrix_t m;
-};
-
 /**
  * cogl_matrix_init_identity:
  * @matrix: A 4x4 transformation matrix
diff --git a/cogl/cogl/cogl-types.h b/cogl/cogl/cogl-types.h
index 35871703d6..6fc9663686 100644
--- a/cogl/cogl/cogl-types.h
+++ b/cogl/cogl/cogl-types.h
@@ -40,6 +40,7 @@
 
 #include <cogl/cogl-defines.h>
 #include <cogl/cogl-macros.h>
+#include <graphene.h>
 
 #include <glib.h>
 #include <glib-object.h>
@@ -87,7 +88,7 @@ cogl_handle_get_type (void) G_GNUC_CONST;
 
 /* We forward declare this in cogl-types to avoid circular dependencies
  * between cogl-matrix.h and cogl-quaterion.h */
-typedef struct _CoglMatrix      CoglMatrix;
+typedef graphene_matrix_t CoglMatrix;
 
 /**
  * CoglAngle:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]