[mutter/gbsneto/graphene-frustrum: 2/16] clutter/stage: Use graphene_plane_t for clipping planes




commit f718dde022ee02fa21b1c75a17333429d9d200df
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Fri Oct 9 16:29:52 2020 -0300

    clutter/stage: Use graphene_plane_t for clipping planes
    
    It allows us to remove quite a bunch of code, and not deal with part
    of the mind-melting maths behind it.

 clutter/clutter/clutter-actor.c                |  2 +-
 clutter/clutter/clutter-paint-volume-private.h |  4 +--
 clutter/clutter/clutter-paint-volume.c         | 15 +++-------
 clutter/clutter/clutter-stage-private.h        |  2 +-
 clutter/clutter/clutter-stage.c                | 40 +++++++++++++++-----------
 5 files changed, 31 insertions(+), 32 deletions(-)
---
diff --git a/clutter/clutter/clutter-actor.c b/clutter/clutter/clutter-actor.c
index 68290b986d..ecae675564 100644
--- a/clutter/clutter/clutter-actor.c
+++ b/clutter/clutter/clutter-actor.c
@@ -3442,7 +3442,7 @@ cull_actor (ClutterActor        *self,
 {
   ClutterActorPrivate *priv = self->priv;
   ClutterStage *stage;
-  const ClutterPlane *stage_clip;
+  const graphene_plane_t *stage_clip;
 
   if (!priv->last_paint_volume_valid)
     {
diff --git a/clutter/clutter/clutter-paint-volume-private.h b/clutter/clutter/clutter-paint-volume-private.h
index 48524f4223..5d160c3806 100644
--- a/clutter/clutter/clutter-paint-volume-private.h
+++ b/clutter/clutter/clutter-paint-volume-private.h
@@ -123,8 +123,8 @@ void                _clutter_paint_volume_axis_align           (ClutterPaintVolu
 void                _clutter_paint_volume_set_reference_actor  (ClutterPaintVolume *pv,
                                                                 ClutterActor *actor);
 
-ClutterCullResult   _clutter_paint_volume_cull                 (ClutterPaintVolume *pv,
-                                                                const ClutterPlane       *planes);
+ClutterCullResult   _clutter_paint_volume_cull                 (ClutterPaintVolume     *pv,
+                                                                const graphene_plane_t *planes);
 
 void                _clutter_paint_volume_get_stage_paint_box  (ClutterPaintVolume *pv,
                                                                 ClutterStage *stage,
diff --git a/clutter/clutter/clutter-paint-volume.c b/clutter/clutter/clutter-paint-volume.c
index c78bfb6c95..705b276349 100644
--- a/clutter/clutter/clutter-paint-volume.c
+++ b/clutter/clutter/clutter-paint-volume.c
@@ -1071,8 +1071,8 @@ _clutter_paint_volume_set_reference_actor (ClutterPaintVolume *pv,
 }
 
 ClutterCullResult
-_clutter_paint_volume_cull (ClutterPaintVolume *pv,
-                            const ClutterPlane *planes)
+_clutter_paint_volume_cull (ClutterPaintVolume     *pv,
+                            const graphene_plane_t *planes)
 {
   int vertex_count;
   graphene_point3d_t *vertices = pv->vertices;
@@ -1097,18 +1097,11 @@ _clutter_paint_volume_cull (ClutterPaintVolume *pv,
 
   for (i = 0; i < 4; i++)
     {
-      const ClutterPlane *plane = &planes[i];
+      const graphene_plane_t *plane = &planes[i];
       int out = 0;
       for (j = 0; j < vertex_count; j++)
         {
-          graphene_vec3_t v;
-
-          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));
-
-          if (graphene_vec3_dot (&plane->n, &v) < 0)
+          if (graphene_plane_distance (plane, &vertices[j]) < 0)
             out++;
         }
 
diff --git a/clutter/clutter/clutter-stage-private.h b/clutter/clutter/clutter-stage-private.h
index ef5ce1da49..8c3d1317a7 100644
--- a/clutter/clutter/clutter-stage-private.h
+++ b/clutter/clutter/clutter-stage-private.h
@@ -98,7 +98,7 @@ ClutterActor *_clutter_stage_do_pick (ClutterStage    *stage,
 ClutterPaintVolume *_clutter_stage_paint_volume_stack_allocate (ClutterStage *stage);
 void                _clutter_stage_paint_volume_stack_free_all (ClutterStage *stage);
 
-const ClutterPlane *_clutter_stage_get_clip (ClutterStage *stage);
+const graphene_plane_t *_clutter_stage_get_clip (ClutterStage *stage);
 
 ClutterStageQueueRedrawEntry *_clutter_stage_queue_actor_redraw            (ClutterStage                 
*stage,
                                                                             ClutterStageQueueRedrawEntry 
*entry,
diff --git a/clutter/clutter/clutter-stage.c b/clutter/clutter/clutter-stage.c
index e9d06cbd23..0b1b193468 100644
--- a/clutter/clutter/clutter-stage.c
+++ b/clutter/clutter/clutter-stage.c
@@ -115,7 +115,7 @@ struct _ClutterStagePrivate
 
   GArray *paint_volume_stack;
 
-  ClutterPlane current_clip_planes[4];
+  graphene_plane_t current_clip_planes[4];
 
   GSList *pending_relayouts;
   GList *pending_queue_redraws;
@@ -659,20 +659,17 @@ typedef struct _Vector4
 } Vector4;
 
 static void
-_cogl_util_get_eye_planes_for_screen_poly (float *polygon,
-                                           int n_vertices,
-                                           float *viewport,
+_cogl_util_get_eye_planes_for_screen_poly (float                   *polygon,
+                                           int                      n_vertices,
+                                           float                   *viewport,
                                            const graphene_matrix_t *projection,
                                            const graphene_matrix_t *inverse_project,
-                                           ClutterPlane *planes)
+                                           graphene_plane_t        *planes)
 {
   float Wc;
   Vector4 *tmp_poly;
-  ClutterPlane *plane;
   int i;
   Vector4 *poly;
-  graphene_vec3_t b;
-  graphene_vec3_t c;
   float zw, ww;
 
   tmp_poly = g_alloca (sizeof (Vector4) * n_vertices * 2);
@@ -732,6 +729,18 @@ _cogl_util_get_eye_planes_for_screen_poly (float *polygon,
                                        tmp_poly,
                                        n_vertices * 2);
 
+#define ROUND_TO_256THS(x) (roundf ((x) * 256) / 256)
+
+  for (i = 0; i < 2 * n_vertices; i++)
+    {
+      tmp_poly[i].x = ROUND_TO_256THS (tmp_poly[i].x);
+      tmp_poly[i].y = ROUND_TO_256THS (tmp_poly[i].y);
+      tmp_poly[i].z = ROUND_TO_256THS (tmp_poly[i].z);
+      tmp_poly[i].w = ROUND_TO_256THS (tmp_poly[i].w);
+    }
+
+#undef ROUND_TO_256THS
+
   /* XXX: It's quite ugly that we end up with these casts between
    * Vector4 types and CoglVector3s, it might be better if the
    * cogl_vector APIs just took pointers to floats.
@@ -739,21 +748,18 @@ _cogl_util_get_eye_planes_for_screen_poly (float *polygon,
 
   for (i = 0; i < n_vertices; i++)
     {
-      plane = &planes[i];
+      graphene_point3d_t p[3];
 
       poly = &tmp_poly[i];
-      graphene_vec3_init (&plane->v0, poly->x, poly->y, poly->z);
+      graphene_point3d_init (&p[0], poly->x, poly->y, poly->z);
 
       poly = &tmp_poly[n_vertices + i];
-      graphene_vec3_init (&b, poly->x, poly->y, poly->z);
+      graphene_point3d_init (&p[1], poly->x, poly->y, poly->z);
 
       poly = &tmp_poly[n_vertices + ((i + 1) % n_vertices)];
-      graphene_vec3_init (&c, poly->x, poly->y, poly->z);
+      graphene_point3d_init (&p[2], 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);
+      graphene_plane_init_from_points (&planes[i], &p[0], &p[1], &p[2]);
     }
 }
 
@@ -3081,7 +3087,7 @@ _clutter_stage_paint_volume_stack_free_all (ClutterStage *stage)
 
 /* The is an out-of-band parameter available while painting that
  * can be used to cull actors. */
-const ClutterPlane *
+const graphene_plane_t *
 _clutter_stage_get_clip (ClutterStage *stage)
 {
   return stage->priv->current_clip_planes;


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