-
Notifications
You must be signed in to change notification settings - Fork 4
/
Shader.h
39 lines (32 loc) · 1.03 KB
/
Shader.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
#ifndef SHADER_H
#define SHADER_H
#include <string>
#include <unordered_map>
#include <glm/glm.hpp>
struct ShaderProgramSource
{
std::string VertexShader;
std::string FragmentShader;
};
class Shader
{
private:
std::string m_FilePath;
unsigned int m_RendererID;
// caching for uniforms
std::unordered_map<std::string, int> m_UniformLocationCache;
public:
Shader(const std::string& filepath);
~Shader();
void Bind() const;
void Unbind() const;
void SetUniform1i(const std::string& name, int value);
void SetUniform4f(const std::string& name, float v0, float v1, float v2, float v3);
void SetUniformMatrix4fv(const std::string& name, const glm::mat4 &matrix);
private:
ShaderProgramSource ParseShader(const std::string& filepath);
unsigned int CompileShader(unsigned int type, const std::string& source);
unsigned int CreateShader(const std::string& vertexShader, const std::string& fragmentShader);
int GetUniformLocation(const std::string& name);
};
#endif // defined(SHADER_H)