-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathShaderProgram.h
53 lines (46 loc) · 1.42 KB
/
ShaderProgram.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
#ifndef _SHADER_PROGRAM_H_
#define _SHADER_PROGRAM_H_
#include <cstdint>
#include <GL/glew.h>
#include <map>
#include <functional>
#include <glm/glm.hpp>
class UniformVariable
{
public:
UniformVariable();
explicit UniformVariable(GLuint program, GLint id);
UniformVariable(const UniformVariable &rhs)=default;
float operator=(float);
uint32_t operator=(uint32_t);
int32_t operator=(int32_t);
glm::uvec2 operator=(const glm::uvec2 &);
glm::vec2 operator=(const glm::vec2 &);
glm::vec3 operator=(const glm::vec3 &);
glm::mat4 operator=(const glm::mat4 &);
UniformVariable &operator=(const UniformVariable &rhs)=default;
bool valid() const;
private:
GLuint m_program;
GLint m_id;
};
class Program
{
public:
Program()=default;
Program(const Program &)=default;
static Program LoadFromFile(const std::string &filename);
static Program LoadFromFile(const std::string &vs, const std::string &fs);
static Program LoadFromFile(const std::string &vs, const std::string &gs, const std::string &fs);
UniformVariable &operator[](const std::string &);
bool valid() const;
void use() const;
void dispatchCompute(uint32_t x, uint32_t y, uint32_t z) const;
void release();
private:
static GLuint CreateShader(GLenum type, const std::string &src);
Program(GLuint prog);
std::map<std::string, UniformVariable> m_uniformVariables;
GLuint m_program;
};
#endif