-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRenderer.h
322 lines (290 loc) · 11 KB
/
Renderer.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
#ifndef RENDERER_H
#define RENDERER_H
#include <SDL.h>
/*We need this weirdo define for the core profile gl3 stuff to work*/
#define GL_GLEXT_PROTOTYPES 1
#include <SDL2/SDL_opengl.h>
#include "Mat4.h"
#include <vector>
#include "Shader.h"
#include "Light.h"
class Renderer
{
private:
enum vaoIds {TRIANGLES, NUM_VAOS};
enum bufferIds {ARRAY_BUFFER, NUM_BUFFERS};
enum indexIds {INDEXS, NUM_INDEXS};
enum texIds {TEXTURE, NUM_TEXTURES};
GLint vPosition;
GLint vColour;
GLint vNormal;
GLuint vertArrays[NUM_VAOS];
GLuint buffers[NUM_BUFFERS];
GLuint ibo[NUM_INDEXS];
//GLuint textures[NUM_TEXTURES];
float mf_width;
float mf_height;
float mf_aspectRatio;
float mf_fov;
float mf_near;
float mf_far;
GLint projMatLocation;
GLint modelMatLocation;
GLint cameraMatLocation;
GLint camPositionLocation;
GLint textureLocation;
GLint normalMapLocation;
GLint numEnabledLightsLocation;
GLint program;
GLint maxTextureUnits;
const static int numUniforms = 180;
/*const char *shaderUniforms[numUniforms] = {
"isEnabled",
"enableDiffuse",
"enableSpecular",
"isSpotlight",
"isPointlight",
"specularMode",
"ambientLight",
"diffuseLight",
"specularLight",
"shininess",
"strength",
"position",
"normal",
"angle",
"linearAtten",
"quadAtten",
"constAtten",
"spotponent"
};*/
const char *shaderUniforms[numUniforms] = {
"lights[0].isEnabled",
"lights[0].enableDiffuse",
"lights[0].enableSpecular",
"lights[0].isSpotlight",
"lights[0].isPointlight",
"lights[0].specularMode",
"lights[0].ambientLight",
"lights[0].diffuseLight",
"lights[0].specularLight",
"lights[0].shininess",
"lights[0].strength",
"lights[0].position",
"lights[0].normal",
"lights[0].angle",
"lights[0].linearAtten",
"lights[0].quadAtten",
"lights[0].constAtten",
"lights[0].spotponent",
"lights[1].isEnabled",
"lights[1].enableDiffuse",
"lights[1].enableSpecular",
"lights[1].isSpotlight",
"lights[1].isPointlight",
"lights[1].specularMode",
"lights[1].ambientLight",
"lights[1].diffuseLight",
"lights[1].specularLight",
"lights[1].shininess",
"lights[1].strength",
"lights[1].position",
"lights[1].normal",
"lights[1].angle",
"lights[1].linearAtten",
"lights[1].quadAtten",
"lights[1].constAtten",
"lights[1].spotponent",
"lights[2].isEnabled",
"lights[2].enableDiffuse",
"lights[2].enableSpecular",
"lights[2].isSpotlight",
"lights[2].isPointlight",
"lights[2].specularMode",
"lights[2].ambientLight",
"lights[2].diffuseLight",
"lights[2].specularLight",
"lights[2].shininess",
"lights[2].strength",
"lights[2].position",
"lights[2].normal",
"lights[2].angle",
"lights[2].linearAtten",
"lights[2].quadAtten",
"lights[2].constAtten",
"lights[2].spotponent",
"lights[3].isEnabled",
"lights[3].enableDiffuse",
"lights[3].enableSpecular",
"lights[3].isSpotlight",
"lights[3].isPointlight",
"lights[3].specularMode",
"lights[3].ambientLight",
"lights[3].diffuseLight",
"lights[3].specularLight",
"lights[3].shininess",
"lights[3].strength",
"lights[3].position",
"lights[3].normal",
"lights[3].angle",
"lights[3].linearAtten",
"lights[3].quadAtten",
"lights[3].constAtten",
"lights[3].spotponent",
"lights[4].isEnabled",
"lights[4].enableDiffuse",
"lights[4].enableSpecular",
"lights[4].isSpotlight",
"lights[4].isPointlight",
"lights[4].specularMode",
"lights[4].ambientLight",
"lights[4].diffuseLight",
"lights[4].specularLight",
"lights[4].shininess",
"lights[4].strength",
"lights[4].position",
"lights[4].normal",
"lights[4].angle",
"lights[4].linearAtten",
"lights[4].quadAtten",
"lights[4].constAtten",
"lights[4].spotponent",
"lights[5].isEnabled",
"lights[5].enableDiffuse",
"lights[5].enableSpecular",
"lights[5].isSpotlight",
"lights[5].isPointlight",
"lights[5].specularMode",
"lights[5].ambientLight",
"lights[5].diffuseLight",
"lights[5].specularLight",
"lights[5].shininess",
"lights[5].strength",
"lights[5].position",
"lights[5].normal",
"lights[5].angle",
"lights[5].linearAtten",
"lights[5].quadAtten",
"lights[5].constAtten",
"lights[5].spotponent",
"lights[6].isEnabled",
"lights[6].enableDiffuse",
"lights[6].enableSpecular",
"lights[6].isSpotlight",
"lights[6].isPointlight",
"lights[6].specularMode",
"lights[6].ambientLight",
"lights[6].diffuseLight",
"lights[6].specularLight",
"lights[6].shininess",
"lights[6].strength",
"lights[6].position",
"lights[6].normal",
"lights[6].angle",
"lights[6].linearAtten",
"lights[6].quadAtten",
"lights[6].constAtten",
"lights[6].spotponent",
"lights[7].isEnabled",
"lights[7].enableDiffuse",
"lights[7].enableSpecular",
"lights[7].isSpotlight",
"lights[7].isPointlight",
"lights[7].specularMode",
"lights[7].ambientLight",
"lights[7].diffuseLight",
"lights[7].specularLight",
"lights[7].shininess",
"lights[7].strength",
"lights[7].position",
"lights[7].normal",
"lights[7].angle",
"lights[7].linearAtten",
"lights[7].quadAtten",
"lights[7].constAtten",
"lights[7].spotponent",
"lights[8].isEnabled",
"lights[8].enableDiffuse",
"lights[8].enableSpecular",
"lights[8].isSpotlight",
"lights[8].isPointlight",
"lights[8].specularMode",
"lights[8].ambientLight",
"lights[8].diffuseLight",
"lights[8].specularLight",
"lights[8].shininess",
"lights[8].strength",
"lights[8].position",
"lights[8].normal",
"lights[8].angle",
"lights[8].linearAtten",
"lights[8].quadAtten",
"lights[8].constAtten",
"lights[8].spotponent",
"lights[9].isEnabled",
"lights[9].enableDiffuse",
"lights[9].enableSpecular",
"lights[9].isSpotlight",
"lights[9].isPointlight",
"lights[9].specularMode",
"lights[9].ambientLight",
"lights[9].diffuseLight",
"lights[9].specularLight",
"lights[9].shininess",
"lights[9].strength",
"lights[9].position",
"lights[9].normal",
"lights[9].angle",
"lights[9].linearAtten",
"lights[9].quadAtten",
"lights[9].constAtten",
"lights[9].spotponent",
};
const static int MAX_LIGHTS = 10;
GLuint uboIndex;
GLint uboSize;
GLuint ubo;
GLuint uboStride;
//GLvoid *buffer; //We need to store the uniform structure in our application then upload it to gfx....
GLuint uniformIndices[numUniforms];
GLint uniformSizes[numUniforms];
GLint uniformOffsets[numUniforms];
GLint uniformType[numUniforms];
GLint uniformStrides[numUniforms];
int triangleCount;
Mat4<float> modelMatrix;
Mat4<float> projectionMatrix;
Mat4<float> cameraMatrix;
Vec4<float> camPosition;
Mat4<float> frustumProjection(float left, float right, float top, float bottom, float near, float far);
Mat4<float> perspectiveProjection(float FOV, float aspectRatio, float near, float far);
std::string title;
SDL_Window *window = NULL;
SDL_GLContext context = NULL;
std::vector<GLuint> textures;
public:
Renderer();
Renderer(float width, float height);
Renderer(float width, float height, float near, float far, float fov);
bool initSDL();
void initGL(std::vector<struct ShaderList> list);
void cleanup();
void setWindowTitle(std::string title);
GLint loadProgram(std::vector<struct ShaderList> list);
void useProgram(GLint program);
void setProjectionMatrix(Mat4<float> projMat);
void setNumEnabledLights(int count);
void setTriangleCount(float triangles);
Light newLight(int i);
void updateCameraMatrix(Mat4<float> camMat);
void updateModelMatrix(Mat4<float> modMat);
void updateCameraPosition(Vec4<float> camDir);
void updateLight(Light updatedLight);
void updateLights(std::vector<Light> lights);
void draw();
void loadPrimitiveData(float *vertices, size_t vcount, unsigned short *indices, size_t icount, float *colour, size_t ccount, size_t tsize, float *texCoords, float *normals, size_t nsize);
void loadTexture(char *name);
void loadTest();
const int getMaxLights();
};
#endif