Replace ClutterVertex by graphene_point3d_t

Pretty direct and straightforward port. This requires a
GNOME Shell counterpart. In addition to that, include a
progress function.

https://gitlab.gnome.org/GNOME/mutter/merge_requests/458
This commit is contained in:
Georges Basile Stavracas Neto
2019-02-20 10:18:48 -03:00
parent ba0f17f5b1
commit a5d0cfe8fb
30 changed files with 252 additions and 431 deletions

View File

@ -51,8 +51,8 @@ void
_clutter_util_fully_transform_vertices (const CoglMatrix *modelview,
const CoglMatrix *projection,
const float *viewport,
const ClutterVertex *vertices_in,
ClutterVertex *vertices_out,
const graphene_point3d_t *vertices_in,
graphene_point3d_t *vertices_out,
int n_vertices)
{
CoglMatrix modelview_projection;
@ -69,7 +69,7 @@ _clutter_util_fully_transform_vertices (const CoglMatrix *modelview,
modelview);
cogl_matrix_project_points (&modelview_projection,
3,
sizeof (ClutterVertex),
sizeof (graphene_point3d_t),
vertices_in,
sizeof (ClutterVertex4),
vertices_tmp,
@ -79,7 +79,7 @@ _clutter_util_fully_transform_vertices (const CoglMatrix *modelview,
{
cogl_matrix_transform_points (modelview,
3,
sizeof (ClutterVertex),
sizeof (graphene_point3d_t),
vertices_in,
sizeof (ClutterVertex4),
vertices_tmp,
@ -97,7 +97,7 @@ _clutter_util_fully_transform_vertices (const CoglMatrix *modelview,
for (i = 0; i < n_vertices; i++)
{
ClutterVertex4 vertex_tmp = vertices_tmp[i];
ClutterVertex *vertex_out = &vertices_out[i];
graphene_point3d_t *vertex_out = &vertices_out[i];
/* Finally translate from OpenGL coords to window coords */
vertex_out->x = MTX_GL_SCALE_X (vertex_tmp.x, vertex_tmp.w,
viewport[2], viewport[0]);
@ -299,48 +299,12 @@ _clutter_util_matrix_skew_yz (ClutterMatrix *matrix,
matrix->zw += matrix->yw * factor;
}
static float
_clutter_util_vertex_length (const ClutterVertex *vertex)
{
return sqrtf (vertex->x * vertex->x + vertex->y * vertex->y + vertex->z * vertex->z);
}
static void
_clutter_util_vertex_normalize (ClutterVertex *vertex)
{
float factor = _clutter_util_vertex_length (vertex);
if (factor == 0.f)
return;
vertex->x /= factor;
vertex->y /= factor;
vertex->z /= factor;
}
static float
_clutter_util_vertex_dot (const ClutterVertex *v1,
const ClutterVertex *v2)
{
return v1->x * v2->x + v1->y * v2->y + v1->z * v2->z;
}
static void
_clutter_util_vertex_cross (const ClutterVertex *v1,
const ClutterVertex *v2,
ClutterVertex *res)
{
res->x = v1->y * v2->z - v2->y * v1->z;
res->y = v1->z * v2->x - v2->z * v1->x;
res->z = v1->x * v2->y - v2->x * v1->y;
}
static void
_clutter_util_vertex_combine (const ClutterVertex *a,
const ClutterVertex *b,
double ascl,
double bscl,
ClutterVertex *res)
_clutter_util_vertex_combine (const graphene_point3d_t *a,
const graphene_point3d_t *b,
double ascl,
double bscl,
graphene_point3d_t *res)
{
res->x = (ascl * a->x) + (bscl * b->x);
res->y = (ascl * a->y) + (bscl * b->y);
@ -388,16 +352,16 @@ _clutter_util_vertex4_interpolate (const ClutterVertex4 *a,
*/
gboolean
_clutter_util_matrix_decompose (const ClutterMatrix *src,
ClutterVertex *scale_p,
graphene_point3d_t *scale_p,
float shear_p[3],
ClutterVertex *rotate_p,
ClutterVertex *translate_p,
graphene_point3d_t *rotate_p,
graphene_point3d_t *translate_p,
ClutterVertex4 *perspective_p)
{
CoglMatrix matrix = *src;
CoglMatrix perspective;
ClutterVertex4 vertex_tmp;
ClutterVertex row[3], pdum;
graphene_point3d_t row[3], pdum;
int i, j;
#define XY_SHEAR 0
@ -485,34 +449,34 @@ _clutter_util_matrix_decompose (const ClutterMatrix *src,
}
/* compute scale.x and normalize the first row */
scale_p->x = _clutter_util_vertex_length (&row[0]);
_clutter_util_vertex_normalize (&row[0]);
scale_p->x = graphene_point3d_length (&row[0]);
graphene_point3d_normalize (&row[0], &row[0]);
/* compute XY shear and make the second row orthogonal to the first */
shear_p[XY_SHEAR] = _clutter_util_vertex_dot (&row[0], &row[1]);
shear_p[XY_SHEAR] = graphene_point3d_dot (&row[0], &row[1]);
_clutter_util_vertex_combine (&row[1], &row[0],
1.0, -shear_p[XY_SHEAR],
&row[1]);
/* compute the Y scale and normalize the second row */
scale_p->y = _clutter_util_vertex_length (&row[1]);
_clutter_util_vertex_normalize (&row[1]);
scale_p->y = graphene_point3d_length (&row[1]);
graphene_point3d_normalize (&row[1], &row[1]);
shear_p[XY_SHEAR] /= scale_p->y;
/* compute XZ and YZ shears, orthogonalize the third row */
shear_p[XZ_SHEAR] = _clutter_util_vertex_dot (&row[0], &row[2]);
shear_p[XZ_SHEAR] = graphene_point3d_dot (&row[0], &row[2]);
_clutter_util_vertex_combine (&row[2], &row[0],
1.0, -shear_p[XZ_SHEAR],
&row[2]);
shear_p[YZ_SHEAR] = _clutter_util_vertex_dot (&row[1], &row[2]);
shear_p[YZ_SHEAR] = graphene_point3d_dot (&row[1], &row[2]);
_clutter_util_vertex_combine (&row[2], &row[1],
1.0, -shear_p[YZ_SHEAR],
&row[2]);
/* get the Z scale and normalize the third row*/
scale_p->z = _clutter_util_vertex_length (&row[2]);
_clutter_util_vertex_normalize (&row[2]);
scale_p->z = graphene_point3d_length (&row[2]);
graphene_point3d_normalize (&row[2], &row[2]);
shear_p[XZ_SHEAR] /= scale_p->z;
shear_p[YZ_SHEAR] /= scale_p->z;
@ -520,8 +484,8 @@ _clutter_util_matrix_decompose (const ClutterMatrix *src,
* check for a coordinate system flip; if the determinant
* is -1, then negate the matrix and scaling factors
*/
_clutter_util_vertex_cross (&row[1], &row[2], &pdum);
if (_clutter_util_vertex_dot (&row[0], &pdum) < 0.f)
graphene_point3d_cross (&row[1], &row[2], &pdum);
if (graphene_point3d_dot (&row[0], &pdum) < 0.f)
{
scale_p->x *= -1.f;