blob: 83e06e1287c30eca50f72d66394891450d5e3751 (
plain) (
blame)
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
|
#pragma once
#include <string>
class Shader {
std::string shaderSource;
GLuint shaderId;
bool isVertex = true;
Shader(const Shader &);
public:
Shader(std::string fileName, bool vertex = true);
~Shader();
void bind();
GLuint GetId() {
return shaderId;
}
};
class ShaderProgram {
GLuint shaderProgram;
public:
ShaderProgram() {
shaderProgram = glCreateProgram();
}
~ShaderProgram() {
glDeleteProgram(shaderProgram);
}
void Attach(Shader &shader) {
glAttachShader(shaderProgram, shader.GetId());
}
void Link() {
glLinkProgram(shaderProgram);
GLint success;
GLchar infoLog[512];
glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success);
if (!success) {
glGetProgramInfoLog(shaderProgram, 512, NULL, infoLog);
std::cout << "Shader program linking failed: " << infoLog << std::endl;
}
glUseProgram(shaderProgram);
}
GLuint GetId() {
return shaderProgram;
}
explicit operator GLuint() const {
return shaderProgram;
}
};
|