1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
#include "graphic_shader.h"
#include "shader/util.h"
GraphicShader::Guard::Guard(GLuint id):
_id(id) {
glUseProgram(_id);
}
GraphicShader::Guard::~Guard() {
glUseProgram(0);
}
GraphicShader::Guard GraphicShader::use() const {
return Guard(_id);
}
GraphicShader::GraphicShader(const std::string& vertex,
const std::string& geometry,
const std::string fragment):
_id(glCreateProgram()) {
glAttachShader(_id, util::compileShader(vertex, GL_VERTEX_SHADER));
glAttachShader(_id, util::compileShader(geometry, GL_GEOMETRY_SHADER));
glAttachShader(_id, util::compileShader(fragment, GL_FRAGMENT_SHADER));
glLinkProgram(_id);
}
GraphicShader::GraphicShader(const std::string& vertex, const std::string fragment):
_id(glCreateProgram()) {
glAttachShader(_id, util::compileShader(vertex, GL_VERTEX_SHADER));
glAttachShader(_id, util::compileShader(fragment, GL_FRAGMENT_SHADER));
glLinkProgram(_id);
}
GraphicShader::~GraphicShader() {
glDeleteProgram(_id);
}
GLuint GraphicShader::setUniform(const std::string& name, int value) const {
GLuint id = util::getUniform(_id, name);
glUniform1i(id, value);
return id;
}
GLuint GraphicShader::setUniform(const std::string& name, GLuint value) const {
GLuint id = util::getUniform(_id, name);
glUniform1ui(id, value);
return id;
}
GLuint GraphicShader::setUniform(const std::string& name, const std::vector<GLuint>& v) const {
GLuint id = util::getUniform(_id, name);
glUniform1iv(id, v.size(), reinterpret_cast<const GLint*>(v.data()));
return id;
}
GLuint GraphicShader::setUniform(const std::string& name, glm::mat4& M) const {
GLuint id = util::getUniform(_id, name);
glUniformMatrix4fv(id, 1, GL_FALSE, &M[0][0]);
return id;
}
|