Add glsl_type::field_type
authorIan Romanick <ian.d.romanick@intel.com>
Mon, 19 Apr 2010 22:40:01 +0000 (15:40 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Thu, 29 Apr 2010 01:22:54 +0000 (18:22 -0700)
Query the type of a structure field

glsl_types.cpp
glsl_types.h

index b4abfdd..71d7dd3 100644 (file)
@@ -657,3 +657,18 @@ glsl_type::get_array_instance(const glsl_type *base, unsigned array_size)
 
    return t;
 }
+
+
+const glsl_type *
+glsl_type::field_type(const char *name) const
+{
+   if (this->base_type != GLSL_TYPE_STRUCT)
+      return error_type;
+
+   for (unsigned i = 0; i < this->length; i++) {
+      if (strcmp(name, this->fields.structure[i].name) == 0)
+        return this->fields.structure[i].type;
+   }
+
+   return error_type;
+}
index 2bdfeb8..1f8559a 100644 (file)
@@ -332,6 +332,17 @@ struct glsl_type {
         : error_type;
    }
 
+
+   /**
+    * Get the type of a structure field
+    *
+    * \return
+    * Pointer to the type of the named field.  If the type is not a structure
+    * or the named field does not exist, \c glsl_type::error_type is returned.
+    */
+   const glsl_type *field_type(const char *name) const;
+
+
    /**
     * Query the number of elements in an array type
     *