if(!(*i)->is_compiled())
(*i)->compile();
+ uniforms.clear();
+
glLinkProgramARB(id);
int value;
glGetObjectParameterivARB(id, GL_OBJECT_LINK_STATUS_ARB, &value);
if(!(linked = value))
throw CompileError(get_info_log());
+
+ glGetObjectParameterivARB(id, GL_OBJECT_ACTIVE_UNIFORMS_ARB, &value);
+ for(int i=0; i<value; ++i)
+ {
+ UniformInfo info;
+ char name[128];
+ int len = 0;
+ glGetActiveUniformARB(id, i, 128, &len, &info.size, &info.type, name);
+ if(len)
+ {
+ info.name = name;
+ info.location = glGetUniformLocationARB(id, name);
+ uniforms[name] = info;
+ }
+ }
}
string Program::get_info_log() const
int Program::get_uniform_location(const string &n) const
{
- return glGetUniformLocationARB(id, n.c_str());
+ map<string, UniformInfo>::const_iterator i = uniforms.find(n);
+ if(i==uniforms.end())
+ return -1;
+
+ return i->second.location;
}
void Program::unbind()
std::string create_flags() const;
};
+ struct UniformInfo
+ {
+ std::string name;
+ int location;
+ int size;
+ GLenum type;
+ };
+
private:
unsigned id;
std::list<Shader *> shaders;
bool del_shaders;
bool linked;
+ std::map<std::string, UniformInfo> uniforms;
public:
Program();