]> git.tdb.fi Git - libs/gl.git/blobdiff - source/program.cpp
Require mspgbase now that Image was moved there
[libs/gl.git] / source / program.cpp
index f34133faf767b1e905f7706e1caae938f606c6a4..eed8b87a469a1ccf3f58cdb9f43a5fba1c10764d 100644 (file)
@@ -5,6 +5,7 @@ Copyright © 2007 Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
+#include <algorithm>
 #include "arb_shader_objects.h"
 #include "arb_vertex_shader.h"
 #include "except.h"
@@ -74,20 +75,20 @@ void Program::set_del_shaders(bool ds)
        del_shaders=ds;
 }
 
-void Program::bind_attribute(int index, const string &name)
+void Program::bind_attribute(uint index, const string &name)
 {
        glBindAttribLocationARB(id, index, name.c_str());
 }
 
-bool Program::link()
+void Program::link()
 {
        for(list<Shader *>::iterator i=shaders.begin(); i!=shaders.end(); ++i)
-               if(!(*i)->get_compiled() && !(*i)->compile())
-                       return false;
+               if(!(*i)->get_compiled())
+                       (*i)->compile();
 
        glLinkProgramARB(id);
-       linked=get_param(GL_LINK_STATUS);
-       return linked;
+       if(!(linked=get_param(GL_LINK_STATUS)))
+               throw CompileError(get_info_log());
 }
 
 int Program::get_param(GLenum param) const
@@ -119,7 +120,7 @@ int Program::get_uniform_location(const string &n) const
        return glGetUniformLocationARB(id, n.c_str());
 }
 
-void Program::uniform(int i, int v)
+/*void Program::uniform(int i, int v)
 {
        glUniform1iARB(i, v);
 }
@@ -144,10 +145,15 @@ void Program::uniform(int i, float x, float y, float z, float w)
        glUniform4fARB(i, x, y, z, w);
 }
 
+void Program::uniform4(int i, const float *v)
+{
+       glUniform4fvARB(i, 1, v);
+}
+
 void Program::uniform_matrix4(int i, const float *v)
 {
        glUniformMatrix4fvARB(i, 1, false, v);
-}
+}*/
 
 void Program::unbind()
 {
@@ -174,11 +180,7 @@ Program::Loader::Loader(Program &p):
 
        add("vertex_shader",   &Loader::vertex_shader);
        add("fragment_shader", &Loader::fragment_shader);
-}
-
-Program::Loader::~Loader()
-{
-       prog.link();
+       add("attribute",       &Loader::attribute);
 }
 
 void Program::Loader::vertex_shader(const string &src)
@@ -191,5 +193,15 @@ void Program::Loader::fragment_shader(const string &src)
        prog.attach_shader(*new Shader(FRAGMENT_SHADER, src));
 }
 
+void Program::Loader::attribute(uint i, const string &n)
+{
+       prog.bind_attribute(i, n);
+}
+
+void Program::Loader::finish()
+{
+       prog.link();
+}
+
 } // namespace GL
 } // namespace Msp