-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathShaderProgram.h
executable file
·57 lines (54 loc) · 1.66 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
54
55
56
57
#pragma once
#include <GL/glew.h>
#include <glm/glm.hpp>
#include "Shader.h"
#include "Frame.h"
#include <initializer_list>
#include <vector>
#include <string>
#include <map>
class ShaderProgram
{
public:
struct Uniform
{
const ShaderProgram *program;
GLint Location;
std::string Name;
Uniform& operator=(glm::vec2 value);
Uniform& operator=(glm::vec3 value);
Uniform& operator=(glm::vec4 value);
Uniform& operator=(glm::mat3 value);
Uniform& operator=(glm::mat4 value);
Uniform& operator=(const std::vector<glm::vec2>& values);
Uniform& operator=(const std::vector<glm::vec3>& values);
Uniform& operator=(const std::vector<glm::vec4>& values);
Uniform& operator=(const std::vector<glm::mat3>& values);
Uniform& operator=(const std::vector<glm::mat4>& values);
Uniform& operator=(GLfloat value);
Uniform& operator=(GLint value);
void warn(GLenum sym, std::string keyword, int num = 1);
};
GLuint program;
ShaderProgram();
ShaderProgram(std::initializer_list<std::string> paths);
ShaderProgram(std::vector<Shader *>& shaders);
~ShaderProgram();
ShaderProgram(const ShaderProgram&) = delete;
ShaderProgram& operator=(const ShaderProgram&) = delete;
ShaderProgram(ShaderProgram&& other);
ShaderProgram& operator=(ShaderProgram&& other);
void LinkProgram(std::vector<Shader *> &shaders);
GLint GetUniformLocation(std::string name) const;
void DrawFrame(Frame *frame, glm::mat4 mvMatrix) const;
Uniform operator[](std::string name) const;
template<class Fn>
void Use(Fn func) const
{
GLint name;
glGetIntegerv(GL_CURRENT_PROGRAM, &name);
glUseProgram(program);
func();
glUseProgram(name);
}
};