diff options
| -rw-r--r-- | glsl_types.cpp | 28 | ||||
| -rw-r--r-- | glsl_types.h | 9 | 
2 files changed, 37 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; +   } +} diff --git a/glsl_types.h b/glsl_types.h index 3265016146..939c173fd4 100644 --- a/glsl_types.h +++ b/glsl_types.h @@ -215,6 +215,15 @@ struct glsl_type {     }     /** +    * Calculate the number of components slots required to hold this type +    * +    * This is used to determine how many uniform or varying locations a type +    * might occupy. +    */ +   unsigned component_slots() const; + + +   /**      * Query whether or not a type is a scalar (non-vector and non-matrix).      */     bool is_scalar() const | 
