[mutter/gbsneto/graphene-matrix: 37/57] clutter/stage: Setup 2D view internally




commit 930f45536e9203751853707f2c3ea4c480253136
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Fri Sep 11 16:17:51 2020 -0300

    clutter/stage: Setup 2D view internally
    
    Move and simplify cogl_matrix_view_2d_in_perspective() to inside
    ClutterStage, since it's the only consumer of this API, and remove
    it from Cogl.
    
    https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439

 clutter/clutter/clutter-stage.c | 49 +++++++++++++++++++++-----
 cogl/cogl/cogl-matrix.c         | 57 ------------------------------
 cogl/cogl/cogl-matrix.h         | 78 -----------------------------------------
 3 files changed, 41 insertions(+), 143 deletions(-)
---
diff --git a/clutter/clutter/clutter-stage.c b/clutter/clutter/clutter-stage.c
index dd47c2f733..ac6abb7336 100644
--- a/clutter/clutter/clutter-stage.c
+++ b/clutter/clutter/clutter-stage.c
@@ -2755,6 +2755,40 @@ calculate_z_translation (float z_near)
        + z_near;
 }
 
+static void
+view_2d_in_perspective (graphene_matrix_t *matrix,
+                        float              fov_y,
+                        float              aspect,
+                        float              z_near,
+                        float              z_2d,
+                        float              width_2d,
+                        float              height_2d)
+{
+  float top = z_near * tan (fov_y * G_PI / 360.0);
+  float left = -top * aspect;
+  float right = top * aspect;
+  float bottom = -top;
+
+  float left_2d_plane = left / z_near * z_2d;
+  float right_2d_plane = right / z_near * z_2d;
+  float bottom_2d_plane = bottom / z_near * z_2d;
+  float top_2d_plane = top / z_near * z_2d;
+
+  float width_2d_start = right_2d_plane - left_2d_plane;
+  float height_2d_start = top_2d_plane - bottom_2d_plane;
+
+  /* Factors to scale from framebuffer geometry to frustum
+   * cross-section geometry. */
+  float width_scale = width_2d_start / width_2d;
+  float height_scale = height_2d_start / height_2d;
+
+  graphene_matrix_init_scale (matrix, width_scale, -height_scale, width_scale);
+  graphene_matrix_translate (matrix,
+                             &GRAPHENE_POINT3D_INIT (left_2d_plane,
+                                                     top_2d_plane,
+                                                     -z_2d));
+}
+
 static void
 clutter_stage_update_view_perspective (ClutterStage *stage)
 {
@@ -2779,14 +2813,13 @@ clutter_stage_update_view_perspective (ClutterStage *stage)
 
   clutter_stage_set_perspective (stage, &perspective);
 
-  cogl_matrix_init_identity (&priv->view);
-  cogl_matrix_view_2d_in_perspective (&priv->view,
-                                      perspective.fovy,
-                                      perspective.aspect,
-                                      perspective.z_near,
-                                      z_2d,
-                                      priv->viewport[2],
-                                      priv->viewport[3]);
+  view_2d_in_perspective (&priv->view,
+                          perspective.fovy,
+                          perspective.aspect,
+                          perspective.z_near,
+                          z_2d,
+                          priv->viewport[2],
+                          priv->viewport[3]);
 
   clutter_actor_invalidate_transform (CLUTTER_ACTOR (stage));
 }
diff --git a/cogl/cogl/cogl-matrix.c b/cogl/cogl/cogl-matrix.c
index a4a1e9636d..a8a96c6941 100644
--- a/cogl/cogl/cogl-matrix.c
+++ b/cogl/cogl/cogl-matrix.c
@@ -246,63 +246,6 @@ cogl_matrix_init_from_euler (graphene_matrix_t      *matrix,
   graphene_matrix_rotate_euler (matrix, euler);
 }
 
