[mutter/gbsneto/graphene-frustrum: 4/19] clutter: Use graphene_matrix_inverse()
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter/gbsneto/graphene-frustrum: 4/19] clutter: Use graphene_matrix_inverse()
- Date: Tue, 13 Oct 2020 11:33:26 +0000 (UTC)
commit 335610bb1a3ccb05b021f9d264fc1e51d3411659
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Sun Oct 11 13:30:25 2020 -0300
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
clutter/clutter/clutter-actor.c | 5 ++---
clutter/clutter/clutter-stage.c | 4 ++--
cogl/cogl/cogl-graphene.c | 35 -----------------------------------
cogl/cogl/cogl-graphene.h | 16 ----------------
cogl/cogl/cogl-matrix-stack.c | 4 ++--
5 files changed, 6 insertions(+), 58 deletions(-)
---
diff --git a/clutter/clutter/clutter-actor.c b/clutter/clutter/clutter-actor.c
index 2e19e24f72..9034545231 100644
--- a/clutter/clutter/clutter-actor.c
+++ b/clutter/clutter/clutter-actor.c
@@ -3165,9 +3165,8 @@ ensure_valid_actor_transform (ClutterActor *actor)
graphene_matrix_init_identity (&priv->transform);
CLUTTER_ACTOR_GET_CLASS (actor)->apply_transform (actor, &priv->transform);
- priv->has_inverse_transform =
- cogl_graphene_matrix_get_inverse (&priv->transform,
- &priv->inverse_transform);
+ priv->has_inverse_transform = graphene_matrix_inverse (&priv->transform,
+ &priv->inverse_transform);
priv->transform_valid = TRUE;
}
diff --git a/clutter/clutter/clutter-stage.c b/clutter/clutter/clutter-stage.c
index 2f362f29c5..ac6f500a31 100644
--- a/clutter/clutter/clutter-stage.c
+++ b/clutter/clutter/clutter-stage.c
@@ -2068,8 +2068,8 @@ clutter_stage_set_perspective (ClutterStage *stage,
priv->perspective.aspect,
priv->perspective.z_near,
priv->perspective.z_far);
- cogl_graphene_matrix_get_inverse (&priv->projection,
- &priv->inverse_projection);
+ graphene_matrix_inverse (&priv->projection,
+ &priv->inverse_projection);
_clutter_stage_dirty_projection (stage);
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
diff --git a/cogl/cogl/cogl-graphene.c b/cogl/cogl/cogl-graphene.c
index 90e1f5b86b..d9bd3bd42c 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 4a561f6d84..4206297108 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 3f68830681..4e132baf5c 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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]