diff options
author | Georges Basile Stavracas Neto <georges.stavracas@gmail.com> | 2020-10-11 13:30:25 -0300 |
---|---|---|
committer | Georges Basile Stavracas Neto <georges.stavracas@gmail.com> | 2020-10-16 13:37:44 -0300 |
commit | 1f99395d2077bb5dfd5ae8c83bf4cbfa328ac794 (patch) | |
tree | eacb9a2972f5edde5fcf03ab9ea676df7f904d6f /cogl | |
parent | 78c648f947a952b6035371267f77a39ae4fc6511 (diff) | |
download | mutter-1f99395d2077bb5dfd5ae8c83bf4cbfa328ac794.tar.gz |
clutter: Use graphene_matrix_inverse()
Instead of our own implementation that upscales, then downscales back,
use graphene_matrix_inverse() directly. This is possible after switching
to a z-near value that doesn't have problems with float precision.
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1489
Diffstat (limited to 'cogl')
-rw-r--r-- | cogl/cogl/cogl-graphene.c | 35 | ||||
-rw-r--r-- | cogl/cogl/cogl-graphene.h | 16 | ||||
-rw-r--r-- | cogl/cogl/cogl-matrix-stack.c | 4 |
3 files changed, 2 insertions, 53 deletions
diff --git a/cogl/cogl/cogl-graphene.c b/cogl/cogl/cogl-graphene.c index 90e1f5b86..d9bd3bd42 100644 --- a/cogl/cogl/cogl-graphene.c +++ b/cogl/cogl/cogl-graphene.c @@ -274,38 +274,3 @@ cogl_graphene_matrix_project_points (const graphene_matrix_t *matrix, n_points); } } - -gboolean -cogl_graphene_matrix_get_inverse (const graphene_matrix_t *matrix, - graphene_matrix_t *inverse) -{ - graphene_matrix_t scaled; - graphene_matrix_t m; - gboolean invertible; - float pivot = G_MAXFLOAT; - float v[16]; - float scale; - - graphene_matrix_init_from_matrix (&m, matrix); - graphene_matrix_to_float (&m, v); - - pivot = MIN (pivot, v[0]); - pivot = MIN (pivot, v[5]); - pivot = MIN (pivot, v[10]); - pivot = MIN (pivot, v[15]); - scale = 1.f / pivot; - - graphene_matrix_init_scale (&scaled, scale, scale, scale); - - /* Float precision is a limiting factor */ - graphene_matrix_multiply (&m, &scaled, &m); - - invertible = graphene_matrix_inverse (&m, inverse); - - if (invertible) - graphene_matrix_multiply (&scaled, inverse, inverse); - else - graphene_matrix_init_identity (inverse); - - return invertible; -} diff --git a/cogl/cogl/cogl-graphene.h b/cogl/cogl/cogl-graphene.h index 4a561f6d8..420629710 100644 --- a/cogl/cogl/cogl-graphene.h +++ b/cogl/cogl/cogl-graphene.h @@ -163,22 +163,6 @@ cogl_graphene_matrix_project_points (const graphene_matrix_t *matrix, void *points_out, int n_points); -/** - * cogl_graphene_matrix_get_inverse: - * @matrix: A 4x4 transformation matrix - * @inverse: (out): The destination for a 4x4 inverse transformation matrix - * - * Gets the inverse transform of a given matrix and uses it to initialize - * a new #graphene_matrix_t. - * - * Return value: %TRUE if the inverse was successfully calculated or %FALSE - * for degenerate transformations that can't be inverted (in this case the - * @inverse matrix will simply be initialized with the identity matrix) - */ -COGL_EXPORT gboolean -cogl_graphene_matrix_get_inverse (const graphene_matrix_t *matrix, - graphene_matrix_t *inverse); - G_END_DECLS #endif /* COGL_GRAPHENE_H */ diff --git a/cogl/cogl/cogl-matrix-stack.c b/cogl/cogl/cogl-matrix-stack.c index 3f6883068..4e132baf5 100644 --- a/cogl/cogl/cogl-matrix-stack.c +++ b/cogl/cogl/cogl-matrix-stack.c @@ -358,9 +358,9 @@ cogl_matrix_stack_get_inverse (CoglMatrixStack *stack, graphene_matrix_t *internal = cogl_matrix_stack_get (stack, &matrix); if (internal) - return cogl_graphene_matrix_get_inverse (internal, inverse); + return graphene_matrix_inverse (internal, inverse); else - return cogl_graphene_matrix_get_inverse (&matrix, inverse); + return graphene_matrix_inverse (&matrix, inverse); } /* In addition to writing the stack matrix into the give @matrix |