blob: fe5d5761afdb13694ad1174c262ab80a33f9eab4 (
plain)
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
|
#include <GL/glew.h>
#include <stdexcept>
#include "Program.hpp"
#include "../../Common/Assert.hpp"
namespace MC::GFX::Shading {
Program::Program(Shader vertex, Shader fragment) {
m_program = glCreateProgram();
glAttachShader(m_program, fragment.get());
glAttachShader(m_program, vertex.get());
glLinkProgram(m_program);
glDeleteShader(fragment.get());
glDeleteShader(vertex.get());
GLint success;
glGetProgramiv(m_program, GL_LINK_STATUS, &success);
if(!success) {
Char message[512] = {};
glGetProgramInfoLog(m_program, 512, nullptr, message);
throw std::runtime_error(message);
}
}
void Program::bind() const {
ASSERT(m_program != 0, "Program is not initialized");
glUseProgram(m_program);
}
void Program::unbind() const {
glUseProgram(0);
}
std::optional<Uniform> Program::uniform(const std::string& name) const {
ASSERT(m_program != 0, "Program is not initialized");
auto index = glGetUniformLocation(m_program, name.c_str());
if (index == -1) return {};
return {{name, static_cast<U32>(index)}};
}
U32 Program::get() const {
return m_program;
}
}
|