On 16 June 2010 10:41, Richard Hughes <hughsi...@gmail.com> wrote:
> ...This would contain the size

Two new patches attached. Careful review please.

Richard.
From b0b3e8c365e44a2b78aad93e394f55241737588f Mon Sep 17 00:00:00 2001
From: Richard Hughes <rich...@hughsie.com>
Date: Wed, 16 Jun 2010 17:32:14 +0100
Subject: [PATCH 1/2] Allocate memory for the ClutterShaderMatrix so we can support non-square data in the future

---
 clutter/clutter-shader-types.c |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/clutter/clutter-shader-types.c b/clutter/clutter-shader-types.c
index 9ed3998..57bf11c 100644
--- a/clutter/clutter-shader-types.c
+++ b/clutter/clutter-shader-types.c
@@ -93,8 +93,8 @@ struct _ClutterShaderInt
 
 struct _ClutterShaderMatrix
 {
-  gint    size;
-  GLfloat value[16];
+  gint     size;
+  GLfloat *value;
 };
 
 static gpointer
@@ -296,7 +296,10 @@ clutter_value_init_shader_matrix (GValue *value)
 static void
 clutter_value_free_shader_matrix (GValue *value)
 {
-  g_slice_free (ClutterShaderMatrix, value->data[0].v_pointer);
+  ClutterShaderMatrix *shader_matrix;
+  shader_matrix = value->data[0].v_pointer;
+  g_free (shader_matrix->value);
+  g_slice_free (ClutterShaderMatrix, shader_matrix);
 }
 
 static void
