From: Ian Romanick Date: Mon, 19 Apr 2010 22:40:01 +0000 (-0700) Subject: Add glsl_type::field_type X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8f755dcb67848966c350883ad6fbb50547d9ec24;p=mesa.git Add glsl_type::field_type Query the type of a structure field --- diff --git a/glsl_types.cpp b/glsl_types.cpp index b4abfdd7b68..71d7dd36f84 100644 --- a/glsl_types.cpp +++ b/glsl_types.cpp @@ -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; +} diff --git a/glsl_types.h b/glsl_types.h index 2bdfeb8cb60..1f8559aa6a4 100644 --- a/glsl_types.h +++ b/glsl_types.h @@ -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 *