cogl/graphene: Simplify matrix_project_points helper
As it is always used for 3 components, drop n=2 and n=4 support. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4180>
This commit is contained in:
parent
42ba494f07
commit
1fce76a0fb
@ -66,13 +66,12 @@ _clutter_util_fully_transform_vertices (const graphene_matrix_t *modelview,
|
||||
/* XXX: we should find a way to cache this per actor */
|
||||
graphene_matrix_multiply (modelview, projection, &modelview_projection);
|
||||
|
||||
cogl_graphene_matrix_project_points (&modelview_projection,
|
||||
3,
|
||||
sizeof (graphene_point3d_t),
|
||||
vertices_in,
|
||||
sizeof (ClutterVertex4),
|
||||
vertices_tmp,
|
||||
n_vertices);
|
||||
cogl_graphene_matrix_project_points_f3 (&modelview_projection,
|
||||
sizeof (graphene_point3d_t),
|
||||
vertices_in,
|
||||
sizeof (ClutterVertex4),
|
||||
vertices_tmp,
|
||||
n_vertices);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -84,13 +83,12 @@ _clutter_util_fully_transform_vertices (const graphene_matrix_t *modelview,
|
||||
vertices_tmp,
|
||||
n_vertices);
|
||||
|
||||
cogl_graphene_matrix_project_points (projection,
|
||||
3,
|
||||
sizeof (ClutterVertex4),
|
||||
vertices_tmp,
|
||||
sizeof (ClutterVertex4),
|
||||
vertices_tmp,
|
||||
n_vertices);
|
||||
cogl_graphene_matrix_project_points_f3 (projection,
|
||||
sizeof (ClutterVertex4),
|
||||
vertices_tmp,
|
||||
sizeof (ClutterVertex4),
|
||||
vertices_tmp,
|
||||
n_vertices);
|
||||
}
|
||||
|
||||
for (i = 0; i < n_vertices; i++)
|
||||
|
@ -90,34 +90,6 @@ transform_points_f2 (const graphene_matrix_t *matrix,
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
@ -145,13 +117,13 @@ transform_points_f3 (const graphene_matrix_t *matrix,
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
void
|
||||
cogl_graphene_matrix_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;
|
||||
@ -173,33 +145,6 @@ project_points_f3 (const graphene_matrix_t *matrix,
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
@ -248,37 +193,3 @@ cogl_graphene_matrix_transform_points (const graphene_matrix_t *matrix,
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -73,9 +73,6 @@ cogl_graphene_matrix_project_point (const graphene_matrix_t *matrix,
|
||||
* 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:
|
||||
* ```c
|
||||
* typedef struct {
|
||||
@ -113,10 +110,8 @@ cogl_graphene_matrix_transform_points (const graphene_matrix_t *matrix,
|
||||
int n_points);
|
||||
|
||||
/**
|
||||
* cogl_graphene_matrix_project_points:
|
||||
* cogl_graphene_matrix_project_points_f3:
|
||||
* @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.
|
||||
@ -124,15 +119,14 @@ cogl_graphene_matrix_transform_points (const graphene_matrix_t *matrix,
|
||||
* @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
|
||||
* array of output points. 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:
|
||||
* ```c
|
||||
* typedef struct {
|
||||
* float x,y;
|
||||
* float x,y, z;
|
||||
* uint8_t r,g,b,a;
|
||||
* float s,t,p;
|
||||
* } MyInVertex;
|
||||
@ -147,22 +141,20 @@ cogl_graphene_matrix_transform_points (const 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);
|
||||
* cogl_graphene_matrix_project_points_f3 (&matrix,
|
||||
* sizeof (MyInVertex),
|
||||
* &vertices[0].x,
|
||||
* sizeof (MyOutVertex),
|
||||
* &results[0].x,
|
||||
* N_VERTICES);
|
||||
* ```
|
||||
*/
|
||||
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);
|
||||
cogl_graphene_matrix_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);
|
||||
|
||||
G_END_DECLS
|
||||
|
Loading…
x
Reference in New Issue
Block a user