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
This commit is contained in:
Georges Basile Stavracas Neto 2020-09-11 15:14:26 -03:00
parent 050053a114
commit cedb5318da
14 changed files with 534 additions and 463 deletions

View File

@ -1289,7 +1289,7 @@ _clutter_actor_transform_local_box_to_stage (ClutterActor *self,
float z = 0.f;
float w = 1.f;
cogl_matrix_transform_point (&transform_to_stage,
cogl_graphene_matrix_project_point (&transform_to_stage,
&vertices[v].x,
&vertices[v].y,
&z,
@ -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

View File

@ -857,7 +857,7 @@ _clutter_paint_volume_transform (ClutterPaintVolume *pv,
{
gfloat w = 1;
/* Just transform the origin */
cogl_matrix_transform_point (matrix,
cogl_graphene_matrix_project_point (matrix,
&pv->vertices[0].x,
&pv->vertices[0].y,
&pv->vertices[0].z,
@ -876,7 +876,7 @@ _clutter_paint_volume_transform (ClutterPaintVolume *pv,
else
transform_count = 8;
cogl_matrix_transform_points (matrix,
cogl_graphene_matrix_transform_points (matrix,
3,
sizeof (graphene_point3d_t),
pv->vertices,

View File

@ -725,7 +725,7 @@ _cogl_util_get_eye_planes_for_screen_poly (float *polygon,
#undef CLIP_X
#undef CLIP_Y
cogl_matrix_project_points (inverse_project,
cogl_graphene_matrix_project_points (inverse_project,
4,
sizeof (Vector4),
tmp_poly,

View File

@ -77,7 +77,7 @@ _clutter_util_fully_transform_vertices (const CoglMatrix *modelview,
cogl_matrix_multiply (&modelview_projection,
projection,
modelview);
cogl_matrix_project_points (&modelview_projection,
cogl_graphene_matrix_project_points (&modelview_projection,
3,
sizeof (graphene_point3d_t),
vertices_in,
@ -87,7 +87,7 @@ _clutter_util_fully_transform_vertices (const CoglMatrix *modelview,
}
else
{
cogl_matrix_transform_points (modelview,
cogl_graphene_matrix_transform_points (modelview,
3,
sizeof (graphene_point3d_t),
vertices_in,
@ -95,7 +95,7 @@ _clutter_util_fully_transform_vertices (const CoglMatrix *modelview,
vertices_tmp,
n_vertices);
cogl_matrix_project_points (projection,
cogl_graphene_matrix_project_points (projection,
3,
sizeof (ClutterVertex4),
vertices_tmp,

276
cogl/cogl/cogl-graphene.c Normal file
View File

@ -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);
}
}

169
cogl/cogl/cogl-graphene.h Normal file
View File

@ -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 */

View File

@ -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,7 +1213,7 @@ upload_vertices (CoglJournal *journal,
if (entry->modelview_entry != last_modelview_entry)
cogl_matrix_entry_get (entry->modelview_entry, &modelview);
cogl_matrix_transform_points (&modelview,
cogl_graphene_matrix_transform_points (&modelview,
2, /* n_components */
sizeof (float) * 2, /* stride_in */
v, /* points_in */
@ -1672,7 +1673,7 @@ entry_to_screen_polygon (CoglFramebuffer *framebuffer,
*/
cogl_matrix_entry_get (entry->modelview_entry, &modelview);
cogl_matrix_transform_points (&modelview,
cogl_graphene_matrix_transform_points (&modelview,
2, /* n_components */
sizeof (float) * 4, /* stride_in */
poly, /* points_in */
@ -1685,7 +1686,7 @@ entry_to_screen_polygon (CoglFramebuffer *framebuffer,
_cogl_framebuffer_get_projection_stack (framebuffer);
cogl_matrix_stack_get (projection_stack, &projection);
cogl_matrix_project_points (&projection,
cogl_graphene_matrix_transform_points (&projection,
3, /* n_components */
sizeof (float) * 4, /* stride_in */
poly, /* points_in */

View File

@ -396,255 +396,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)
{

View File

@ -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

View File

@ -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;

View File

@ -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>

View File

@ -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;

View File

@ -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

View File

@ -170,7 +170,7 @@ meta_actor_painting_untransformed (CoglFramebuffer *fb,
for (i = 0; i < 4; i++)
{
float w = 1;
cogl_matrix_transform_point (&modelview_projection,
cogl_graphene_matrix_project_point (&modelview_projection,
&vertices[i].x,
&vertices[i].y,
&vertices[i].z,