From 8f755dcb67848966c350883ad6fbb50547d9ec24 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Mon, 19 Apr 2010 15:40:01 -0700 Subject: [PATCH] Add glsl_type::field_type Query the type of a structure field --- glsl_types.cpp | 15 +++++++++++++++ glsl_types.h | 11 +++++++++++ 2 files changed, 26 insertions(+) diff --git a/glsl_types.cpp b/glsl_types.cpp index b4abfdd..71d7dd3 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 2bdfeb8..1f8559a 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 * -- 2.7.4