-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShaderManager.h
54 lines (42 loc) · 1.24 KB
/
ShaderManager.h
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
#pragma once
#include <GL/glew.h>
#include <glm/glm.hpp>
#include <unordered_map>
#include <string>
#include <vector>
struct Shader
{
std::string const name;
std::string const vertexFile;
std::string const fragmentFile;
GLuint programId;
std::unordered_map<std::string, GLuint> uniformLocations;
Shader(std::string _name, std::string vsFile, std::string fsFile) :
name(_name),
vertexFile(vsFile),
fragmentFile(fsFile)
{
}
};
class ShaderManager
{
public:
ShaderManager();
~ShaderManager();
void AddShader(std::string const& name, const char* sVertexFile, const char* sFragmentFile);
void UseShader(std::string const& name);
void SetUniform1i(const char* uniformName, int value);
void SetUniform1f(const char* uniformName, float value);
void SetUniform3f(const char* uniformName, glm::vec3 const& value);
void SetUniformMatrix(const char* uniformName, glm::mat4 const& value);
void Recompile();
GLuint GetProgramID(std::string const& name);
private:
GLuint GetUniformLocation(std::string const& uniformName);
private:
std::unordered_map<std::string, Shader> m_shaderPrograms;
Shader* m_activeShader;
public:
ShaderManager(ShaderManager const&) = delete;
void operator=(ShaderManager const&) = delete;
};