@@ -442,7 +445,7 @@ clutter_value_set_shader_int (GValue     *value,
 /**
  * clutter_value_set_shader_matrix:
  * @value: a #GValue
- * @size: number of floating point values in @floats
+ * @size: dimension of the square floating point 2D array in @matrix
  * @matrix: a matrix of floating point values
  *
  * Sets @matrix as the contents of @value. The passed #GValue
@@ -459,11 +462,11 @@ clutter_value_set_shader_matrix (GValue       *value,
   gint i;
 
   g_return_if_fail (CLUTTER_VALUE_HOLDS_SHADER_MATRIX (value));
-  g_return_if_fail (size <= 4);
 
   shader_matrix = value->data[0].v_pointer;
 
   shader_matrix->size = size;
+  shader_matrix->value = g_new0 (GLfloat, size * size);
 
   for (i = 0; i < size * size; i++)
     shader_matrix->value[i] = matrix[i];
-- 
1.7.1

From 33f8e79deeb1a90ef11d1998b91c545058837b1b Mon Sep 17 00:00:00 2001
From: Richard Hughes <rich...@hughsie.com>
Date: Wed, 16 Jun 2010 17:46:57 +0100
Subject: [PATCH 2/2] Allow non-square matrix data to be passed to a ClutterShader

This allows programs to send large amounts of data as arrays of vectors,
rather than the old 4x4 static maximum. This functionality already existed
in COGL, but was not exploited by clutter.
---
 clutter/clutter-shader-types.c |   79 +++++++++++++++++++++++++++++++++-------
 clutter/clutter-shader-types.h |    7 ++++
 clutter/clutter-shader.c       |    5 ++-
 3 files changed, 76 insertions(+), 15 deletions(-)

diff --git a/clutter/clutter-shader-types.c b/clutter/clutter-shader-types.c
index 57bf11c..f4f131c 100644
--- a/clutter/clutter-shader-types.c
+++ b/clutter/clutter-shader-types.c
@@ -94,6 +94,7 @@ struct _ClutterShaderInt
 struct _ClutterShaderMatrix
 {
   gint     size;
+  gint     length;
   GLfloat *value;
 };
 
@@ -445,18 +446,24 @@ clutter_value_set_shader_int (GValue     *value,
 /**
  * clutter_value_set_shader_matrix:
  * @value: a #GValue
- * @size: dimension of the square floating point 2D array in @matrix
+ * @size: dimension of the vector to load,
+ *              e.g. 3 would correspond to a GLSL vec3
+ * @length: dimension of 2D array in @matrix,
+ *              to correspond with the number of vectors in the array
  * @matrix: a matrix of floating point values
  *
  * Sets @matrix as the contents of @value. The passed #GValue
  * must have been initialized using %CLUTTER_TYPE_SHADER_MATRIX.
  *
- * Since: 0.8
+ * The number of points in @matrix must be at least @size x @length.
+ *
+ * Since: 1.0
  */
 void
-clutter_value_set_shader_matrix (GValue       *value,
-                                 gint          size,
-                                 const gfloat *matrix)
+clutter_value_set_shader_matrix_full (GValue       *value,
+                                      gint          size,
+                                      gint          length,
+                                      const gfloat *matrix)
 {
   ClutterShaderMatrix *shader_matrix;
   gint i;
@@ -466,13 +473,33 @@ clutter_value_set_shader_matrix (GValue       *value,
   shader_matrix = value->data[0].v_pointer;
 
   shader_matrix->size = size;
-  shader_matrix->value = g_new0 (GLfloat, size * size);
+  shader_matrix->length = length;
+  shader_matrix->value = g_new0 (GLfloat, size * length);
 
-  for (i = 0; i < size * size; i++)
+  for (i = 0; i < size * length; i++)
     shader_matrix->value[i] = matrix[i];
 }
 
 /**
+ * clutter_value_set_shader_matrix:
+ * @value: a #GValue
+ * @size: dimension of the square floating point 2D array in @matrix
+ * @matrix: a matrix of floating point values
+ *
+ * Sets @matrix as the contents of @value. The passed #GValue
+ * must have been initialized using %CLUTTER_TYPE_SHADER_MATRIX.
+ *
+ * Since: 0.8
+ */
+void
+clutter_value_set_shader_matrix (GValue       *value,
+                                 gint          size,
+                                 const gfloat *matrix)
+{
+  clutter_value_set_shader_matrix_full (value, size, size, matrix);
+}
+
+/**
  * clutter_value_get_shader_float:
  * @value: a #GValue
  * @length: return location for the number of returned floating
@@ -537,10 +564,10 @@ clutter_value_get_shader_int (const GValue *value,
 }
 
 /**
- * clutter_value_get_shader_matrix:
+ * clutter_value_get_shader_matrix_full:
  * @value: a #GValue
- * @length: (out): return location for the number of returned floating
- *   point values, or %NULL
+ * @size: (out): return location for the size of returned vectors, or %NULL
+ * @length: (out): return location for the number of returned vectors, or %NULL
  *
  * Retrieves a matrix of floating point values stored inside
  * the passed #GValue. @value must have been initialized with
@@ -553,8 +580,9 @@ clutter_value_get_shader_int (const GValue *value,
  * Since: 0.8
  */
 G_CONST_RETURN gfloat *
-clutter_value_get_shader_matrix (const GValue *value,
-                                 gsize        *length)
+clutter_value_get_shader_matrix_full (const GValue *value,
+                                      gsize        *size,
+                                      gsize        *length)
 {
   ClutterShaderMatrix *shader_matrix;
 
@@ -562,8 +590,33 @@ clutter_value_get_shader_matrix (const GValue *value,
 
   shader_matrix = value->data[0].v_pointer;
 
+  if (size)
+    *size = shader_matrix->size;
   if (length)
-    *length = shader_matrix->size;
+    *length = shader_matrix->length;
 
   return shader_matrix->value;
 }
+
+/**
+ * clutter_value_get_shader_matrix:
+ * @value: a #GValue
+ * @length: (out): return location for the number of returned floating
+ *   point values, or %NULL
+ *
+ * Retrieves a matrix of floating point values stored inside
+ * the passed #GValue. @value must have been initialized with
+ * %CLUTTER_TYPE_SHADER_MATRIX.
+ *
+ * Return value: (array length=length) (transfer none): the pointer to a matrix
+ *   of floating point values. The returned value is owned by the #GValue and
+ *   should never be modified or freed.
+ *
+ * Since: 0.8
+ */
+G_CONST_RETURN gfloat *
+clutter_value_get_shader_matrix (const GValue *value,
+                                 gsize        *length)
+{
+  return clutter_value_get_shader_matrix_full (value, length, NULL);
+}
diff --git a/clutter/clutter-shader-types.h b/clutter/clutter-shader-types.h
index 1b48426..350c22c 100644
--- a/clutter/clutter-shader-types.h
+++ b/clutter/clutter-shader-types.h
@@ -84,12 +84,19 @@ void                    clutter_value_set_shader_int    (GValue       *value,
 void                    clutter_value_set_shader_matrix (GValue       *value,
                                                          gint          size,
                                                          const gfloat *matrix);
+void                    clutter_value_set_shader_matrix_full (GValue       *value,
+                                                         gint          size,
+                                                         gint          length,
+                                                         const gfloat *matrix);
 G_CONST_RETURN gfloat * clutter_value_get_shader_float  (const GValue *value,
                                                          gsize        *length);
 G_CONST_RETURN gint   * clutter_value_get_shader_int    (const GValue *value,
                                                          gsize        *length);
 G_CONST_RETURN gfloat * clutter_value_get_shader_matrix (const GValue *value,
                                                          gsize        *length);
+G_CONST_RETURN gfloat * clutter_value_get_shader_matrix_full (const GValue *value,
+                                                         gsize        *size,
+                                                         gsize        *length);
 
 G_END_DECLS
 
diff --git a/clutter/clutter-shader.c b/clutter/clutter-shader.c
index 9e2e845..286a4b0 100644
--- a/clutter/clutter-shader.c
+++ b/clutter/clutter-shader.c
@@ -711,6 +711,7 @@ clutter_shader_set_uniform (ClutterShader *shader,
   ClutterShaderPrivate *priv;
   GLint                 location = 0;
   gsize                 size;
+  gsize                 length;
 
   g_return_if_fail (CLUTTER_IS_SHADER (shader));
   g_return_if_fail (name != NULL);
@@ -744,8 +745,8 @@ clutter_shader_set_uniform (ClutterShader *shader,
     {
       const GLfloat *matrix;
 
-      matrix = clutter_value_get_shader_matrix (value, &size);
-      cogl_program_uniform_matrix (location, size, 1, FALSE, matrix);
+      matrix = clutter_value_get_shader_matrix_full (value, &size, &length);
+      cogl_program_uniform_matrix (location, size, length, FALSE, matrix);
     }
   else if (G_VALUE_HOLDS_FLOAT (value))
     {
-- 
1.7.1

Reply via email to