-
Notifications
You must be signed in to change notification settings - Fork 0
/
asstcommon.h
68 lines (52 loc) · 1.82 KB
/
asstcommon.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
#ifndef ASSTCOMMON_H
#define ASSTCOMMON_H
#include <cstddef>
#include <vector>
#include <memory>
#include <stdexcept>
#if __GNUG__
# include <tr1/memory>
#endif
#include "glsupport.h"
#include "matrix4.h"
extern const bool g_Gl2Compatible;
struct ShaderState {
GlProgram program;
// Handles to uniform variables
GLint h_uLight, h_uLight2;
GLint h_uProjMatrix;
GLint h_uModelViewMatrix;
GLint h_uNormalMatrix;
GLint h_uColor;
GLint h_uIdColor;
// Handles to vertex attributes
GLint h_aPosition;
GLint h_aNormal;
ShaderState(const char* vsfn, const char* fsfn) {
readAndCompileShader(program, vsfn, fsfn);
const GLuint h = program; // short hand
// Retrieve handles to uniform variables
h_uLight = safe_glGetUniformLocation(h, "uLight");
h_uLight2 = safe_glGetUniformLocation(h, "uLight2");
h_uProjMatrix = safe_glGetUniformLocation(h, "uProjMatrix");
h_uModelViewMatrix = safe_glGetUniformLocation(h, "uModelViewMatrix");
h_uNormalMatrix = safe_glGetUniformLocation(h, "uNormalMatrix");
h_uColor = safe_glGetUniformLocation(h, "uColor");
h_uIdColor = safe_glGetUniformLocation(h, "uIdColor");
// Retrieve handles to vertex attributes
h_aPosition = safe_glGetAttribLocation(h, "aPosition");
h_aNormal = safe_glGetAttribLocation(h, "aNormal");
if (!g_Gl2Compatible)
glBindFragDataLocation(h, 0, "fragColor");
checkGlErrors();
}
};
// takes MVM and its normal matrix to the shaders
inline void sendModelViewNormalMatrix(const ShaderState& curSS, const Matrix4& MVM, const Matrix4& NMVM) {
GLfloat glmatrix[16];
MVM.writeToColumnMajorMatrix(glmatrix); // send MVM
safe_glUniformMatrix4fv(curSS.h_uModelViewMatrix, glmatrix);
NMVM.writeToColumnMajorMatrix(glmatrix); // send NMVM
safe_glUniformMatrix4fv(curSS.h_uNormalMatrix, glmatrix);
}
#endif