summaryrefslogtreecommitdiff
path: root/src/glsl/glsl_types.cpp
diff options
context:
space:
mode:
authorPaul Berry <stereotype441@gmail.com>2013-07-31 08:24:48 -0700
committerPaul Berry <stereotype441@gmail.com>2013-08-01 20:19:22 -0700
commit7d95d2b4c9b39b42ea7f9669c8c0da0b229c327c (patch)
tree4b97205d68e38262578e4a453e3f5ad7ac3aa0f8 /src/glsl/glsl_types.cpp
parent0026ad4994ca88a6cdd4e5ef4098469ab57bdcc1 (diff)
glsl: Expand count_attribute_slots() to cover structs.
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Diffstat (limited to 'src/glsl/glsl_types.cpp')
-rw-r--r--src/glsl/glsl_types.cpp37
1 files changed, 32 insertions, 5 deletions
diff --git a/src/glsl/glsl_types.cpp b/src/glsl/glsl_types.cpp
index 0c639b3eb87..0c7e8eb11a3 100644
--- a/src/glsl/glsl_types.cpp
+++ b/src/glsl/glsl_types.cpp
@@ -846,13 +846,40 @@ glsl_type::count_attribute_slots() const
* should be safe to assume the total number of slots consumed by an array
* is the number of entries in the array multiplied by the number of slots
* consumed by a single element of the array.
+ *
+ * The spec says nothing about how structs are counted, because vertex
+ * attributes are not allowed to be (or contain) structs. However, Mesa
+ * allows varying structs, the number of varying slots taken up by a
+ * varying struct is simply equal to the sum of the number of slots taken
+ * up by each element.
*/
+ switch (this->base_type) {
+ case GLSL_TYPE_UINT:
+ case GLSL_TYPE_INT:
+ case GLSL_TYPE_FLOAT:
+ case GLSL_TYPE_BOOL:
+ return this->matrix_columns;
- if (this->is_array())
- return this->array_size() * this->element_type()->count_attribute_slots();
+ case GLSL_TYPE_STRUCT:
+ case GLSL_TYPE_INTERFACE: {
+ unsigned size = 0;
- if (this->is_matrix())
- return this->matrix_columns;
+ for (unsigned i = 0; i < this->length; i++)
+ size += this->fields.structure[i].type->count_attribute_slots();
- return 1;
+ return size;
+ }
+
+ case GLSL_TYPE_ARRAY:
+ return this->length * this->fields.array->count_attribute_slots();
+
+ case GLSL_TYPE_SAMPLER:
+ case GLSL_TYPE_VOID:
+ case GLSL_TYPE_ERROR:
+ break;
+ }
+
+ assert(!"Unexpected type in count_attribute_slots()");
+
+ return 0;
}