2015-11-07 14:11:23 +00:00
|
|
|
#include "program.hpp"
|
|
|
|
|
2015-11-09 15:06:34 +00:00
|
|
|
#include "shader.hpp"
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
|
2015-11-11 17:28:11 +00:00
|
|
|
const std::string Program::filename(const std::string &name)
|
2015-11-07 14:11:23 +00:00
|
|
|
{
|
2015-11-11 17:28:11 +00:00
|
|
|
return "/data/shaders/" + name;
|
|
|
|
}
|
|
|
|
|
2015-11-13 11:20:00 +00:00
|
|
|
Program::Program(const std::string &name)
|
2015-11-11 17:28:11 +00:00
|
|
|
{
|
|
|
|
const std::string path = filename(name) + '/';
|
2015-11-09 15:06:34 +00:00
|
|
|
|
|
|
|
const Shader vertex_shader = Shader(GL_VERTEX_SHADER, (path + "vertex.glsl").c_str());
|
|
|
|
const Shader fragment_shader = Shader(GL_FRAGMENT_SHADER, (path + "fragment.glsl").c_str());
|
|
|
|
|
2015-11-07 14:11:23 +00:00
|
|
|
_id = glCreateProgram();
|
|
|
|
|
2015-11-09 15:06:34 +00:00
|
|
|
glAttachShader(_id, vertex_shader.id());
|
|
|
|
glAttachShader(_id, fragment_shader.id());
|
2015-11-07 14:11:23 +00:00
|
|
|
}
|
|
|
|
|
2015-11-13 11:29:42 +00:00
|
|
|
void Program::bind_attrib_location(GLuint index, const GLchar *name)
|
2015-11-07 14:11:23 +00:00
|
|
|
{
|
2015-11-13 11:29:42 +00:00
|
|
|
glBindAttribLocation(_id, index, name);
|
2015-11-07 14:11:23 +00:00
|
|
|
}
|
|
|
|
|
2015-11-13 13:02:14 +00:00
|
|
|
void Program::bind_attribs(GLuint count, const GLchar *const names[])
|
|
|
|
{
|
|
|
|
for (GLuint index = 0; index < count; ++index)
|
|
|
|
bind_attrib_location(index, names[index]);
|
|
|
|
}
|
|
|
|
|
2015-11-13 11:23:22 +00:00
|
|
|
void Program::link()
|
|
|
|
{
|
|
|
|
glLinkProgram(_id);
|
|
|
|
}
|
|
|
|
|
2015-11-13 11:29:42 +00:00
|
|
|
void Program::use() const
|
|
|
|
{
|
|
|
|
glUseProgram(_id);
|
|
|
|
}
|
|
|
|
|
2015-11-07 14:11:23 +00:00
|
|
|
GLuint Program::get_uniform_location(const GLchar *name) const
|
|
|
|
{
|
|
|
|
return glGetUniformLocation(_id, name);
|
|
|
|
}
|