[Mesa-dev] [PATCH V4 5/6] glsl: add helper for calculating offsets for struct members
Timothy Arceri
t_arceri at yahoo.com.au
Tue Sep 15 00:51:04 PDT 2015
From: Timothy <t_arceri at yahoo.com.au>
Cc: Jason Ekstrand <jason.ekstrand at intel.com>
---
src/glsl/glsl_types.cpp | 20 ++++++++++++++++++++
src/glsl/glsl_types.h | 7 +++++++
2 files changed, 27 insertions(+)
diff --git a/src/glsl/glsl_types.cpp b/src/glsl/glsl_types.cpp
index 755618a..38b1660 100644
--- a/src/glsl/glsl_types.cpp
+++ b/src/glsl/glsl_types.cpp
@@ -1040,6 +1040,26 @@ 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()) {
+ 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 {
+ 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 02a398f..8ee8968 100644
--- a/src/glsl/glsl_types.h
+++ b/src/glsl/glsl_types.h
@@ -292,6 +292,13 @@ struct glsl_type {
unsigned component_slots() const;
/**
+ * Calculate offset between the base location and this 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.
*
--
2.4.3
More information about the mesa-dev
mailing list