-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathShader.h
executable file
·164 lines (142 loc) · 4.14 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#pragma once
#include "opengl.h"
#include <string>
#include <array>
class Shader {
private:
/**
* OpenGL reference to the vertex shader
*/
GLuint vertexShader;
/**
* OpenGL reference to the fragment shader
*/
GLuint fragmentShader;
/**
* OpenGL reference to the program
*/
GLuint program;
// Basic uniform locations
std::array<GLint, 5> parameters;
/**
* Create vertexShader and fragmentShader, add load the given files
*
* \param vsPath Path to the vertex shader file
* \param fsPath Path to the fragment shader file
*/
void createShaders(const std::string& vsPath,
const std::string& fsPath);
/**
* Compile the previously initilaized shaders
*
* Should be used after createShaders
*
* \param vsPath Path to the vertex shader
* \param fsPath Path to the fragment shader
*/
void compileShaders(const std::string& vsPath,
const std::string& fsPath);
/**
* Create the program and attach the shaders
*
* Should be used after compileShaders
*
* \param vsPath Path to the vertex shader
* \param fsPath Path to the fragment shader
*/
void createProgram(const std::string& vsPath,
const std::string& fsPath);
/**
* Link the program
*
* Should be used after createProgram
*
* \param vsPath Path to the vertex shader
* \param fsPath Path to the fragment shader
*/
void linkProgram(const std::string& vsPath,
const std::string& fsPath);
/**
* get the basic uniforms location (Ka, Kd, Ks, Ns, d)
*/
void getBasicUniformsLocation();
/**
* get the txt file content
*
* \param filePath Path to the file
*
* \return A malloced string with the content of the file
*/
char* loadFileASCII(const std::string& filePath);
public:
typedef enum
{
Ka = 0,
Kd = 3,
Ks = 6,
Ns = 9,
d = 10,
} uniforms;
/**
* Default constructor, valid but useless state
*/
Shader();
/**
* Copy constructor
*
* \param shader Shader to copy from
*/
Shader(const Shader& shader);
/**
* Move constructor
*
* \param shader Shader to move from, which should be left in
* an useless but valid state
*
* \todo Actually, doing nothing more than the copy constructor
*/
Shader(Shader&& shader);
/**
* Construct a Shader with the given path to the vs and fs
*
* \param vsPath Path to the vertex shader file
* \param fsPath Path to the fragment shader file
*/
Shader(const std::string& vsPath,
const std::string& fsPath);
/**
* Use the shader's program
*/
void use() const;
/**
* Give a way to sort Shaders, less operator
*
* \param b Shader to compare to
*
* \return True if the sum of the vs and fs is less than the one of b
*/
bool operator<(const Shader &b) const;
/**
* set the specified basic uniform variable float value
*
* \param uniform the uniform variable to set
* \param value the value
*/
void setUniformValue(Shader::uniforms uniform, float value);
/**
* set the specified basic uniform variable vec3 value
*
* \param uniform the uniform variable to set
* \param v1 the value of vec3.x
* \param v2 the value of vec3.y
* \param v3 the value of vec3.z
*/
void setUniformValue(Shader::uniforms uniform,
float v1, float v2, float v3);
/**
* set all basic uniform variables values
*
* \param values the values in this order (Ka, Kd, Ks, Ns, d)
*/
void setUniformValue(std::array<float, 11> values);
};