]> 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 77fe7e7510d9e09597712803ade770267486b26e..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"
@@ -215,11 +208,28 @@ void Program::link()
                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
@@ -244,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()