From: Mikko Rasa Date: Sat, 17 Nov 2012 22:14:58 +0000 (+0200) Subject: More robust handling of uniform arrays X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=commitdiff_plain;h=5c883e77411a7eccc58d345b7d53d8709ae39452 More robust handling of uniform arrays --- diff --git a/source/program.cpp b/source/program.cpp index 636988d7..1735d5fa 100644 --- a/source/program.cpp +++ b/source/program.cpp @@ -192,12 +192,19 @@ void Program::link() vector 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(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 && offsetsecond.size) return i->second.location+offset; }