]> git.tdb.fi Git - libs/gl.git/commitdiff
More robust handling of uniform arrays
authorMikko Rasa <tdb@tdb.fi>
Sat, 17 Nov 2012 22:14:58 +0000 (00:14 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 24 Nov 2012 22:27:05 +0000 (00:27 +0200)
source/program.cpp

index 636988d75c75dd11f3728906cf3c761b31553b34..1735d5fa6e328afd2f3141f7783b3544d74bb083 100644 (file)
@@ -192,12 +192,19 @@ void Program::link()
 
        vector<const UniformInfo *> blockless_uniforms;
        for(UniformMap::iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
+       {
                if(!i->second.block)
                {
                        i->second.location = glGetUniformLocation(id, i->second.name.c_str());
                        blockless_uniforms.push_back(&i->second);
                }
 
+               /* Some implementations report the first element of a uniform array,
+               others report just the name of an array. */
+               if(i->second.name.size()>3 && !i->second.name.compare(i->second.name.size()-3, 3, "[0]"))
+                       i->second.name.erase(i->second.name.size()-3, 3);
+       }
+
        uniform_layout_hash = compute_layout_hash(blockless_uniforms);
 }
 
@@ -249,7 +256,7 @@ int Program::get_uniform_location(const string &n) const
                                gives us the first element of the array, so try to look that up and
                                add an offset. */
                                unsigned offset = lexical_cast<unsigned>(n.substr(open_bracket+1, n.size()-2-open_bracket));
-                               i = uniforms.find(n.substr(0, open_bracket)+"[0]");
+                               i = uniforms.find(n.substr(0, open_bracket));
                                if(i!=uniforms.end() && !i->second.block && offset<i->second.size)
                                        return i->second.location+offset;
                        }