summaryrefslogtreecommitdiff
path: root/glstate.cpp
diff options
context:
space:
mode:
authorZack Rusin <zack@kde.org>2011-11-15 21:33:31 -0500
committerZack Rusin <zack@kde.org>2011-11-15 21:33:31 -0500
commita0f95ec9c6acaf25291461ef7ddc124f281dbceb (patch)
treeaaee08dc8719429667d7223933a812faecb59833 /glstate.cpp
parent38c932b18ad60176980f0c99f202c610757c000a (diff)
Fix fetching of the data for uniform arrays.
The initial array element is usually returned as arrayName[0] not arrayName which means that we were usually creating two-dimensional arrays for those elements which in turned always returned garbage.
Diffstat (limited to 'glstate.cpp')
-rw-r--r--glstate.cpp33
1 files changed, 30 insertions, 3 deletions
diff --git a/glstate.cpp b/glstate.cpp
index db1128a..9445645 100644
--- a/glstate.cpp
+++ b/glstate.cpp
@@ -205,10 +205,33 @@ dumpProgramObj(JSONWriter &json, GLhandleARB programObj)
}
}
+/*
+ * When fetching the uniform name of an array we usually get name[0]
+ * so we need to cut the trailing "[0]" in order to properly construct
+ * array names later. Otherwise we endup with stuff like
+ * uniformArray[0][0],
+ * uniformArray[0][1],
+ * instead of
+ * uniformArray[0],
+ * uniformArray[1].
+ */
+static std::string
+resolveUniformName(const GLchar *name, GLint size)
+{
+ std::string qualifiedName(name);
+ if (size > 1) {
+ std::string::size_type nameLength = qualifiedName.length();
+ static const char * const arrayStart = "[0]";
+ static const int arrayStartLen = 3;
+ if (qualifiedName.rfind(arrayStart) == (nameLength - arrayStartLen)) {
+ qualifiedName = qualifiedName.substr(0, nameLength - 3);
+ }
+ }
+ return qualifiedName;
+}
static void
dumpUniform(JSONWriter &json, GLint program, GLint size, GLenum type, const GLchar *name) {
-
GLenum elemType;
GLint numElems;
__gl_uniform_size(type, elemType, numElems);
@@ -223,9 +246,11 @@ dumpUniform(JSONWriter &json, GLint program, GLint size, GLenum type, const GLch
GLint i, j;
+ std::string qualifiedName = resolveUniformName(name, size);
+
for (i = 0; i < size; ++i) {
std::stringstream ss;
- ss << name;
+ ss << qualifiedName;
if (size > 1) {
ss << '[' << i << ']';
@@ -301,9 +326,11 @@ dumpUniformARB(JSONWriter &json, GLhandleARB programObj, GLint size, GLenum type
GLint i, j;
+ std::string qualifiedName = resolveUniformName(name, size);
+
for (i = 0; i < size; ++i) {
std::stringstream ss;
- ss << name;
+ ss << qualifiedName;
if (size > 1) {
ss << '[' << i << ']';