summary refs log tree commit diff
path: root/src/GFX/Shading/Shader.cpp
blob: 54f8ad117fcb8bea1a40767944e6904ff816cfa4 (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
#include <GL/glew.h>
#include <stdexcept>
#include "Shader.hpp"

namespace MC::GFX::Shading {

Shader::Shader(Type type, const Char* source) {
    U32 gl_type = 0;
    switch (type) {
        case Type::Vertex:
            gl_type = GL_VERTEX_SHADER;
            break;
        case Type::Fragment:
            gl_type = GL_FRAGMENT_SHADER;
            break;
    }

    m_shader = glCreateShader(gl_type);

    glShaderSource(m_shader, 1, &source, nullptr);
    glCompileShader(m_shader);

    GLint success;
    glGetShaderiv(m_shader, GL_COMPILE_STATUS, &success);
    if(!success) {
        Char message[512] = {};
        glGetShaderInfoLog(m_shader, 512, nullptr, message);

        throw std::runtime_error(message);
    }
}


}