-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathShader.hpp
More file actions
44 lines (35 loc) · 951 Bytes
/
Shader.hpp
File metadata and controls
44 lines (35 loc) · 951 Bytes
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
#pragma once
#include "GLAD/glad.h"
#include <fstream>
#include <sstream>
#include <iostream>
struct Shader
{
GLuint Index = 0;
Shader(GLenum type)
{
Index = glCreateShader(type);
}
void Source(std::string shaderFilePath)
{
// TODO: make a proper file system
std::ifstream ShaderFile(shaderFilePath);
std::stringstream Buffer;
Buffer << ShaderFile.rdbuf();
auto ShaderScript = Buffer.str();
auto ShaderScriptC = ShaderScript.c_str();
glShaderSource(Index, 1, &ShaderScriptC, 0);
}
void Compile()
{
glCompileShader(Index);
int Success = 0;
glGetShaderiv(Index, GL_COMPILE_STATUS, &Success);
if (!Success)
{
char InfoLog[512] { 0 };
glGetShaderInfoLog(Index, 512, NULL, InfoLog);
std::cout << "Shader Compilation Failed: " << InfoLog << std::endl;
};
}
};