- char log[len+1];
- glGetInfoLogARB(id, len+1, &len, log);
- return string(log, len);
+ char *buf = new char[len+1];
+ glGetInfoLogARB(id, len+1, &len, buf);
+ string log(buf, len);
+ delete[] buf;
+ return log;
+}
+
+int Program::get_uniform_location(const string &n) const
+{
+ UniformMap::const_iterator i = uniforms.find(n);
+ if(i==uniforms.end())
+ {
+ if(n[n.size()-1]==']')
+ {
+ string::size_type open_bracket = n.rfind('[');
+ if(open_bracket!=string::npos)
+ {
+ /* The requested name looks like an array. glGetActiveUniform only
+ gives us the first element of the array, so try to look that up and
+ add an offset. */
+ int offset = lexical_cast<unsigned>(n.substr(open_bracket+1, n.size()-2-open_bracket));
+ i = uniforms.find(n.substr(0, open_bracket)+"[0]");
+ if(i!=uniforms.end() && offset<i->second.size)
+ return i->second.location+offset;
+ }
+ }
+ return -1;
+ }
+
+ return i->second.location;