[mutter/gbsneto/graphene: 9/15] Replace CoglVector* by graphene_vec*_t



commit f76b3e59b130bf8b4ae600173dd614b173f82787
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Mon Feb 18 15:25:31 2019 -0300

    Replace CoglVector* by graphene_vec*_t
    
    This is an extremely straightforward and minimalistic port of
    CoglVector APIs to the corresponding Graphene APIs.
    
    Make ClutterPlane use graphene_vec3_t internally too, for the
    simplest purpose of keeping the patch focused.
    
    https://gitlab.gnome.org/GNOME/mutter/merge_requests/458

 clutter/clutter/clutter-paint-volume.c |  20 +-
 clutter/clutter/clutter-private.h      |   4 +-
 clutter/clutter/clutter-stage.c        |  47 +++--
 cogl/cogl/cogl-matrix.c                |  43 ++--
 cogl/cogl/cogl-vector.c                | 298 ---------------------------
 cogl/cogl/cogl-vector.h                | 356 ---------------------------------
 cogl/cogl/cogl.h                       |   1 -
 cogl/cogl/cogl.symbols                 |  17 --
 cogl/cogl/meson.build                  |   2 -
 9 files changed, 61 insertions(+), 727 deletions(-)
---
diff --git a/clutter/clutter/clutter-paint-volume.c b/clutter/clutter/clutter-paint-volume.c
index 6adf626a4..0a197cdf6 100644
--- a/clutter/clutter/clutter-paint-volume.c
+++ b/clutter/clutter/clutter-paint-volume.c
@@ -1097,24 +1097,18 @@ _clutter_paint_volume_cull (ClutterPaintVolume *pv,
 
   for (i = 0; i < 4; i++)
     {
+      const ClutterPlane *plane = &planes[i];
       int out = 0;
       for (j = 0; j < vertex_count; j++)
         {
-          ClutterVertex p;
-          float distance;
+          graphene_vec3_t v;
 
-          /* XXX: for perspective projections this can be optimized
-           * out because all the planes should pass through the origin
-           * so (0,0,0) is a valid v0. */
-          p.x = vertices[j].x - planes[i].v0[0];
-          p.y = vertices[j].y - planes[i].v0[1];
-          p.z = vertices[j].z - planes[i].v0[2];
+          graphene_vec3_init (&v,
+                              vertices[j].x - graphene_vec3_get_x (&plane->v0),
+                              vertices[j].y - graphene_vec3_get_y (&plane->v0),
+                              vertices[j].z - graphene_vec3_get_z (&plane->v0));
 
-          distance = (planes[i].n[0] * p.x +
-                      planes[i].n[1] * p.y +
-                      planes[i].n[2] * p.z);
-
-          if (distance < 0)
+          if (graphene_vec3_dot (&plane->n, &v) < 0)
             out++;
         }
 
diff --git a/clutter/clutter/clutter-private.h b/clutter/clutter/clutter-private.h
index fb94bfa07..24ada7247 100644
--- a/clutter/clutter/clutter-private.h
+++ b/clutter/clutter/clutter-private.h
@@ -292,8 +292,8 @@ PangoDirection _clutter_pango_find_base_dir     (const gchar *text,
 
 typedef struct _ClutterPlane
 {
-  float v0[3];
-  float n[3];
+  graphene_vec3_t v0;
+  graphene_vec3_t n;
 } ClutterPlane;
 
 typedef enum _ClutterCullResult
diff --git a/clutter/clutter/clutter-stage.c b/clutter/clutter/clutter-stage.c
index eabcaeaf0..a72b81b04 100644
--- a/clutter/clutter/clutter-stage.c
+++ b/clutter/clutter/clutter-stage.c
@@ -715,8 +715,9 @@ _cogl_util_get_eye_planes_for_screen_poly (float *polygon,
   Vector4 *tmp_poly;
   ClutterPlane *plane;
   int i;
-  float b[3];
-  float c[3];
+  Vector4 *poly;
+  graphene_vec3_t b;
+  graphene_vec3_t c;
   int count;
 
   tmp_poly = g_alloca (sizeof (Vector4) * n_vertices * 2);
@@ -783,23 +784,37 @@ _cogl_util_get_eye_planes_for_screen_poly (float *polygon,
   for (i = 0; i < count; i++)
     {
       plane = &planes[i];
-      memcpy (plane->v0, tmp_poly + i, sizeof (float) * 3);
-      memcpy (b, tmp_poly + n_vertices + i, sizeof (float) * 3);
-      memcpy (c, tmp_poly + n_vertices + i + 1, sizeof (float) * 3);
-      cogl_vector3_subtract (b, b, plane->v0);
-      cogl_vector3_subtract (c, c, plane->v0);
-      cogl_vector3_cross_product (plane->n, b, c);
-      cogl_vector3_normalize (plane->n);
+
+      poly = &tmp_poly[i];
+      graphene_vec3_init (&plane->v0, poly->x, poly->y, poly->z);
+
+      poly = &tmp_poly[n_vertices + i];
+      graphene_vec3_init (&b, poly->x, poly->y, poly->z);
+
+      poly = &tmp_poly[n_vertices + i + 1];
+      graphene_vec3_init (&c, poly->x, poly->y, poly->z);
+
+      graphene_vec3_subtract (&b, &plane->v0, &b);
+      graphene_vec3_subtract (&c, &plane->v0, &c);
+      graphene_vec3_cross (&b, &c, &plane->n);
+      graphene_vec3_normalize (&plane->n, &plane->n);
     }
 
   plane = &planes[n_vertices - 1];
-  memcpy (plane->v0, tmp_poly + 0, sizeof (float) * 3);
-  memcpy (b, tmp_poly + (2 * n_vertices - 1), sizeof (float) * 3);
-  memcpy (c, tmp_poly + n_vertices, sizeof (float) * 3);
-  cogl_vector3_subtract (b, b, plane->v0);
-  cogl_vector3_subtract (c, c, plane->v0);
-  cogl_vector3_cross_product (plane->n, b, c);
-  cogl_vector3_normalize (plane->n);
+
+  poly = &tmp_poly[0];
+  graphene_vec3_init (&plane->v0, poly->x, poly->y, poly->z);
+
+  poly = &tmp_poly[2 * n_vertices - 1];
+  graphene_vec3_init (&b, poly->x, poly->y, poly->z);
+
+  poly = &tmp_poly[n_vertices];
+  graphene_vec3_init (&c, poly->x, poly->y, poly->z);
+
+  graphene_vec3_subtract (&b, &plane->v0, &b);
+  graphene_vec3_subtract (&c, &plane->v0, &c);
+  graphene_vec3_cross (&b, &c, &plane->n);
+  graphene_vec3_normalize (&plane->n, &plane->n);
 }
 
 static void
diff --git a/cogl/cogl/cogl-matrix.c b/cogl/cogl/cogl-matrix.c
index 185ded57a..02c38344e 100644
--- a/cogl/cogl/cogl-matrix.c
+++ b/cogl/cogl/cogl-matrix.c
@@ -75,7 +75,6 @@
 #include <cogl-debug.h>
 #include <cogl-matrix.h>
 #include <cogl-matrix-private.h>
-#include <cogl-vector.h>
 
 #include <glib.h>
 #include <math.h>
@@ -2184,41 +2183,41 @@ cogl_matrix_look_at (CoglMatrix *matrix,
                      float world_up_z)
 {
   CoglMatrix tmp;
-  float forward[3];
-  float side[3];
-  float up[3];
+  graphene_vec3_t forward;
+  graphene_vec3_t side;
+  graphene_vec3_t up;
 
   /* Get a unit viewing direction vector */
-  cogl_vector3_init (forward,
-                     object_x - eye_position_x,
-                     object_y - eye_position_y,
-                     object_z - eye_position_z);
-  cogl_vector3_normalize (forward);
+  graphene_vec3_init (&forward,
+                      object_x - eye_position_x,
+                      object_y - eye_position_y,
+                      object_z - eye_position_z);
+  graphene_vec3_normalize (&forward, &forward);
 
-  cogl_vector3_init (up, world_up_x, world_up_y, world_up_z);
+  graphene_vec3_init (&up, world_up_x, world_up_y, world_up_z);
 
   /* Take the sideways direction as being perpendicular to the viewing
    * direction and the word up vector. */
-  cogl_vector3_cross_product (side, forward, up);
-  cogl_vector3_normalize (side);
+  graphene_vec3_cross (&forward, &up, &side);
+  graphene_vec3_normalize (&side, &side);
 
   /* Now we have unit sideways and forward-direction vectors calculate
    * a new mutually perpendicular up vector. */
-  cogl_vector3_cross_product (up, side, forward);
+  graphene_vec3_cross (&side, &forward, &up);
 
-  tmp.xx = side[0];
-  tmp.yx = side[1];
-  tmp.zx = side[2];
+  tmp.xx = graphene_vec3_get_x (&side);
+  tmp.yx = graphene_vec3_get_y (&side);
+  tmp.zx = graphene_vec3_get_z (&side);
   tmp.wx = 0;
 
-  tmp.xy = up[0];
-  tmp.yy = up[1];
-  tmp.zy = up[2];
+  tmp.xy = graphene_vec3_get_x (&up);
+  tmp.yy = graphene_vec3_get_y (&up);
+  tmp.zy = graphene_vec3_get_z (&up);
   tmp.wy = 0;
 
-  tmp.xz = -forward[0];
-  tmp.yz = -forward[1];
-  tmp.zz = -forward[2];
+  tmp.xz = -graphene_vec3_get_x (&forward);
+  tmp.yz = -graphene_vec3_get_y (&forward);
+  tmp.zz = -graphene_vec3_get_z (&forward);
   tmp.wz = 0;
 
   tmp.xw = 0;
diff --git a/cogl/cogl/cogl.h b/cogl/cogl/cogl.h
index e0c93c873..d93cb1b09 100644
--- a/cogl/cogl/cogl.h
+++ b/cogl/cogl/cogl.h
@@ -101,7 +101,6 @@
 #include <cogl/cogl-context.h>
 #include <cogl/cogl-buffer.h>
 #include <cogl/cogl-pixel-buffer.h>
-#include <cogl/cogl-vector.h>
 #include <cogl/cogl-texture-2d.h>
 #include <cogl/cogl-texture-2d-gl.h>
 #include <cogl/cogl-texture-2d-sliced.h>
diff --git a/cogl/cogl/cogl.symbols b/cogl/cogl/cogl.symbols
index e0a9b57d8..d3d914095 100644
--- a/cogl/cogl/cogl.symbols
+++ b/cogl/cogl/cogl.symbols
@@ -885,23 +885,6 @@ cogl_texture_2d_sliced_new_with_size
 cogl_transform
 cogl_translate
 
-cogl_vector3_add
-cogl_vector3_copy
-cogl_vector3_cross_product
-cogl_vector3_distance
-cogl_vector3_divide_scalar
-cogl_vector3_dot_product
-cogl_vector3_equal
-cogl_vector3_equal_with_epsilon
-cogl_vector3_free
-cogl_vector3_init
-cogl_vector3_init_zero
-cogl_vector3_invert
-cogl_vector3_magnitude
-cogl_vector3_multiply_scalar
-cogl_vector3_normalize
-cogl_vector3_subtract
-
 cogl_vertex_buffer_add
 cogl_vertex_buffer_delete
 cogl_vertex_buffer_disable
diff --git a/cogl/cogl/meson.build b/cogl/cogl/meson.build
index ed20e46a6..261955796 100644
--- a/cogl/cogl/meson.build
+++ b/cogl/cogl/meson.build
@@ -112,7 +112,6 @@ cogl_nonintrospected_headers = [
   'cogl-attribute.h',
   'cogl-primitive.h',
   'cogl-frame-info.h',
-  'cogl-vector.h',
   'cogl-output.h',
   'cogl-matrix-stack.h',
   'cogl-poll.h',
@@ -264,7 +263,6 @@ cogl_sources = [
   'cogl-primitive-private.h',
   'cogl-primitive.c',
   'cogl-matrix.c',
-  'cogl-vector.c',
   'cogl-matrix-private.h',
   'cogl-matrix-stack.c',
   'cogl-matrix-stack-private.h',


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