1
0
Fork 0
This repository has been archived on 2023-03-27. You can view files and clone it, but cannot push or open issues or pull requests.
matabstrix/src/program.cpp

54 lines
1.1 KiB
C++
Raw Normal View History

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:10:49 +00:00
const Program *Program::build(GLuint count, const GLchar *const names[])
2015-11-13 13:02:14 +00:00
{
for (GLuint index = 0; index < count; ++index)
bind_attrib_location(index, names[index]);
2015-11-13 13:10:49 +00:00
link();
return this;
2015-11-13 13:02:14 +00:00
}
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);
}