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,8 +66,7 @@ _clutter_util_fully_transform_vertices (const graphene_matrix_t *modelview,
|
|||||||
/* XXX: we should find a way to cache this per actor */
|
/* XXX: we should find a way to cache this per actor */
|
||||||
graphene_matrix_multiply (modelview, projection, &modelview_projection);
|
graphene_matrix_multiply (modelview, projection, &modelview_projection);
|
||||||
|
|
||||||
cogl_graphene_matrix_project_points (&modelview_projection,
|
cogl_graphene_matrix_project_points_f3 (&modelview_projection,
|
||||||
3,
|
|
||||||
sizeof (graphene_point3d_t),
|
sizeof (graphene_point3d_t),
|
||||||
vertices_in,
|
vertices_in,
|
||||||
sizeof (ClutterVertex4),
|
sizeof (ClutterVertex4),
|
||||||
@ -84,8 +83,7 @@ _clutter_util_fully_transform_vertices (const graphene_matrix_t *modelview,
|
|||||||
vertices_tmp,
|
vertices_tmp,
|
||||||
n_vertices);
|
n_vertices);
|
||||||
|
|
||||||
cogl_graphene_matrix_project_points (projection,
|
cogl_graphene_matrix_project_points_f3 (projection,
|
||||||
3,
|
|
||||||
sizeof (ClutterVertex4),
|
sizeof (ClutterVertex4),
|
||||||
vertices_tmp,
|
vertices_tmp,
|
||||||
sizeof (ClutterVertex4),
|
sizeof (ClutterVertex4),
|
||||||
|
@ -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
|
static void
|
||||||
transform_points_f3 (const graphene_matrix_t *matrix,
|
transform_points_f3 (const graphene_matrix_t *matrix,
|
||||||
size_t stride_in,
|
size_t stride_in,
|
||||||
@ -145,8 +117,8 @@ transform_points_f3 (const graphene_matrix_t *matrix,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
void
|
||||||
project_points_f3 (const graphene_matrix_t *matrix,
|
cogl_graphene_matrix_project_points_f3 (const graphene_matrix_t *matrix,
|
||||||
size_t stride_in,
|
size_t stride_in,
|
||||||
const void *points_in,
|
const void *points_in,
|
||||||
size_t stride_out,
|
size_t stride_out,
|
||||||
@ -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
|
void
|
||||||
cogl_graphene_matrix_project_point (const graphene_matrix_t *matrix,
|
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);
|
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
|
* The output array can simply point to the input array to do the
|
||||||
* transform in-place.
|
* 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:
|
* Here's an example with differing input/output strides:
|
||||||
* ```c
|
* ```c
|
||||||
* typedef struct {
|
* typedef struct {
|
||||||
@ -113,10 +110,8 @@ cogl_graphene_matrix_transform_points (const graphene_matrix_t *matrix,
|
|||||||
int n_points);
|
int n_points);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cogl_graphene_matrix_project_points:
|
* cogl_graphene_matrix_project_points_f3:
|
||||||
* @matrix: A projection matrix
|
* @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.
|
* @stride_in: The stride in bytes between input points.
|
||||||
* @points_in: A pointer to the first component of the first input point.
|
* @points_in: A pointer to the first component of the first input point.
|
||||||
* @stride_out: The stride in bytes between output points.
|
* @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.
|
* @n_points: The number of points to transform.
|
||||||
*
|
*
|
||||||
* Projects an array of input points and writes the result to another
|
* 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
|
* array of output points. The output points always have 4 components (known
|
||||||
* components each. The output points always have 4 components (known
|
|
||||||
* as homogeneous coordinates). The output array can simply point to
|
* as homogeneous coordinates). The output array can simply point to
|
||||||
* the input array to do the transform in-place.
|
* the input array to do the transform in-place.
|
||||||
*
|
*
|
||||||
* Here's an example with differing input/output strides:
|
* Here's an example with differing input/output strides:
|
||||||
* ```c
|
* ```c
|
||||||
* typedef struct {
|
* typedef struct {
|
||||||
* float x,y;
|
* float x,y, z;
|
||||||
* uint8_t r,g,b,a;
|
* uint8_t r,g,b,a;
|
||||||
* float s,t,p;
|
* float s,t,p;
|
||||||
* } MyInVertex;
|
* } MyInVertex;
|
||||||
@ -147,8 +141,7 @@ cogl_graphene_matrix_transform_points (const graphene_matrix_t *matrix,
|
|||||||
* my_load_vertices (vertices);
|
* my_load_vertices (vertices);
|
||||||
* my_get_matrix (&matrix);
|
* my_get_matrix (&matrix);
|
||||||
*
|
*
|
||||||
* cogl_graphene_matrix_project_points (&matrix,
|
* cogl_graphene_matrix_project_points_f3 (&matrix,
|
||||||
* 2,
|
|
||||||
* sizeof (MyInVertex),
|
* sizeof (MyInVertex),
|
||||||
* &vertices[0].x,
|
* &vertices[0].x,
|
||||||
* sizeof (MyOutVertex),
|
* sizeof (MyOutVertex),
|
||||||
@ -157,8 +150,7 @@ cogl_graphene_matrix_transform_points (const graphene_matrix_t *matrix,
|
|||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
COGL_EXPORT void
|
COGL_EXPORT void
|
||||||
cogl_graphene_matrix_project_points (const graphene_matrix_t *matrix,
|
cogl_graphene_matrix_project_points_f3 (const graphene_matrix_t *matrix,
|
||||||
int n_components,
|
|
||||||
size_t stride_in,
|
size_t stride_in,
|
||||||
const void *points_in,
|
const void *points_in,
|
||||||
size_t stride_out,
|
size_t stride_out,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user