diff options
author | Timothy <[email protected]> | 2015-09-12 07:33:27 +1000 |
---|---|---|
committer | Timothy Arceri <[email protected]> | 2015-09-17 11:28:27 +1000 |
commit | 0ad44ce3735aa39391ab866c6a692eb76115b8c1 (patch) | |
tree | ad699726e070c46cb151cedce60f5aaebd4ca036 | |
parent | 12af915e27e4f10bc4c29f1cc8119b28ba27d874 (diff) |
glsl: add helper for calculating offsets for struct members
V2: update comments
Reviewed-by: Jason Ekstrand <[email protected]>
-rw-r--r-- | src/glsl/glsl_types.cpp | 26 | ||||
-rw-r--r-- | src/glsl/glsl_types.h | 8 |
2 files changed, 34 insertions, 0 deletions
diff --git a/src/glsl/glsl_types.cpp b/src/glsl/glsl_types.cpp index 755618ac28b..97c79fa4ca1 100644 --- a/src/glsl/glsl_types.cpp +++ b/src/glsl/glsl_types.cpp @@ -1040,6 +1040,32 @@ glsl_type::component_slots() const } unsigned +glsl_type::record_location_offset(unsigned length) const +{ + unsigned offset = 0; + const glsl_type *t = this->without_array(); + if (t->is_record()) { + assert(length <= t->length); + + for (unsigned i = 0; i < length; i++) { + const glsl_type *st = t->fields.structure[i].type; + const glsl_type *wa = st->without_array(); + if (wa->is_record()) { + unsigned r_offset = wa->record_location_offset(wa->length); + offset += st->is_array() ? st->length * r_offset : r_offset; + } else { + /* We dont worry about arrays here because unless the array + * contains a structure or another array it only takes up a single + * uniform slot. + */ + offset += 1; + } + } + } + return offset; +} + +unsigned glsl_type::uniform_locations() const { unsigned size = 0; diff --git a/src/glsl/glsl_types.h b/src/glsl/glsl_types.h index 02a398f6112..860276a2b17 100644 --- a/src/glsl/glsl_types.h +++ b/src/glsl/glsl_types.h @@ -292,6 +292,14 @@ struct glsl_type { unsigned component_slots() const; /** + * Calculate offset between the base location of the struct in + * uniform storage and a struct member. + * For the initial call, length is the index of the member to find the + * offset for. + */ + unsigned record_location_offset(unsigned length) const; + + /** * Calculate the number of unique values from glGetUniformLocation for the * elements of the type. * |