summaryrefslogtreecommitdiff
path: root/glsl_types.cpp
diff options
context:
space:
mode:
authorIan Romanick <ian.d.romanick@intel.com>2010-06-21 16:05:00 -0700
committerIan Romanick <ian.d.romanick@intel.com>2010-06-23 10:56:04 -0700
commit57bb893a46ced683792f8e7ebdffbb5c5a892b84 (patch)
tree70a3ad8e1bfce94ee15b7741a327223dec27b81c /glsl_types.cpp
parent13e10e43c315be3ba2bee509502bc9c542d90249 (diff)
glsl_type: Add method to get number of slots used by a type
Diffstat (limited to 'glsl_types.cpp')
-rw-r--r--glsl_types.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/glsl_types.cpp b/glsl_types.cpp
index 290756d453..2b7c5bce30 100644
--- a/glsl_types.cpp
+++ b/glsl_types.cpp
@@ -732,3 +732,31 @@ glsl_type::field_index(const char *name) const
return -1;
}
+
+
+unsigned
+glsl_type::component_slots() const
+{
+ switch (this->base_type) {
+ case GLSL_TYPE_UINT:
+ case GLSL_TYPE_INT:
+ case GLSL_TYPE_FLOAT:
+ case GLSL_TYPE_BOOL:
+ return this->components();
+
+ case GLSL_TYPE_STRUCT: {
+ unsigned size = 0;
+
+ for (unsigned i = 0; i < this->length; i++)
+ size += this->fields.structure[i].type->component_slots();
+
+ return size;
+ }
+
+ case GLSL_TYPE_ARRAY:
+ return this->length * this->fields.array->component_slots();
+
+ default:
+ return 0;
+ }
+}