From: Ian Romanick Date: Thu, 10 Jun 2010 00:27:31 +0000 (-0700) Subject: Add glsl_types::field_index to get the location of a record field X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=eeedd355cfc2f0c578282657bd4259440a88742c;p=mesa.git Add glsl_types::field_index to get the location of a record field --- diff --git a/glsl_types.cpp b/glsl_types.cpp index 9487819a447..4b6a61a13c2 100644 --- a/glsl_types.cpp +++ b/glsl_types.cpp @@ -718,3 +718,18 @@ glsl_type::field_type(const char *name) const return error_type; } + + +int +glsl_type::field_index(const char *name) const +{ + if (this->base_type != GLSL_TYPE_STRUCT) + return -1; + + for (unsigned i = 0; i < this->length; i++) { + if (strcmp(name, this->fields.structure[i].name) == 0) + return i; + } + + return -1; +} diff --git a/glsl_types.h b/glsl_types.h index 823897df4ae..3265016146d 100644 --- a/glsl_types.h +++ b/glsl_types.h @@ -355,6 +355,12 @@ struct glsl_type { const glsl_type *field_type(const char *name) const; + /** + * Get the location of a filed within a record type + */ + int field_index(const char *name) const; + + /** * Query the number of elements in an array type *