summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>2020-09-11 09:36:04 -0300
committerGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>2020-09-25 11:19:51 -0300
commit7f837be845a15e652c0bc3950f64a14188c3f4da (patch)
tree0de283e4c0e779150dbceb1c1556aeac82492ce6
parent941d05d9a3a0bc1f05b2ae4c17e244f9b4c1b7a9 (diff)
downloadmutter-7f837be845a15e652c0bc3950f64a14188c3f4da.tar.gz
cogl/matrix: Rename and change cogl_matrix_get_array()
Rename cogl_matrix_get_array() to cogl_matrix_to_float(), and make it copy the floats to an out argument instead of returning a pointer to the casted CoglMatrix struct. The naming change is specifically made to match graphene's, and ease the transition. https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
-rw-r--r--clutter/clutter/clutter-shader-effect.c7
-rw-r--r--cogl/cogl/cogl-matrix.c7
-rw-r--r--cogl/cogl/cogl-matrix.h12
-rw-r--r--cogl/cogl/cogl-pipeline-state.h2
-rw-r--r--cogl/cogl/driver/gl/cogl-pipeline-progend-glsl.c35
-rw-r--r--cogl/tests/conform/test-pipeline-uniforms.c4
-rw-r--r--cogl/tests/conform/test-snippets.c4
7 files changed, 44 insertions, 27 deletions
diff --git a/clutter/clutter/clutter-shader-effect.c b/clutter/clutter/clutter-shader-effect.c
index be15d32b1..92526b47e 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 f635f70bc..da611a3e8 100644
--- a/cogl/cogl/cogl-matrix.c
+++ b/cogl/cogl/cogl-matrix.c
@@ -577,10 +577,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;
+ memcpy (matrix, out_array, 16 * sizeof (float));
}
float
diff --git a/cogl/cogl/cogl-matrix.h b/cogl/cogl/cogl-matrix.h
index 120d9a736..b7d396b61 100644
--- a/cogl/cogl/cogl-matrix.h
+++ b/cogl/cogl/cogl-matrix.h
@@ -480,15 +480,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 ceec55fc9..1745ae049 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 b9b6048fd..e00db212f 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-pipeline-uniforms.c b/cogl/tests/conform/test-pipeline-uniforms.c
index a02f5d446..fe08cd053 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 9b19b221b..ea0582dc8 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 */