-/* $Id$
-
-This file is part of libmspgl
-Copyright © 2007 Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
#include <algorithm>
#include "arb_shader_objects.h"
#include "arb_vertex_shader.h"
void Program::link()
{
for(list<Shader *>::iterator i=shaders.begin(); i!=shaders.end(); ++i)
- if(!(*i)->get_compiled())
+ if(!(*i)->is_compiled())
(*i)->compile();
+ uniforms.clear();
+
glLinkProgramARB(id);
- if(!(linked = get_param(GL_LINK_STATUS)))
+ int value;
+ glGetObjectParameterivARB(id, GL_OBJECT_LINK_STATUS_ARB, &value);
+ if(!(linked = value))
throw CompileError(get_info_log());
-}
-int Program::get_param(GLenum param) const
-{
- int value;
- glGetObjectParameterivARB(id, param, &value);
- return value;
+ 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
{
- GLsizei len = get_param(GL_INFO_LOG_LENGTH);
+ GLsizei len = 0;
+ glGetObjectParameterivARB(id, GL_OBJECT_INFO_LOG_LENGTH_ARB, &len);
char log[len+1];
glGetInfoLogARB(id, len+1, &len, log);
return string(log, len);
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()