[mutter/gbsneto/graphene-matrix: 8/39] cogl/matrix: Rename and change cogl_matrix_get_array()
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter/gbsneto/graphene-matrix: 8/39] cogl/matrix: Rename and change cogl_matrix_get_array()
- Date: Tue, 22 Sep 2020 12:55:00 +0000 (UTC)
commit c56be01e12b60a13559c5989f61bef452bdd918d
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Fri Sep 11 09:36:04 2020 -0300
cogl/matrix: Rename and change cogl_matrix_get_array()
There's no guarantee that graphene matrices are composed of
16 floating points, and we can't just assume that. However,
cogl_matrix_get_array() would still do a simple cast and
pretend the matrix itself is an array.
Make the float array an out argument, and rename it to match
graphene's API.
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
clutter/clutter/clutter-shader-effect.c | 7 +++--
cogl/cogl/cogl-matrix.c | 7 +++--
cogl/cogl/cogl-matrix.h | 12 ++++----
cogl/cogl/cogl-pipeline-state.h | 2 +-
cogl/cogl/driver/gl/cogl-pipeline-progend-glsl.c | 35 ++++++++++++++++--------
cogl/tests/conform/test-euler.c | 6 ++--
cogl/tests/conform/test-pipeline-uniforms.c | 4 +--
cogl/tests/conform/test-snippets.c | 4 ++-
8 files changed, 48 insertions(+), 29 deletions(-)
---
diff --git a/clutter/clutter/clutter-shader-effect.c b/clutter/clutter/clutter-shader-effect.c
index be15d32b10..92526b47ee 100644
--- a/clutter/clutter/clutter-shader-effect.c
+++ b/clutter/clutter/clutter-shader-effect.c
@@ -824,9 +824,12 @@ add_uniform:
* Finally, a uniform named "map" and containing a matrix can be set using:
*
* |[<!-- language="C" -->
+ * float v[16];
+ *
+ * cogl_matrix_to_float (&matrix, v);
* clutter_shader_effect_set_uniform (effect, "map",
- * CLUTTER_TYPE_SHADER_MATRIX, 1,
- * cogl_matrix_get_array (&matrix));
+ * CLUTTER_TYPE_SHADER_MATRIX,
+ * 1, v);
* ]|
*
* Since: 1.4
diff --git a/cogl/cogl/cogl-matrix.c b/cogl/cogl/cogl-matrix.c
index 55a575dc73..c2086d4615 100644
--- a/cogl/cogl/cogl-matrix.c
+++ b/cogl/cogl/cogl-matrix.c
@@ -447,10 +447,11 @@ cogl_matrix_free (CoglMatrix *matrix)
g_slice_free (CoglMatrix, matrix);
}
-const float *
-cogl_matrix_get_array (const CoglMatrix *matrix)
+void
+cogl_matrix_to_float (const CoglMatrix *matrix,
+ float *out_array)
{
- return (float *)matrix;
+ graphene_matrix_to_float (&matrix->m, out_array);
}
float
diff --git a/cogl/cogl/cogl-matrix.h b/cogl/cogl/cogl-matrix.h
index 57a8a70a29..347584dfe5 100644
--- a/cogl/cogl/cogl-matrix.h
+++ b/cogl/cogl/cogl-matrix.h
@@ -440,15 +440,17 @@ cogl_matrix_init_from_matrix (CoglMatrix *matrix,
const CoglMatrix *source);
/**
- * cogl_matrix_get_array:
+ * cogl_matrix_to_float:
* @matrix: A 4x4 transformation matrix
+ * @out_array: (array fixed-size=16) (out caller-allocates): return location
+ * for an array of floating point values. The array must be capable of
+ * holding at least 16 values.
*
* Casts @matrix to a float array which can be directly passed to OpenGL.
- *
- * Return value: a pointer to the float array
*/
-COGL_EXPORT const float *
-cogl_matrix_get_array (const CoglMatrix *matrix);
+COGL_EXPORT void
+cogl_matrix_to_float (const CoglMatrix *matrix,
+ float *out_array);
/**
* cogl_matrix_get_value:
diff --git a/cogl/cogl/cogl-pipeline-state.h b/cogl/cogl/cogl-pipeline-state.h
index ceec55fc98..1745ae0499 100644
--- a/cogl/cogl/cogl-pipeline-state.h
+++ b/cogl/cogl/cogl-pipeline-state.h
@@ -716,7 +716,7 @@ cogl_pipeline_set_uniform_int (CoglPipeline *pipeline,
* If @transpose is %FALSE then the matrix is expected to be in
* column-major order or if it is %TRUE then the matrix is in
* row-major order. You can pass a #CoglMatrix by calling by passing
- * the result of cogl_matrix_get_array() in @value and setting
+ * the result of cogl_matrix_to_float() in @value and setting
* @transpose to %FALSE.
*
* Since: 2.0
diff --git a/cogl/cogl/driver/gl/cogl-pipeline-progend-glsl.c
b/cogl/cogl/driver/gl/cogl-pipeline-progend-glsl.c
index b9b6048fd9..e00db212f4 100644
--- a/cogl/cogl/driver/gl/cogl-pipeline-progend-glsl.c
+++ b/cogl/cogl/driver/gl/cogl-pipeline-progend-glsl.c
@@ -432,10 +432,10 @@ update_constants_cb (CoglPipeline *pipeline,
(state->update_all || unit_state->dirty_texture_matrix))
{
const CoglMatrix *matrix;
- const float *array;
+ float array[16];
matrix = _cogl_pipeline_get_layer_matrix (pipeline, layer_index);
- array = cogl_matrix_get_array (matrix);
+ cogl_matrix_to_float (matrix, array);
GE (ctx, glUniformMatrix4fv (unit_state->texture_matrix_uniform,
1, FALSE, array));
unit_state->dirty_texture_matrix = FALSE;
@@ -1033,6 +1033,8 @@ _cogl_pipeline_progend_glsl_pre_paint (CoglPipeline *pipeline,
if (modelview_changed || projection_changed)
{
+ float v[16];
+
if (program_state->mvp_uniform != -1)
need_modelview = need_projection = TRUE;
else
@@ -1060,16 +1062,22 @@ _cogl_pipeline_progend_glsl_pre_paint (CoglPipeline *pipeline,
}
if (projection_changed && program_state->projection_uniform != -1)
- GE (ctx, glUniformMatrix4fv (program_state->projection_uniform,
- 1, /* count */
- FALSE, /* transpose */
- cogl_matrix_get_array (&projection)));
+ {
+ cogl_matrix_to_float (&projection, v);
+ GE (ctx, glUniformMatrix4fv (program_state->projection_uniform,
+ 1, /* count */
+ FALSE, /* transpose */
+ v));
+ }
if (modelview_changed && program_state->modelview_uniform != -1)
- GE (ctx, glUniformMatrix4fv (program_state->modelview_uniform,
- 1, /* count */
- FALSE, /* transpose */
- cogl_matrix_get_array (&modelview)));
+ {
+ cogl_matrix_to_float (&modelview,v);
+ GE (ctx, glUniformMatrix4fv (program_state->modelview_uniform,
+ 1, /* count */
+ FALSE, /* transpose */
+ v));
+ }
if (program_state->mvp_uniform != -1)
{
@@ -1078,11 +1086,12 @@ _cogl_pipeline_progend_glsl_pre_paint (CoglPipeline *pipeline,
avoiding the matrix multiplication */
if (cogl_matrix_entry_is_identity (modelview_entry))
{
+ cogl_matrix_to_float (&projection, v);
GE (ctx,
glUniformMatrix4fv (program_state->mvp_uniform,
1, /* count */
FALSE, /* transpose */
- cogl_matrix_get_array (&projection)));
+ v));
}
else
{
@@ -1091,11 +1100,13 @@ _cogl_pipeline_progend_glsl_pre_paint (CoglPipeline *pipeline,
cogl_matrix_multiply (&combined,
&projection,
&modelview);
+ cogl_matrix_to_float (&combined, v);
+
GE (ctx,
glUniformMatrix4fv (program_state->mvp_uniform,
1, /* count */
FALSE, /* transpose */
- cogl_matrix_get_array (&combined)));
+ v));
}
}
}
diff --git a/cogl/tests/conform/test-euler.c b/cogl/tests/conform/test-euler.c
index a99576abee..4690d412bb 100644
--- a/cogl/tests/conform/test-euler.c
+++ b/cogl/tests/conform/test-euler.c
@@ -22,10 +22,12 @@
#define COMPARE_MATRICES(a, b) \
do { \
- const float *af = cogl_matrix_get_array (a);\
- const float *bf = cogl_matrix_get_array (b);\
+ float af[16], bf[16]; \
int i; \
\
+ cogl_matrix_to_float (a, af); \
+ cogl_matrix_to_float (b, bf); \
+ \
for (i = 0; i < 16; i++) \
COMPARE_ELEMENT (af, bf, i); \
} while (0)
diff --git a/cogl/tests/conform/test-pipeline-uniforms.c b/cogl/tests/conform/test-pipeline-uniforms.c
index a02f5d4464..fe08cd0536 100644
--- a/cogl/tests/conform/test-pipeline-uniforms.c
+++ b/cogl/tests/conform/test-pipeline-uniforms.c
@@ -242,9 +242,7 @@ paint_matrix_pipeline (CoglPipeline *pipeline)
cogl_matrix_transpose (matrices + 3);
for (i = 0; i < 4; i++)
- memcpy (matrix_floats + i * 16,
- cogl_matrix_get_array (matrices + i),
- sizeof (float) * 16);
+ cogl_matrix_to_float (&matrices[i], &matrix_floats[i * 16]);
/* Set the first three matrices as transposed */
uniform_location =
diff --git a/cogl/tests/conform/test-snippets.c b/cogl/tests/conform/test-snippets.c
index 9b19b221bf..ea0582dc82 100644
--- a/cogl/tests/conform/test-snippets.c
+++ b/cogl/tests/conform/test-snippets.c
@@ -492,6 +492,7 @@ test_vertex_transform_hook (TestState *state)
CoglSnippet *snippet;
CoglMatrix identity_matrix;
CoglMatrix matrix;
+ float v[16];
int location;
/* Test the vertex transform hook */
@@ -513,12 +514,13 @@ test_vertex_transform_hook (TestState *state)
/* Copy the current projection matrix to a uniform */
cogl_framebuffer_get_projection_matrix (test_fb, &matrix);
location = cogl_pipeline_get_uniform_location (pipeline, "pmat");
+ cogl_matrix_to_float (&matrix, v);
cogl_pipeline_set_uniform_matrix (pipeline,
location,
4, /* dimensions */
1, /* count */
FALSE, /* don't transpose */
- cogl_matrix_get_array (&matrix));
+ v);
/* Replace the real projection matrix with the identity. This should
mess up the drawing unless the snippet replacement is working */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]