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-13 15:02:01 +00:00
|
|
|
return "/data/programs/" + name;
|
2015-11-11 17:28:11 +00:00
|
|
|
}
|
|
|
|
|
2015-11-13 14:52:35 +00:00
|
|
|
Program::Program(Store &store, const std::string &name):
|
|
|
|
vertex_shader(store.load<Shader>(name + ".vert")),
|
|
|
|
fragment_shader(store.load<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[],
|
2015-11-13 15:02:01 +00:00
|
|
|
unsigned uniform_count, const GLchar *const uniforms[]) const
|
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 14:52:35 +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
|
|
|
}
|