glsl: Fix calculation of std140 offset alignment for mat2s.
authorEric Anholt <eric@anholt.net>
Mon, 23 Jul 2012 21:11:38 +0000 (14:11 -0700)
committerEric Anholt <eric@anholt.net>
Tue, 7 Aug 2012 20:54:50 +0000 (13:54 -0700)
We were getting the base offset of a vec2, not of a vec2[2] like the quoted
spec text says we should.

v2: Fix swapped then/else cases.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/glsl/glsl_types.cpp

index 3d7866058240cfc44c385b191d6af6e1d5778c7f..2aa51f0b3861aa02d0815fd419e174f19c0ce9fa 100644 (file)
@@ -694,14 +694,19 @@ glsl_type::std140_base_alignment(bool row_major) const
     *     row vectors with <C> components each, according to rule (4).
     */
    if (this->is_matrix()) {
-      const struct glsl_type *vec_type;
+      const struct glsl_type *vec_type, *array_type;
+      int c = this->matrix_columns;
+      int r = this->vector_elements;
+
       if (row_major) {
-        vec_type = get_instance(GLSL_TYPE_FLOAT, this->vector_elements, 1);
+        vec_type = get_instance(GLSL_TYPE_FLOAT, c, 1);
+        array_type = glsl_type::get_array_instance(vec_type, r);
       } else {
-        vec_type = get_instance(GLSL_TYPE_FLOAT, this->matrix_columns, 1);
+        vec_type = get_instance(GLSL_TYPE_FLOAT, r, 1);
+        array_type = glsl_type::get_array_instance(vec_type, c);
       }
 
-      return vec_type->std140_base_alignment(false);
+      return array_type->std140_base_alignment(false);
    }
 
    /* (9) If the member is a structure, the base alignment of the