glsl: add glsl_type::uniform_locations() helper function
authorTapani Pälli <tapani.palli@intel.com>
Thu, 5 Jun 2014 04:37:16 +0000 (07:37 +0300)
committerTapani Pälli <tapani.palli@intel.com>
Mon, 16 Jun 2014 03:49:59 +0000 (06:49 +0300)
This function calculates the number of unique values from
glGetUniformLocation for the elements of the type.

Signed-off-by: Tapani Pälli <tapani.palli@intel.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
src/glsl/glsl_types.cpp
src/glsl/glsl_types.h

index 62a908782b1fefb0f19067bb06c9c8027541b18b..f9cd258fefa06b74f244cce16f527e0b9ae81b08 100644 (file)
@@ -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
index 35a4e6acc8c867aadb94b02ce97806e5d74f2cf7..f6d4a02ab68b4f9881ec04d62bc11fc7b53020f2 100644 (file)
@@ -255,6 +255,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
     *