diff options
author | Tapani Pälli <[email protected]> | 2014-06-05 07:37:16 +0300 |
---|---|---|
committer | Tapani Pälli <[email protected]> | 2014-06-16 06:49:59 +0300 |
commit | dadc3d04f034327b4afeeadf9a860e1b620fab37 (patch) | |
tree | b1947bb1840d456474a8f56bc82f8d6a315b6644 /src/glsl | |
parent | bfe42ddd99e8702e2daf14238966069fd25b6d0e (diff) |
glsl: add glsl_type::uniform_locations() helper function
This function calculates the number of unique values from
glGetUniformLocation for the elements of the type.
Signed-off-by: Tapani Pälli <[email protected]>
Reviewed-by: Ian Romanick <[email protected]>
Diffstat (limited to 'src/glsl')
-rw-r--r-- | src/glsl/glsl_types.cpp | 26 | ||||
-rw-r--r-- | src/glsl/glsl_types.h | 6 |
2 files changed, 32 insertions, 0 deletions
diff --git a/src/glsl/glsl_types.cpp b/src/glsl/glsl_types.cpp index 62a908782b1..f9cd258fefa 100644 --- a/src/glsl/glsl_types.cpp +++ b/src/glsl/glsl_types.cpp @@ -675,6 +675,32 @@ glsl_type::component_slots() const return 0; } +unsigned +glsl_type::uniform_locations() const +{ + if (this->is_matrix()) + return 1; + + unsigned size = 0; + + switch (this->base_type) { + case GLSL_TYPE_STRUCT: + case GLSL_TYPE_INTERFACE: + for (unsigned i = 0; i < this->length; i++) + size += this->fields.structure[i].type->uniform_locations(); + return size; + case GLSL_TYPE_ARRAY: + return this->length * this->fields.array->uniform_locations(); + default: + break; + } + + /* The location count for many types match with component_slots() result, + * all expections should be handled above. + */ + return component_slots(); +} + bool glsl_type::can_implicitly_convert_to(const glsl_type *desired, _mesa_glsl_parse_state *state) const diff --git a/src/glsl/glsl_types.h b/src/glsl/glsl_types.h index 35a4e6acc8c..f6d4a02ab68 100644 --- a/src/glsl/glsl_types.h +++ b/src/glsl/glsl_types.h @@ -256,6 +256,12 @@ struct glsl_type { unsigned component_slots() const; /** + * Calculate the number of unique values from glGetUniformLocation for the + * elements of the type. + */ + unsigned uniform_locations() const; + + /** * Calculate the number of attribute slots required to hold this type * * This implements the language rules of GLSL 1.50 for counting the number |