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 13:37:53 +00:00
|
|
|
Program::Program(const std::string &name):
|
2015-11-13 14:40:50 +00:00
|
|
|
vertex_shader(name + ".vert"),
|
|
|
|
fragment_shader(name + ".frag")
|
2015-11-13 13:37:53 +00:00
|
|
|
{}
|
2015-11-07 14:11:23 +00:00
|
|
|
|
2015-11-13 13:52:01 +00:00
|
|
|
const Executable *Program::build(
|
|
|
|
GLuint attrib_count, const GLchar *const attribs[],
|
|
|
|
unsigned uniform_count, const GLchar *const uniforms[])
|
2015-11-07 14:11:23 +00:00
|
|
|
{
|
2015-11-13 13:37:53 +00:00
|
|
|
Executable *exe = new Executable();
|
2015-11-13 13:10:49 +00:00
|
|
|
|
2015-11-13 13:37:53 +00:00
|
|
|
exe->attach_shader(vertex_shader);
|
|
|
|
exe->attach_shader(fragment_shader);
|
2015-11-13 13:10:49 +00:00
|
|
|
|
2015-11-13 13:52:01 +00:00
|
|
|
for (GLuint attrib = 0; attrib < attrib_count; ++attrib)
|
|
|
|
exe->bind_attrib_location(attrib, attribs[attrib]);
|
2015-11-13 11:23:22 +00:00
|
|
|
|
2015-11-13 13:37:53 +00:00
|
|
|
exe->link();
|
2015-11-13 11:29:42 +00:00
|
|
|
|
2015-11-13 13:52:01 +00:00
|
|
|
exe->get_uniforms(uniform_count, uniforms);
|
|
|
|
|
2015-11-13 13:37:53 +00:00
|
|
|
return exe;
|
2015-11-07 14:11:23 +00:00
|
|
|
}
|