Distributed under the LGPL
*/
+#include <algorithm>
#include "arb_shader_objects.h"
#include "arb_vertex_shader.h"
#include "except.h"
namespace GL {
Program::Program():
- del_shaders(false),
- linked(false)
+ del_shaders(false)
{
- require_extension("GL_ARB_shader_objects");
- require_extension("GL_ARB_vertex_shader");
-
- id=glCreateProgramObjectARB();
+ init();
}
Program::Program(const string &vert, const string &frag):
- del_shaders(true),
- linked(false)
+ del_shaders(true)
{
- require_extension("GL_ARB_shader_objects");
- require_extension("GL_ARB_vertex_shader");
+ init();
- id=glCreateProgramObjectARB();
attach_shader(*new Shader(VERTEX_SHADER, vert));
attach_shader(*new Shader(FRAGMENT_SHADER, frag));
link();
}
+void Program::init()
+{
+ static RequireExtension _ext("GL_ARB_shader_objects");
+
+ linked=false;
+ id=glCreateProgramObjectARB();
+}
+
Program::~Program()
{
if(del_shaders)
void Program::bind_attribute(uint index, const string &name)
{
+ static RequireExtension _ext("GL_ARB_vertex_shader");
glBindAttribLocationARB(id, index, name.c_str());
}
return string(log, len);
}
-void Program::bind()
+void Program::bind() const
{
if(!linked)
throw InvalidState("Program is not linked");
return glGetUniformLocationARB(id, n.c_str());
}
-/*void Program::uniform(int i, int v)
-{
- glUniform1iARB(i, v);
-}
-
-void Program::uniform(int i, float x)
-{
- glUniform1fARB(i, x);
-}
-
-void Program::uniform(int i, float x, float y)
-{
- glUniform2fARB(i, x, y);
-}
-
-void Program::uniform(int i, float x, float y, float z)
-{
- glUniform3fARB(i, x, y, z);
-}
-
-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()
{
if(cur_prog)
bind();
}
-Program *Program::cur_prog=0;
+const Program *Program::cur_prog=0;
Program::Loader::Loader(Program &p):