-void
-cogl_matrix_view_2d_in_frustum (graphene_matrix_t *matrix,
-                                float              left,
-                                float              right,
-                                float              bottom,
-                                float              top,
-                                float              z_near,
-                                float              z_2d,
-                                float              width_2d,
-                                float              height_2d)
-{
-  float left_2d_plane = left / z_near * z_2d;
-  float right_2d_plane = right / z_near * z_2d;
-  float bottom_2d_plane = bottom / z_near * z_2d;
-  float top_2d_plane = top / z_near * z_2d;
-
-  float width_2d_start = right_2d_plane - left_2d_plane;
-  float height_2d_start = top_2d_plane - bottom_2d_plane;
-
-  /* Factors to scale from framebuffer geometry to frustum
-   * cross-section geometry. */
-  float width_scale = width_2d_start / width_2d;
-  float height_scale = height_2d_start / height_2d;
-
-  cogl_matrix_translate (matrix,
-                         left_2d_plane, top_2d_plane, -z_2d);
-
-  cogl_matrix_scale (matrix, width_scale, -height_scale, width_scale);
-}
-
-/* Assuming a symmetric perspective matrix is being used for your
- * projective transform this convenience function lets you compose a
- * view transform such that geometry on the z=0 plane will map to
- * screen coordinates with a top left origin of (0,0) and with the
- * given width and height.
- */
-void
-cogl_matrix_view_2d_in_perspective (graphene_matrix_t *matrix,
-                                    float              fov_y,
-                                    float              aspect,
-                                    float              z_near,
-                                    float              z_2d,
-                                    float              width_2d,
-                                    float              height_2d)
-{
-  float top = z_near * tan (fov_y * G_PI / 360.0);
-  cogl_matrix_view_2d_in_frustum (matrix,
-                                  -top * aspect,
-                                  top * aspect,
-                                  -top,
-                                  top,
-                                  z_near,
-                                  z_2d,
-                                  width_2d,
-                                  height_2d);
-}
-
 gboolean
 cogl_matrix_equal (const void *v1, const void *v2)
 {
diff --git a/cogl/cogl/cogl-matrix.h b/cogl/cogl/cogl-matrix.h
index c4222a91e2..008e5b4676 100644
--- a/cogl/cogl/cogl-matrix.h
+++ b/cogl/cogl/cogl-matrix.h
@@ -308,84 +308,6 @@ cogl_matrix_orthographic (graphene_matrix_t *matrix,
                           float              near,
                           float              far);
 
-/**
- * cogl_matrix_view_2d_in_frustum:
- * @matrix: A 4x4 transformation matrix
- * @left: coord of left vertical clipping plane
- * @right: coord of right vertical clipping plane
- * @bottom: coord of bottom horizontal clipping plane
- * @top: coord of top horizontal clipping plane
- * @z_near: The distance to the near clip plane. Never pass 0 and always pass
- *   a positive number.
- * @z_2d: The distance to the 2D plane. (Should always be positive and
- *   be between @z_near and the z_far value that was passed to
- *   cogl_matrix_frustum())
- * @width_2d: The width of the 2D coordinate system
- * @height_2d: The height of the 2D coordinate system
- *
- * Multiplies @matrix by a view transform that maps the 2D coordinates
- * (0,0) top left and (@width_2d,@height_2d) bottom right the full viewport
- * size. Geometry at a depth of 0 will now lie on this 2D plane.
- *
- * Note: this doesn't multiply the matrix by any projection matrix,
- * but it assumes you have a perspective projection as defined by
- * passing the corresponding arguments to cogl_matrix_frustum().
-
- * Toolkits such as Clutter that mix 2D and 3D drawing can use this to
- * create a 2D coordinate system within a 3D perspective projected
- * view frustum.
- *
- * Since: 1.8
- * Stability: unstable
- */
-COGL_EXPORT void
-cogl_matrix_view_2d_in_frustum (graphene_matrix_t *matrix,
-                                float              left,
-                                float              right,
-                                float              bottom,
-                                float              top,
-                                float              z_near,
-                                float              z_2d,
-                                float              width_2d,
-                                float              height_2d);
-
-/**
- * cogl_matrix_view_2d_in_perspective:
- * @fov_y: A field of view angle for the Y axis
- * @aspect: The ratio of width to height determining the field of view angle
- *   for the x axis.
- * @z_near: The distance to the near clip plane. Never pass 0 and always pass
- *   a positive number.
- * @z_2d: The distance to the 2D plane. (Should always be positive and
- *   be between @z_near and the z_far value that was passed to
- *   cogl_matrix_frustum())
- * @width_2d: The width of the 2D coordinate system
- * @height_2d: The height of the 2D coordinate system
- *
- * Multiplies @matrix by a view transform that maps the 2D coordinates
- * (0,0) top left and (@width_2d,@height_2d) bottom right the full viewport
- * size. Geometry at a depth of 0 will now lie on this 2D plane.
- *
- * Note: this doesn't multiply the matrix by any projection matrix,
- * but it assumes you have a perspective projection as defined by
- * passing the corresponding arguments to cogl_matrix_perspective().
- *
- * Toolkits such as Clutter that mix 2D and 3D drawing can use this to
- * create a 2D coordinate system within a 3D perspective projected
- * view frustum.
- *
- * Since: 1.8
- * Stability: unstable
- */
-COGL_EXPORT void
-cogl_matrix_view_2d_in_perspective (graphene_matrix_t *matrix,
-                                    float              fov_y,
-                                    float              aspect,
-                                    float              z_near,
-                                    float              z_2d,
-                                    float              width_2d,
-                                    float              height_2d);
-
 /**
  * cogl_matrix_init_from_array:
  * @matrix: A 4x4 transformation matrix


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