[mutter/gbsneto/graphene2: 19/45] cogl/matrix: Change semantincs of cogl_matrix_get_array
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter/gbsneto/graphene2: 19/45] cogl/matrix: Change semantincs of cogl_matrix_get_array
- Date: Sat, 7 Sep 2019 11:18:50 +0000 (UTC)
commit 54f9bebeb8a0cf20b076d9d019bf57768247f597
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Fri Feb 22 15:06:34 2019 -0300
cogl/matrix: Change semantincs of cogl_matrix_get_array
CoglMatrix.get_array() returns the column-major CoglMatrix itself,
since the first fields of the matrix is effectively an array of
floats, and we can just pretend it is. Of course, it basically
ignores any C-specific type checking.
WIP
cogl/cogl/cogl-matrix.c | 11 +++++---
cogl/cogl/cogl-matrix.h | 8 +++---
cogl/cogl/driver/gl/cogl-clip-stack-gl.c | 10 +++++--
cogl/cogl/driver/gl/cogl-pipeline-progend-glsl.c | 34 +++++++++++++++---------
cogl/tests/conform/test-pipeline-uniforms.c | 4 +--
cogl/tests/conform/test-snippets.c | 4 ++-
6 files changed, 45 insertions(+), 26 deletions(-)
---
diff --git a/cogl/cogl/cogl-matrix.c b/cogl/cogl/cogl-matrix.c
index 99b2eb056..d658c2560 100644
--- a/cogl/cogl/cogl-matrix.c
+++ b/cogl/cogl/cogl-matrix.c
@@ -1996,10 +1996,11 @@ cogl_matrix_free (CoglMatrix *matrix)
g_slice_free (CoglMatrix, matrix);
}
-const float *
-cogl_matrix_get_array (const CoglMatrix *matrix)
+void
+cogl_matrix_get_array (const CoglMatrix *matrix,
+ float *array)
{
- return (float *)matrix;
+ memcpy (array, matrix, sizeof (float) * 16);
}
void
@@ -2291,13 +2292,15 @@ void
cogl_matrix_transpose (CoglMatrix *matrix)
{
float new_values[16];
+ float values[16];
/* We don't need to do anything if the matrix is the identity matrix */
if (!(matrix->flags & MAT_DIRTY_TYPE) &&
matrix->type == COGL_MATRIX_TYPE_IDENTITY)
return;
- _cogl_matrix_util_transposef (new_values, cogl_matrix_get_array (matrix));
+ cogl_matrix_get_array (matrix, values);
+ _cogl_matrix_util_transposef (new_values, values);
cogl_matrix_init_from_array (matrix, new_values);
}
diff --git a/cogl/cogl/cogl-matrix.h b/cogl/cogl/cogl-matrix.h
index 1eb897443..bf6e97c53 100644
--- a/cogl/cogl/cogl-matrix.h
+++ b/cogl/cogl/cogl-matrix.h
@@ -508,13 +508,13 @@ cogl_matrix_init_from_array (CoglMatrix *matrix,
/**
* cogl_matrix_get_array:
* @matrix: A 4x4 transformation matrix
+ * @array: the array to copy the contents of @matrix to.
*
* Casts @matrix to a float array which can be directly passed to OpenGL.
- *
- * Return value: a pointer to the float array
*/
-const float *
-cogl_matrix_get_array (const CoglMatrix *matrix);
+void
+cogl_matrix_get_array (const CoglMatrix *matrix,
+ float *array);
/**
* cogl_matrix_init_from_quaternion:
diff --git a/cogl/cogl/driver/gl/cogl-clip-stack-gl.c b/cogl/cogl/driver/gl/cogl-clip-stack-gl.c
index 9a3a2cee2..1954808ed 100644
--- a/cogl/cogl/driver/gl/cogl-clip-stack-gl.c
+++ b/cogl/cogl/driver/gl/cogl-clip-stack-gl.c
@@ -84,9 +84,15 @@ flush_matrix_to_gl_builtin (CoglContext *ctx,
}
if (is_identity)
- GE (ctx, glLoadIdentity ());
+ {
+ GE (ctx, glLoadIdentity ());
+ }
else
- GE (ctx, glLoadMatrixf (cogl_matrix_get_array (matrix)));
+ {
+ float array[16];
+ cogl_matrix_get_array (matrix, array);
+ GE (ctx, glLoadMatrixf (array));
+ }
#endif
}
diff --git a/cogl/cogl/driver/gl/cogl-pipeline-progend-glsl.c
b/cogl/cogl/driver/gl/cogl-pipeline-progend-glsl.c
index 1f9baa9be..819825232 100644
--- a/cogl/cogl/driver/gl/cogl-pipeline-progend-glsl.c
+++ b/cogl/cogl/driver/gl/cogl-pipeline-progend-glsl.c
@@ -440,10 +440,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_get_array (matrix, array);
GE (ctx, glUniformMatrix4fv (unit_state->texture_matrix_uniform,
1, FALSE, array));
unit_state->dirty_texture_matrix = FALSE;
@@ -965,6 +965,8 @@ _cogl_pipeline_progend_glsl_pre_paint (CoglPipeline *pipeline,
if (modelview_changed || projection_changed)
{
+ float array[16];
+
if (program_state->mvp_uniform != -1)
need_modelview = need_projection = TRUE;
else
@@ -992,16 +994,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_get_array (&projection, array);
+ GE (ctx, glUniformMatrix4fv (program_state->projection_uniform,
+ 1, /* count */
+ FALSE, /* transpose */
+ array));
+ }
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_get_array (&modelview, array);
+ GE (ctx, glUniformMatrix4fv (program_state->modelview_uniform,
+ 1, /* count */
+ FALSE, /* transpose */
+ array));
+ }
if (program_state->mvp_uniform != -1)
{
@@ -1010,11 +1018,12 @@ _cogl_pipeline_progend_glsl_pre_paint (CoglPipeline *pipeline,
avoiding the matrix multiplication */
if (cogl_matrix_entry_is_identity (modelview_entry))
{
+ cogl_matrix_get_array (&projection, array);
GE (ctx,
glUniformMatrix4fv (program_state->mvp_uniform,
1, /* count */
FALSE, /* transpose */
- cogl_matrix_get_array (&projection)));
+ array));
}
else
{
@@ -1023,11 +1032,12 @@ _cogl_pipeline_progend_glsl_pre_paint (CoglPipeline *pipeline,
cogl_matrix_multiply (&combined,
&projection,
&modelview);
+ cogl_matrix_get_array (&combined, array);
GE (ctx,
glUniformMatrix4fv (program_state->mvp_uniform,
1, /* count */
FALSE, /* transpose */
- cogl_matrix_get_array (&combined)));
+ array));
}
}
}
diff --git a/cogl/tests/conform/test-pipeline-uniforms.c b/cogl/tests/conform/test-pipeline-uniforms.c
index ab447b1e5..e04bc8240 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_get_array (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..944fe953d 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 array[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_get_array (&matrix, array);
cogl_pipeline_set_uniform_matrix (pipeline,
location,
4, /* dimensions */
1, /* count */
FALSE, /* don't transpose */
- cogl_matrix_get_array (&matrix));
+ array);
/* 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]