[mutter/gbsneto/graphene-frustrum: 3/17] clutter/stage: Simplify view setup




commit f9fe8220ff4a74296ebf0b1d3ff8e92a5144d8a8
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Fri Oct 9 15:54:18 2020 -0300

    clutter/stage: Simplify view setup
    
    ClutterStage defines the 8 vertices of a frustum:
    
      4 ----------------------------- 5
      | \                           / |
      |  \                         /  |
      |   0 --------------------- 1   |
      |   |                       |   |
      |   |                       |   |
      |   3 --------------------- 2   |
      |  /                         \  |
      | /                           \ |
      7 ----------------------------- 6
    
    Then, it uses triplets of vertices to create each  clipping plane.
    It only sets up 4 planes (it doesn't clip based on depth), defined
    by the following vertices:
    
     * 0 - 4 - 5
     * 1 - 5 - 6
     * 2 - 6 - 7
     * 0 - 7 - 4
    
    The first 3 triplets are selected using the for-loop. However, the
    last triplet is different, and is done out of the loop. It could
    have been made simpler by using the "3 - 7 - 4" triplet.
    
    Simplify the current code by using the suggested triplet, calculated
    inside the for-loop.
    
    https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1489

 clutter/clutter/clutter-stage.c | 22 ++--------------------
 1 file changed, 2 insertions(+), 20 deletions(-)
---
diff --git a/clutter/clutter/clutter-stage.c b/clutter/clutter/clutter-stage.c
index ac6f500a31..f35f52cb42 100644
--- a/clutter/clutter/clutter-stage.c
+++ b/clutter/clutter/clutter-stage.c
@@ -674,7 +674,6 @@ _cogl_util_get_eye_planes_for_screen_poly (float *polygon,
   graphene_vec3_t b;
   graphene_vec3_t c;
   float zw, ww;
-  int count;
 
   tmp_poly = g_alloca (sizeof (Vector4) * n_vertices * 2);
 
@@ -738,8 +737,7 @@ _cogl_util_get_eye_planes_for_screen_poly (float *polygon,
    * cogl_vector APIs just took pointers to floats.
    */
 
-  count = n_vertices - 1;
-  for (i = 0; i < count; i++)
+  for (i = 0; i < n_vertices; i++)
     {
       plane = &planes[i];
 
@@ -749,7 +747,7 @@ _cogl_util_get_eye_planes_for_screen_poly (float *polygon,
       poly = &tmp_poly[n_vertices + i];
       graphene_vec3_init (&b, poly->x, poly->y, poly->z);
 
-      poly = &tmp_poly[n_vertices + i + 1];
+      poly = &tmp_poly[n_vertices + ((i + 1) % n_vertices)];
       graphene_vec3_init (&c, poly->x, poly->y, poly->z);
 
       graphene_vec3_subtract (&b, &plane->v0, &b);
@@ -757,22 +755,6 @@ _cogl_util_get_eye_planes_for_screen_poly (float *polygon,
       graphene_vec3_cross (&b, &c, &plane->n);
       graphene_vec3_normalize (&plane->n, &plane->n);
     }
-
-  plane = &planes[n_vertices - 1];
-
-  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);
 }
 
 /* XXX: Instead of having a toplevel 2D clip region, it might be


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