[mutter/gbsneto/graphene-matrix: 1/57] cogl/matrix: Multiply using graphene matrices
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter/gbsneto/graphene-matrix: 1/57] cogl/matrix: Multiply using graphene matrices
- Date: Fri, 25 Sep 2020 11:51:08 +0000 (UTC)
commit d2a41d555a538da2ae8866828f718c33c1140947
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Thu Sep 10 10:34:15 2020 -0300
cogl/matrix: Multiply using graphene matrices
At this point, we are still only changing CoglMatrix APIs internally, and
it should still produce the same output as before. To achieve this, exploit
the fact that graphene matrices are row-major with row vectors.
This makes graphene matrices effectively transposed compared to CoglMatrix,
and we have to to multiply as B x A (the reverse order) instead of A x B,
and that results in the same matrix that Cogl would generate. This is
mathematically sound, since (A x B)^t = B^t x A^t.
By doing this, no consumer of this API needs to be changed for now.
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
cogl/cogl/cogl-matrix.c | 32 +++++++++++---------------------
1 file changed, 11 insertions(+), 21 deletions(-)
---
diff --git a/cogl/cogl/cogl-matrix.c b/cogl/cogl/cogl-matrix.c
index 4f65b16cf9..d191bed9e9 100644
--- a/cogl/cogl/cogl-matrix.c
+++ b/cogl/cogl/cogl-matrix.c
@@ -326,32 +326,22 @@ matrix_multiply_array_with_flags (CoglMatrix *result,
matrix_multiply4x4 ((float *)result, (float *)result, array);
}
-/* Joins both flags and marks the type and inverse as dirty. Calls
- * matrix_multiply3x4() if both matrices are 3D, or matrix_multiply4x4()
- * otherwise.
- */
-static void
-_cogl_matrix_multiply (CoglMatrix *result,
- const CoglMatrix *a,
- const CoglMatrix *b)
-{
- result->flags = (a->flags |
- b->flags |
- MAT_DIRTY_TYPE |
- MAT_DIRTY_INVERSE);
-
- if (TEST_MAT_FLAGS(result, MAT_FLAGS_3D))
- matrix_multiply3x4 ((float *)result, (float *)a, (float *)b);
- else
- matrix_multiply4x4 ((float *)result, (float *)a, (float *)b);
-}
-
void
cogl_matrix_multiply (CoglMatrix *result,
const CoglMatrix *a,
const CoglMatrix *b)
{
- _cogl_matrix_multiply (result, a, b);
+ graphene_matrix_t res;
+ graphene_matrix_t ma;
+ graphene_matrix_t mb;
+
+ cogl_matrix_to_graphene_matrix (a, &ma);
+ cogl_matrix_to_graphene_matrix (b, &mb);
+ graphene_matrix_multiply (&mb, &ma, &res);
+ graphene_matrix_to_cogl_matrix (&res, result);
+
+ result->flags = a->flags | b->flags | MAT_DIRTY_TYPE | MAT_DIRTY_INVERSE;
+
_COGL_MATRIX_DEBUG_PRINT (result);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]