summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>2020-09-11 15:14:26 -0300
committerGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>2020-09-25 11:19:51 -0300
commit9bc9fa8a1dfccb1b87244f377dac0691ab55aedf (patch)
tree3deb37e910c77f30594251ac3bac2bd4b26cbe52
parent3b73f990a6ca6dc14cd72e87842bd50d6af73dcd (diff)
downloadmutter-9bc9fa8a1dfccb1b87244f377dac0691ab55aedf.tar.gz
cogl/matrix: Relocate and update projection and transform APIs
Ideally, we would use Graphene to do that, however as of now Graphene lacks these APIs so we still need these helpers. Since we're preparing to get rid of CoglMatrix, move them to a separate file, and rename them with the 'cogl_graphene' prefix. Since I'm already touching the world with this change, I'm also renaming cogl_matrix_transform_point() to cogl_graphene_matrix_project_point(), as per XXX comment, to make it consistent with the transform/projection semantics in place. https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
-rw-r--r--clutter/clutter/clutter-actor.c16
-rw-r--r--clutter/clutter/clutter-paint-volume.c24
-rw-r--r--clutter/clutter/clutter-stage.c14
-rw-r--r--clutter/clutter/clutter-util.c44
-rw-r--r--cogl/cogl/cogl-graphene.c276
-rw-r--r--cogl/cogl/cogl-graphene.h169
-rw-r--r--cogl/cogl/cogl-journal.c49
-rw-r--r--cogl/cogl/cogl-matrix.c249
-rw-r--r--cogl/cogl/cogl-matrix.h135
-rw-r--r--cogl/cogl/cogl.c5
-rw-r--r--cogl/cogl/cogl.h1
-rw-r--r--cogl/cogl/driver/gl/cogl-clip-stack-gl.c5
-rw-r--r--cogl/cogl/meson.build2
-rw-r--r--src/compositor/clutter-utils.c10
14 files changed, 535 insertions, 464 deletions
diff --git a/clutter/clutter/clutter-actor.c b/clutter/clutter/clutter-actor.c
index f8141e312..0ec9826bb 100644
--- a/clutter/clutter/clutter-actor.c
+++ b/clutter/clutter/clutter-actor.c
@@ -1289,11 +1289,11 @@ _clutter_actor_transform_local_box_to_stage (ClutterActor *self,
float z = 0.f;
float w = 1.f;
- cogl_matrix_transform_point (&transform_to_stage,
- &vertices[v].x,
- &vertices[v].y,
- &z,
- &w);
+ cogl_graphene_matrix_project_point (&transform_to_stage,
+ &vertices[v].x,
+ &vertices[v].y,
+ &z,
+ &w);
}
return TRUE;
@@ -2873,7 +2873,11 @@ clutter_actor_apply_relative_transform_to_point (ClutterActor *self,
}
_clutter_actor_get_relative_transformation_matrix (self, ancestor, &matrix);
- cogl_matrix_transform_point (&matrix, &vertex->x, &vertex->y, &vertex->z, &w);
+ cogl_graphene_matrix_project_point (&matrix,
+ &vertex->x,
+ &vertex->y,
+ &vertex->z,
+ &w);
}
static gboolean
diff --git a/clutter/clutter/clutter-paint-volume.c b/clutter/clutter/clutter-paint-volume.c
index 3facd71cf..807d1c401 100644
--- a/clutter/clutter/clutter-paint-volume.c
+++ b/clutter/clutter/clutter-paint-volume.c
@@ -857,11 +857,11 @@ _clutter_paint_volume_transform (ClutterPaintVolume *pv,
{
gfloat w = 1;
/* Just transform the origin */
- cogl_matrix_transform_point (matrix,
- &pv->vertices[0].x,
- &pv->vertices[0].y,
- &pv->vertices[0].z,
- &w);
+ cogl_graphene_matrix_project_point (matrix,
+ &pv->vertices[0].x,
+ &pv->vertices[0].y,
+ &pv->vertices[0].z,
+ &w);
return;
}
@@ -876,13 +876,13 @@ _clutter_paint_volume_transform (ClutterPaintVolume *pv,
else
transform_count = 8;
- cogl_matrix_transform_points (matrix,
- 3,
- sizeof (graphene_point3d_t),
- pv->vertices,
- sizeof (graphene_point3d_t),
- pv->vertices,
- transform_count);
+ cogl_graphene_matrix_transform_points (matrix,
+ 3,
+ sizeof (graphene_point3d_t),
+ pv->vertices,
+ sizeof (graphene_point3d_t),
+ pv->vertices,
+ transform_count);
pv->is_axis_aligned = FALSE;
}
diff --git a/clutter/clutter/clutter-stage.c b/clutter/clutter/clutter-stage.c
index 70eeda3b8..e30bcb41d 100644
--- a/clutter/clutter/clutter-stage.c
+++ b/clutter/clutter/clutter-stage.c
@@ -725,13 +725,13 @@ _cogl_util_get_eye_planes_for_screen_poly (float *polygon,
#undef CLIP_X
#undef CLIP_Y
- cogl_matrix_project_points (inverse_project,
- 4,
- sizeof (Vector4),
- tmp_poly,
- sizeof (Vector4),
- tmp_poly,
- n_vertices * 2);
+ cogl_graphene_matrix_project_points (inverse_project,
+ 4,
+ sizeof (Vector4),
+ tmp_poly,
+ sizeof (Vector4),
+ tmp_poly,
+ n_vertices * 2);
/* XXX: It's quite ugly that we end up with these casts between
* Vector4 types and CoglVector3s, it might be better if the
diff --git a/clutter/clutter/clutter-util.c b/clutter/clutter/clutter-util.c
index b35b8b0c1..5ead95b3d 100644
--- a/clutter/clutter/clutter-util.c
+++ b/clutter/clutter/clutter-util.c
@@ -75,31 +75,31 @@ _clutter_util_fully_transform_vertices (const CoglMatrix *modelview,
cogl_matrix_multiply (&modelview_projection,
projection,
modelview);
- cogl_matrix_project_points (&modelview_projection,
- 3,
- sizeof (graphene_point3d_t),
- vertices_in,
- sizeof (ClutterVertex4),
- vertices_tmp,
- n_vertices);
+ cogl_graphene_matrix_project_points (&modelview_projection,
+ 3,
+ sizeof (graphene_point3d_t),
+ vertices_in,
+ sizeof (ClutterVertex4),
+ vertices_tmp,
+ n_vertices);
}
else
{
- cogl_matrix_transform_points (modelview,
- 3,
- sizeof (graphene_point3d_t),
- vertices_in,
- sizeof (ClutterVertex4),
- vertices_tmp,
- n_vertices);
-
- cogl_matrix_project_points (projection,
- 3,
- sizeof (ClutterVertex4),
- vertices_tmp,
- sizeof (ClutterVertex4),
- vertices_tmp,
- n_vertices);
+ cogl_graphene_matrix_transform_points (modelview,
+ 3,
+ sizeof (graphene_point3d_t),
+ vertices_in,
+ sizeof (ClutterVertex4),
+ vertices_tmp,
+ n_vertices);
+
+ cogl_graphene_matrix_project_points (projection,
+ 3,
+ sizeof (ClutterVertex4),
+ vertices_tmp,
+ sizeof (ClutterVertex4),
+ vertices_tmp,
+ n_vertices);
}
for (i = 0; i < n_vertices; i++)
diff --git a/cogl/cogl/cogl-graphene.c b/cogl/cogl/cogl-graphene.c
new file mode 100644
index 000000000..d9bd3bd42
--- /dev/null
+++ b/cogl/cogl/cogl-graphene.c
@@ -0,0 +1,276 @@
+/* cogl-graphene.c
+ *
+ * Copyright 2020 Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#include "cogl/cogl-graphene.h"
+
+typedef struct _Point2f
+{
+ float x;
+ float y;
+} Point2f;
+
+typedef struct _Point3f
+{
+ float x;
+ float y;
+ float z;
+} Point3f;
+
+typedef struct _Point4f
+{
+ float x;
+ float y;
+ float z;
+ float w;
+} Point4f;
+
+static void
+init_matrix_rows (const graphene_matrix_t *matrix,
+ unsigned int n_rows,
+ graphene_vec4_t *rows)
+{
+ graphene_matrix_t m;
+ unsigned int i;
+
+ graphene_matrix_transpose (matrix, &m);
+
+ for (i = 0; i < n_rows; i++)
+ graphene_matrix_get_row (&m, i, &rows[i]);
+}
+
+static void
+transform_points_f2 (const graphene_matrix_t *matrix,
+ size_t stride_in,
+ const void *points_in,
+ size_t stride_out,
+ void *points_out,
+ int n_points)
+{
+ graphene_vec4_t rows[3];
+ int i;
+
+ init_matrix_rows (matrix, G_N_ELEMENTS (rows), rows);
+
+ for (i = 0; i < n_points; i++)
+ {
+ Point2f p = *(Point2f *)((uint8_t *)points_in + i * stride_in);
+ Point3f *o = (Point3f *)((uint8_t *)points_out + i * stride_out);
+ graphene_vec4_t point;
+
+ graphene_vec4_init (&point, p.x, p.y, 0.f, 1.f);
+
+ o->x = graphene_vec4_dot (&rows[0], &point);
+ o->y = graphene_vec4_dot (&rows[1], &point);
+ o->z = graphene_vec4_dot (&rows[2], &point);
+ }
+}
+
+static void
+project_points_f2 (const graphene_matrix_t *matrix,
+ size_t stride_in,
+ const void *points_in,
+ size_t stride_out,
+ void *points_out,
+ int n_points)
+{
+ graphene_vec4_t rows[4];
+ int i;
+
+ init_matrix_rows (matrix, G_N_ELEMENTS (rows), rows);
+
+ for (i = 0; i < n_points; i++)
+ {
+ Point2f p = *(Point2f *)((uint8_t *)points_in + i * stride_in);
+ Point4f *o = (Point4f *)((uint8_t *)points_out + i * stride_out);
+ graphene_vec4_t point;
+
+ graphene_vec4_init (&point, p.x, p.y, 0.f, 1.f);
+
+ o->x = graphene_vec4_dot (&rows[0], &point);
+ o->y = graphene_vec4_dot (&rows[1], &point);
+ o->z = graphene_vec4_dot (&rows[2], &point);
+ o->w = graphene_vec4_dot (&rows[3], &point);
+ }
+}
+
+static void
+transform_points_f3 (const graphene_matrix_t *matrix,
+ size_t stride_in,
+ const void *points_in,
+ size_t stride_out,
+ void *points_out,
+ int n_points)
+{
+ graphene_vec4_t rows[3];
+ int i;
+
+ init_matrix_rows (matrix, G_N_ELEMENTS (rows), rows);
+
+ for (i = 0; i < n_points; i++)
+ {
+ Point3f p = *(Point3f *)((uint8_t *)points_in + i * stride_in);
+ Point3f *o = (Point3f *)((uint8_t *)points_out + i * stride_out);
+ graphene_vec4_t point;
+
+ graphene_vec4_init (&point, p.x, p.y, p.z, 1.f);
+
+ o->x = graphene_vec4_dot (&rows[0], &point);
+ o->y = graphene_vec4_dot (&rows[1], &point);
+ o->z = graphene_vec4_dot (&rows[2], &point);
+ }
+}
+
+static void
+project_points_f3 (const graphene_matrix_t *matrix,
+ size_t stride_in,
+ const void *points_in,
+ size_t stride_out,
+ void *points_out,
+ int n_points)
+{
+ graphene_vec4_t rows[4];
+ int i;
+
+ init_matrix_rows (matrix, G_N_ELEMENTS (rows), rows);
+
+ for (i = 0; i < n_points; i++)
+ {
+ Point3f p = *(Point3f *)((uint8_t *)points_in + i * stride_in);
+ Point4f *o = (Point4f *)((uint8_t *)points_out + i * stride_out);
+ graphene_vec4_t point;
+
+ graphene_vec4_init (&point, p.x, p.y, p.z, 1.f);
+
+ o->x = graphene_vec4_dot (&rows[0], &point);
+ o->y = graphene_vec4_dot (&rows[1], &point);
+ o->z = graphene_vec4_dot (&rows[2], &point);
+ o->w = graphene_vec4_dot (&rows[3], &point);
+ }
+}
+
+static void
+project_points_f4 (const graphene_matrix_t *matrix,
+ size_t stride_in,
+ const void *points_in,
+ size_t stride_out,
+ void *points_out,
+ int n_points)
+{
+ graphene_vec4_t rows[4];
+ int i;
+
+ init_matrix_rows (matrix, G_N_ELEMENTS (rows), rows);
+
+ for (i = 0; i < n_points; i++)
+ {
+ Point4f p = *(Point4f *)((uint8_t *)points_in + i * stride_in);
+ Point4f *o = (Point4f *)((uint8_t *)points_out + i * stride_out);
+ graphene_vec4_t point;
+
+ graphene_vec4_init (&point, p.x, p.y, p.z, p.w);
+
+ o->x = graphene_vec4_dot (&rows[0], &point);
+ o->y = graphene_vec4_dot (&rows[1], &point);
+ o->z = graphene_vec4_dot (&rows[2], &point);
+ o->w = graphene_vec4_dot (&rows[3], &point);
+ }
+}
+
+void
+cogl_graphene_matrix_project_point (const graphene_matrix_t *matrix,
+ float *x,
+ float *y,
+ float *z,
+ float *w)
+{
+ graphene_vec4_t p;
+
+ graphene_vec4_init (&p, *x, *y, *z, *w);
+ graphene_matrix_transform_vec4 (matrix, &p, &p);
+
+ *x = graphene_vec4_get_x (&p);
+ *y = graphene_vec4_get_y (&p);
+ *z = graphene_vec4_get_z (&p);
+ *w = graphene_vec4_get_w (&p);
+}
+
+void
+cogl_graphene_matrix_transform_points (const graphene_matrix_t *matrix,
+ int n_components,
+ size_t stride_in,
+ const void *points_in,
+ size_t stride_out,
+ void *points_out,
+ int n_points)
+{
+ /* The results of transforming always have three components... */
+ g_return_if_fail (stride_out >= sizeof (Point3f));
+
+ if (n_components == 2)
+ {
+ transform_points_f2 (matrix,
+ stride_in, points_in,
+ stride_out, points_out,
+ n_points);
+ }
+ else
+ {
+ g_return_if_fail (n_components == 3);
+
+ transform_points_f3 (matrix,
+ stride_in, points_in,
+ stride_out, points_out,
+ n_points);
+ }
+}
+
+void
+cogl_graphene_matrix_project_points (const graphene_matrix_t *matrix,
+ int n_components,
+ size_t stride_in,
+ const void *points_in,
+ size_t stride_out,
+ void *points_out,
+ int n_points)
+{
+ if (n_components == 2)
+ {
+ project_points_f2 (matrix,
+ stride_in, points_in,
+ stride_out, points_out,
+ n_points);
+ }
+ else if (n_components == 3)
+ {
+ project_points_f3 (matrix,
+ stride_in, points_in,
+ stride_out, points_out,
+ n_points);
+ }
+ else
+ {
+ g_return_if_fail (n_components == 4);
+
+ project_points_f4 (matrix,
+ stride_in, points_in,
+ stride_out, points_out,
+ n_points);
+ }
+}
diff --git a/cogl/cogl/cogl-graphene.h b/cogl/cogl/cogl-graphene.h
new file mode 100644
index 000000000..67ffd8547
--- /dev/null
+++ b/cogl/cogl/cogl-graphene.h
@@ -0,0 +1,169 @@
+/* cogl-graphene.h
+ *
+ * Copyright 2020 Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#ifndef COGL_GRAPHENE_H
+#define COGL_GRAPHENE_H
+
+#include <cogl/cogl-defines.h>
+#include <cogl/cogl-macros.h>
+#include <cogl/cogl-types.h>
+
+#include <glib.h>
+
+#include <graphene.h>
+
+G_BEGIN_DECLS
+
+
+/**
+ * cogl_graphene_matrix_project_point:
+ * @matrix: A 4x4 transformation matrix
+ * @x: (inout): The X component of your points position
+ * @y: (inout): The Y component of your points position
+ * @z: (inout): The Z component of your points position
+ * @w: (inout): The W component of your points position
+ *
+ * Transforms a point whose position is given and returned as four float
+ * components.
+ */
+COGL_EXPORT void
+cogl_graphene_matrix_project_point (const graphene_matrix_t *matrix,
+ float *x,
+ float *y,
+ float *z,
+ float *w);
+
+/**
+ * cogl_graphene_matrix_transform_points:
+ * @matrix: A transformation matrix
+ * @n_components: The number of position components for each input point.
+ * (either 2 or 3)
+ * @stride_in: The stride in bytes between input points.
+ * @points_in: A pointer to the first component of the first input point.
+ * @stride_out: The stride in bytes between output points.
+ * @points_out: A pointer to the first component of the first output point.
+ * @n_points: The number of points to transform.
+ *
+ * Transforms an array of input points and writes the result to
+ * another array of output points. The input points can either have 2
+ * or 3 components each. The output points always have 3 components.
+ * The output array can simply point to the input array to do the
+ * transform in-place.
+ *
+ * If you need to transform 4 component points see
+ * cogl_graphene_matrix_project_points().
+ *
+ * Here's an example with differing input/output strides:
+ * |[
+ * typedef struct {
+ * float x,y;
+ * uint8_t r,g,b,a;
+ * float s,t,p;
+ * } MyInVertex;
+ * typedef struct {
+ * uint8_t r,g,b,a;
+ * float x,y,z;
+ * } MyOutVertex;
+ * MyInVertex vertices[N_VERTICES];
+ * MyOutVertex results[N_VERTICES];
+ * graphene_matrix_t matrix;
+ *
+ * my_load_vertices (vertices);
+ * my_get_matrix (&matrix);
+ *
+ * cogl_graphene_matrix_transform_points (&matrix,
+ * 2,
+ * sizeof (MyInVertex),
+ * &vertices[0].x,
+ * sizeof (MyOutVertex),
+ * &results[0].x,
+ * N_VERTICES);
+ * ]|
+ *
+ * Stability: unstable
+ */
+COGL_EXPORT void
+cogl_graphene_matrix_transform_points (const graphene_matrix_t *matrix,
+ int n_components,
+ size_t stride_in,
+ const void *points_in,
+ size_t stride_out,
+ void *points_out,
+ int n_points);
+
+/**
+ * cogl_graphene_matrix_project_points:
+ * @matrix: A projection matrix
+ * @n_components: The number of position components for each input point.
+ * (either 2, 3 or 4)
+ * @stride_in: The stride in bytes between input points.
+ * @points_in: A pointer to the first component of the first input point.
+ * @stride_out: The stride in bytes between output points.
+ * @points_out: A pointer to the first component of the first output point.
+ * @n_points: The number of points to transform.
+ *
+ * Projects an array of input points and writes the result to another
+ * array of output points. The input points can either have 2, 3 or 4
+ * components each. The output points always have 4 components (known
+ * as homogeneous coordinates). The output array can simply point to
+ * the input array to do the transform in-place.
+ *
+ * Here's an example with differing input/output strides:
+ * |[
+ * typedef struct {
+ * float x,y;
+ * uint8_t r,g,b,a;
+ * float s,t,p;
+ * } MyInVertex;
+ * typedef struct {
+ * uint8_t r,g,b,a;
+ * float x,y,z;
+ * } MyOutVertex;
+ * MyInVertex vertices[N_VERTICES];
+ * MyOutVertex results[N_VERTICES];
+ * graphene_matrix_t matrix;
+ *
+ * my_load_vertices (vertices);
+ * my_get_matrix (&matrix);
+ *
+ * cogl_graphene_matrix_project_points (&matrix,
+ * 2,
+ * sizeof (MyInVertex),
+ * &vertices[0].x,
+ * sizeof (MyOutVertex),
+ * &results[0].x,
+ * N_VERTICES);
+ * ]|
+ *
+ * Stability: unstable
+ */
+COGL_EXPORT void
+cogl_graphene_matrix_project_points (const graphene_matrix_t *matrix,
+ int n_components,
+ size_t stride_in,
+ const void *points_in,
+ size_t stride_out,
+ void *points_out,
+ int n_points);
+
+
+G_END_DECLS
+
+#endif /* COGL_GRAPHENE_H */
diff --git a/cogl/cogl/cogl-journal.c b/cogl/cogl/cogl-journal.c
index 418fd9895..33e1ea034 100644
--- a/cogl/cogl/cogl-journal.c
+++ b/cogl/cogl/cogl-journal.c
@@ -32,6 +32,7 @@
#include "cogl-debug.h"
#include "cogl-context-private.h"
+#include "cogl-graphene.h"
#include "cogl-journal-private.h"
#include "cogl-texture-private.h"
#include "cogl-pipeline-private.h"
@@ -1212,14 +1213,14 @@ upload_vertices (CoglJournal *journal,
if (entry->modelview_entry != last_modelview_entry)
cogl_matrix_entry_get (entry->modelview_entry, &modelview);
- cogl_matrix_transform_points (&modelview,
- 2, /* n_components */
- sizeof (float) * 2, /* stride_in */
- v, /* points_in */
- /* strideout */
- vb_stride * sizeof (float),
- vout, /* points_out */
- 4 /* n_points */);
+ cogl_graphene_matrix_transform_points (&modelview,
+ 2, /* n_components */
+ sizeof (float) * 2, /* stride_in */
+ v, /* points_in */
+ /* strideout */
+ vb_stride * sizeof (float),
+ vout, /* points_out */
+ 4 /* n_points */);
}
for (i = 0; i < entry->n_layers; i++)
@@ -1672,27 +1673,27 @@ entry_to_screen_polygon (CoglFramebuffer *framebuffer,
*/
cogl_matrix_entry_get (entry->modelview_entry, &modelview);
- cogl_matrix_transform_points (&modelview,
- 2, /* n_components */
- sizeof (float) * 4, /* stride_in */
- poly, /* points_in */
- /* strideout */
- sizeof (float) * 4,
- poly, /* points_out */
- 4 /* n_points */);
+ cogl_graphene_matrix_transform_points (&modelview,
+ 2, /* n_components */
+ sizeof (float) * 4, /* stride_in */
+ poly, /* points_in */
+ /* strideout */
+ sizeof (float) * 4,
+ poly, /* points_out */
+ 4 /* n_points */);
projection_stack =
_cogl_framebuffer_get_projection_stack (framebuffer);
cogl_matrix_stack_get (projection_stack, &projection);
- cogl_matrix_project_points (&projection,
- 3, /* n_components */
- sizeof (float) * 4, /* stride_in */
- poly, /* points_in */
- /* strideout */
- sizeof (float) * 4,
- poly, /* points_out */
- 4 /* n_points */);
+ cogl_graphene_matrix_transform_points (&projection,
+ 3, /* n_components */
+ sizeof (float) * 4, /* stride_in */
+ poly, /* points_in */
+ /* strideout */
+ sizeof (float) * 4,
+ poly, /* points_out */
+ 4 /* n_points */);
/* Scale from OpenGL normalized device coordinates (ranging from -1 to 1)
* to Cogl window/framebuffer coordinates (ranging from 0 to buffer-size) with
diff --git a/cogl/cogl/cogl-matrix.c b/cogl/cogl/cogl-matrix.c
index 987493f92..81ec4970d 100644
--- a/cogl/cogl/cogl-matrix.c
+++ b/cogl/cogl/cogl-matrix.c
@@ -387,255 +387,6 @@ cogl_matrix_get_value (const CoglMatrix *matrix,
return graphene_matrix_get_value (matrix, column, row);
}
-void
-cogl_matrix_transform_point (const CoglMatrix *matrix,
- float *x,
- float *y,
- float *z,
- float *w)
-{
- graphene_vec4_t p;
-
- graphene_vec4_init (&p, *x, *y, *z, *w);
- graphene_matrix_transform_vec4 (matrix, &p, &p);
-
- *x = graphene_vec4_get_x (&p);
- *y = graphene_vec4_get_y (&p);
- *z = graphene_vec4_get_z (&p);
- *w = graphene_vec4_get_w (&p);
-}
-
-typedef struct _Point2f
-{
- float x;
- float y;
-} Point2f;
-
-typedef struct _Point3f
-{
- float x;
- float y;
- float z;
-} Point3f;
-
-typedef struct _Point4f
-{
- float x;
- float y;
- float z;
- float w;
-} Point4f;
-
-static void
-init_matrix_rows (const CoglMatrix *matrix,
- unsigned int n_rows,
- graphene_vec4_t *rows)
-{
- graphene_matrix_t m;
- unsigned int i;
-
- graphene_matrix_transpose (matrix, &m);
-
- for (i = 0; i < n_rows; i++)
- graphene_matrix_get_row (&m, i, &rows[i]);
-}
-
-static void
-_cogl_matrix_transform_points_f2 (const CoglMatrix *matrix,
- size_t stride_in,
- const void *points_in,
- size_t stride_out,
- void *points_out,
- int n_points)
-{
- graphene_vec4_t rows[3];
- int i;
-
- init_matrix_rows (matrix, G_N_ELEMENTS (rows), rows);
-
- for (i = 0; i < n_points; i++)
- {
- Point2f p = *(Point2f *)((uint8_t *)points_in + i * stride_in);
- Point3f *o = (Point3f *)((uint8_t *)points_out + i * stride_out);
- graphene_vec4_t point;
-
- graphene_vec4_init (&point, p.x, p.y, 0.f, 1.f);
-
- o->x = graphene_vec4_dot (&rows[0], &point);
- o->y = graphene_vec4_dot (&rows[1], &point);
- o->z = graphene_vec4_dot (&rows[2], &point);
- }
-}
-
-static void
-_cogl_matrix_project_points_f2 (const CoglMatrix *matrix,
- size_t stride_in,
- const void *points_in,
- size_t stride_out,
- void *points_out,
- int n_points)
-{
- graphene_vec4_t rows[4];
- int i;
-
- init_matrix_rows (matrix, G_N_ELEMENTS (rows), rows);
-
- for (i = 0; i < n_points; i++)
- {
- Point2f p = *(Point2f *)((uint8_t *)points_in + i * stride_in);
- Point4f *o = (Point4f *)((uint8_t *)points_out + i * stride_out);
- graphene_vec4_t point;
-
- graphene_vec4_init (&point, p.x, p.y, 0.f, 1.f);
-
- o->x = graphene_vec4_dot (&rows[0], &point);
- o->y = graphene_vec4_dot (&rows[1], &point);
- o->z = graphene_vec4_dot (&rows[2], &point);
- o->w = graphene_vec4_dot (&rows[3], &point);
- }
-}
-
-static void
-_cogl_matrix_transform_points_f3 (const CoglMatrix *matrix,
- size_t stride_in,
- const void *points_in,
- size_t stride_out,
- void *points_out,
- int n_points)
-{
- graphene_vec4_t rows[3];
- int i;
-
- init_matrix_rows (matrix, G_N_ELEMENTS (rows), rows);
-
- for (i = 0; i < n_points; i++)
- {
- Point3f p = *(Point3f *)((uint8_t *)points_in + i * stride_in);
- Point3f *o = (Point3f *)((uint8_t *)points_out + i * stride_out);
- graphene_vec4_t point;
-
- graphene_vec4_init (&point, p.x, p.y, p.z, 1.f);
-
- o->x = graphene_vec4_dot (&rows[0], &point);
- o->y = graphene_vec4_dot (&rows[1], &point);
- o->z = graphene_vec4_dot (&rows[2], &point);
- }
-}
-
-static void
-_cogl_matrix_project_points_f3 (const CoglMatrix *matrix,
- size_t stride_in,
- const void *points_in,
- size_t stride_out,
- void *points_out,
- int n_points)
-{
- graphene_vec4_t rows[4];
- int i;
-
- init_matrix_rows (matrix, G_N_ELEMENTS (rows), rows);
-
- for (i = 0; i < n_points; i++)
- {
- Point3f p = *(Point3f *)((uint8_t *)points_in + i * stride_in);
- Point4f *o = (Point4f *)((uint8_t *)points_out + i * stride_out);
- graphene_vec4_t point;
-
- graphene_vec4_init (&point, p.x, p.y, p.z, 1.f);
-
- o->x = graphene_vec4_dot (&rows[0], &point);
- o->y = graphene_vec4_dot (&rows[1], &point);
- o->z = graphene_vec4_dot (&rows[2], &point);
- o->w = graphene_vec4_dot (&rows[3], &point);
- }
-}
-
-static void
-_cogl_matrix_project_points_f4 (const CoglMatrix *matrix,
- size_t stride_in,
- const void *points_in,
- size_t stride_out,
- void *points_out,
- int n_points)
-{
- graphene_vec4_t rows[4];
- int i;
-
- init_matrix_rows (matrix, G_N_ELEMENTS (rows), rows);
-
- for (i = 0; i < n_points; i++)
- {
- Point4f p = *(Point4f *)((uint8_t *)points_in + i * stride_in);
- Point4f *o = (Point4f *)((uint8_t *)points_out + i * stride_out);
- graphene_vec4_t point;
-
- graphene_vec4_init (&point, p.x, p.y, p.z, p.w);
-
- o->x = graphene_vec4_dot (&rows[0], &point);
- o->y = graphene_vec4_dot (&rows[1], &point);
- o->z = graphene_vec4_dot (&rows[2], &point);
- o->w = graphene_vec4_dot (&rows[3], &point);
- }
-}
-
-void
-cogl_matrix_transform_points (const CoglMatrix *matrix,
- int n_components,
- size_t stride_in,
- const void *points_in,
- size_t stride_out,
- void *points_out,
- int n_points)
-{
- /* The results of transforming always have three components... */
- g_return_if_fail (stride_out >= sizeof (Point3f));
-
- if (n_components == 2)
- _cogl_matrix_transform_points_f2 (matrix,
- stride_in, points_in,
- stride_out, points_out,
- n_points);
- else
- {
- g_return_if_fail (n_components == 3);
-
- _cogl_matrix_transform_points_f3 (matrix,
- stride_in, points_in,
- stride_out, points_out,
- n_points);
- }
-}
-
-void
-cogl_matrix_project_points (const CoglMatrix *matrix,
- int n_components,
- size_t stride_in,
- const void *points_in,
- size_t stride_out,
- void *points_out,
- int n_points)
-{
- if (n_components == 2)
- _cogl_matrix_project_points_f2 (matrix,
- stride_in, points_in,
- stride_out, points_out,
- n_points);
- else if (n_components == 3)
- _cogl_matrix_project_points_f3 (matrix,
- stride_in, points_in,
- stride_out, points_out,
- n_points);
- else
- {
- g_return_if_fail (n_components == 4);
-
- _cogl_matrix_project_points_f4 (matrix,
- stride_in, points_in,
- stride_out, points_out,
- n_points);
- }
-}
-
gboolean
cogl_matrix_is_identity (const CoglMatrix *matrix)
{
diff --git a/cogl/cogl/cogl-matrix.h b/cogl/cogl/cogl-matrix.h
index 072ed61d4..601c29c69 100644
--- a/cogl/cogl/cogl-matrix.h
+++ b/cogl/cogl/cogl-matrix.h
@@ -503,141 +503,6 @@ COGL_EXPORT gboolean
cogl_matrix_get_inverse (const CoglMatrix *matrix,
CoglMatrix *inverse);
-/* FIXME: to be consistent with cogl_matrix_{transform,project}_points
- * this could be renamed to cogl_matrix_project_point for Cogl 2.0...
- */
-
-/**
- * cogl_matrix_transform_point:
- * @matrix: A 4x4 transformation matrix
- * @x: (inout): The X component of your points position
- * @y: (inout): The Y component of your points position
- * @z: (inout): The Z component of your points position
- * @w: (inout): The W component of your points position
- *
- * Transforms a point whose position is given and returned as four float
- * components.
- */
-COGL_EXPORT void
-cogl_matrix_transform_point (const CoglMatrix *matrix,
- float *x,
- float *y,
- float *z,
- float *w);
-
-/**
- * cogl_matrix_transform_points:
- * @matrix: A transformation matrix
- * @n_components: The number of position components for each input point.
- * (either 2 or 3)
- * @stride_in: The stride in bytes between input points.
- * @points_in: A pointer to the first component of the first input point.
- * @stride_out: The stride in bytes between output points.
- * @points_out: A pointer to the first component of the first output point.
- * @n_points: The number of points to transform.
- *
- * Transforms an array of input points and writes the result to
- * another array of output points. The input points can either have 2
- * or 3 components each. The output points always have 3 components.
- * The output array can simply point to the input array to do the
- * transform in-place.
- *
- * If you need to transform 4 component points see
- * cogl_matrix_project_points().
- *
- * Here's an example with differing input/output strides:
- * |[
- * typedef struct {
- * float x,y;
- * uint8_t r,g,b,a;
- * float s,t,p;
- * } MyInVertex;
- * typedef struct {
- * uint8_t r,g,b,a;
- * float x,y,z;
- * } MyOutVertex;
- * MyInVertex vertices[N_VERTICES];
- * MyOutVertex results[N_VERTICES];
- * CoglMatrix matrix;
- *
- * my_load_vertices (vertices);
- * my_get_matrix (&matrix);
- *
- * cogl_matrix_transform_points (&matrix,
- * 2,
- * sizeof (MyInVertex),
- * &vertices[0].x,
- * sizeof (MyOutVertex),
- * &results[0].x,
- * N_VERTICES);
- * ]|
- *
- * Stability: unstable
- */
-COGL_EXPORT void
-cogl_matrix_transform_points (const CoglMatrix *matrix,
- int n_components,
- size_t stride_in,
- const void *points_in,
- size_t stride_out,
- void *points_out,
- int n_points);
-
-/**
- * cogl_matrix_project_points:
- * @matrix: A projection matrix
- * @n_components: The number of position components for each input point.
- * (either 2, 3 or 4)
- * @stride_in: The stride in bytes between input points.
- * @points_in: A pointer to the first component of the first input point.
- * @stride_out: The stride in bytes between output points.
- * @points_out: A pointer to the first component of the first output point.
- * @n_points: The number of points to transform.
- *
- * Projects an array of input points and writes the result to another
- * array of output points. The input points can either have 2, 3 or 4
- * components each. The output points always have 4 components (known
- * as homogeneous coordinates). The output array can simply point to
- * the input array to do the transform in-place.
- *
- * Here's an example with differing input/output strides:
- * |[
- * typedef struct {
- * float x,y;
- * uint8_t r,g,b,a;
- * float s,t,p;
- * } MyInVertex;
- * typedef struct {
- * uint8_t r,g,b,a;
- * float x,y,z;
- * } MyOutVertex;
- * MyInVertex vertices[N_VERTICES];
- * MyOutVertex results[N_VERTICES];
- * CoglMatrix matrix;
- *
- * my_load_vertices (vertices);
- * my_get_matrix (&matrix);
- *
- * cogl_matrix_project_points (&matrix,
- * 2,
- * sizeof (MyInVertex),
- * &vertices[0].x,
- * sizeof (MyOutVertex),
- * &results[0].x,
- * N_VERTICES);
- * ]|
- *
- * Stability: unstable
- */
-COGL_EXPORT void
-cogl_matrix_project_points (const CoglMatrix *matrix,
- int n_components,
- size_t stride_in,
- const void *points_in,
- size_t stride_out,
- void *points_out,
- int n_points);
-
/**
* cogl_matrix_is_identity:
* @matrix: A #CoglMatrix
diff --git a/cogl/cogl/cogl.c b/cogl/cogl/cogl.c
index 320c0186d..e35b84c24 100644
--- a/cogl/cogl/cogl.c
+++ b/cogl/cogl/cogl.c
@@ -36,6 +36,7 @@
#include "cogl-i18n-private.h"
#include "cogl-debug.h"
+#include "cogl-graphene.h"
#include "cogl-util.h"
#include "cogl-context-private.h"
#include "cogl-pipeline-private.h"
@@ -184,10 +185,10 @@ _cogl_transform_point (const CoglMatrix *matrix_mv,
float w = 1;
/* Apply the modelview matrix transform */
- cogl_matrix_transform_point (matrix_mv, x, y, &z, &w);
+ cogl_graphene_matrix_project_point (matrix_mv, x, y, &z, &w);
/* Apply the projection matrix transform */
- cogl_matrix_transform_point (matrix_p, x, y, &z, &w);
+ cogl_graphene_matrix_project_point (matrix_p, x, y, &z, &w);
/* Perform perspective division */
*x /= w;
diff --git a/cogl/cogl/cogl.h b/cogl/cogl/cogl.h
index 07b496208..142293dac 100644
--- a/cogl/cogl/cogl.h
+++ b/cogl/cogl/cogl.h
@@ -123,6 +123,7 @@
#include <cogl/cogl-glib-source.h>
#include <cogl/cogl-trace.h>
#include <cogl/cogl-scanout.h>
+#include <cogl/cogl-graphene.h>
/* XXX: This will definitely go away once all the Clutter winsys
* code has been migrated down into Cogl! */
#include <cogl/deprecated/cogl-clutter.h>
diff --git a/cogl/cogl/driver/gl/cogl-clip-stack-gl.c b/cogl/cogl/driver/gl/cogl-clip-stack-gl.c
index 24a714f6c..d5007cf3d 100644
--- a/cogl/cogl/driver/gl/cogl-clip-stack-gl.c
+++ b/cogl/cogl/driver/gl/cogl-clip-stack-gl.c
@@ -35,6 +35,7 @@
#include "cogl-config.h"
#include "cogl-context-private.h"
+#include "cogl-graphene.h"
#include "cogl-primitives-private.h"
#include "cogl-primitive-private.h"
#include "driver/gl/cogl-util-gl-private.h"
@@ -204,8 +205,8 @@ add_stencil_clip_region (CoglFramebuffer *framebuffer,
z2 = 0.f;
w2 = 1.f;
- cogl_matrix_transform_point (&matrix, &x1, &y1, &z1, &w1);
- cogl_matrix_transform_point (&matrix, &x2, &y2, &z2, &w2);
+ cogl_graphene_matrix_project_point (&matrix, &x1, &y1, &z1, &w1);
+ cogl_graphene_matrix_project_point (&matrix, &x2, &y2, &z2, &w2);
v[0].x = x1;
v[0].y = y1;
diff --git a/cogl/cogl/meson.build b/cogl/cogl/meson.build
index 2947b46c9..360675d4c 100644
--- a/cogl/cogl/meson.build
+++ b/cogl/cogl/meson.build
@@ -123,6 +123,7 @@ cogl_nonintrospected_headers = [
'cogl-gtype-private.h',
'cogl-glib-source.h',
'cogl-scanout.h',
+ 'cogl-graphene.h',
]
cogl_nodist_headers = [
@@ -354,6 +355,7 @@ cogl_sources = [
'deprecated/cogl-clutter.c',
'cogl-glib-source.c',
'cogl-mutter.h',
+ 'cogl-graphene.c',
]
if have_x11
diff --git a/src/compositor/clutter-utils.c b/src/compositor/clutter-utils.c
index f05a698f5..6482ceb1a 100644
--- a/src/compositor/clutter-utils.c
+++ b/src/compositor/clutter-utils.c
@@ -170,11 +170,11 @@ meta_actor_painting_untransformed (CoglFramebuffer *fb,
for (i = 0; i < 4; i++)
{
float w = 1;
- cogl_matrix_transform_point (&modelview_projection,
- &vertices[i].x,
- &vertices[i].y,
- &vertices[i].z,
- &w);
+ cogl_graphene_matrix_project_point (&modelview_projection,
+ &vertices[i].x,
+ &vertices[i].y,
+ &vertices[i].z,
+ &w);
vertices[i].x = MTX_GL_SCALE_X (vertices[i].x, w,
viewport[2], viewport[0]);
vertices[i].y = MTX_GL_SCALE_Y (vertices[i].y, w,