]> git.tdb.fi Git - libs/gl.git/blobdiff - source/program.cpp
Drop Id tags and copyright notices from files
[libs/gl.git] / source / program.cpp
index eb9481f2426ae7908f2a875aa9efa07ab7caed3e..3c3a78b7c298a15bb6e55f8b9e75268fd788c4c7 100644 (file)
@@ -1,10 +1,3 @@
-/* $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"
@@ -212,24 +205,37 @@ void Program::bind_attribute(unsigned index, const string &name)
 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);
@@ -248,7 +254,11 @@ void Program::bind() 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()