-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtility.cpp
More file actions
87 lines (73 loc) · 2.01 KB
/
Utility.cpp
File metadata and controls
87 lines (73 loc) · 2.01 KB
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
#include "Utility.h"
#include "FCT/DebugTools/Android_Out.h"
#include <GLES3/gl3.h>
#define CHECK_ERROR(e) case e: aout << "GL Error: "#e << std::endl; break;
bool Utility::checkAndLogGlError(bool alwaysLog) {
GLenum error = glGetError();
if (error == GL_NO_ERROR) {
if (alwaysLog) {
aout << "No GL error" << std::endl;
}
return true;
} else {
switch (error) {
CHECK_ERROR(GL_INVALID_ENUM);
CHECK_ERROR(GL_INVALID_VALUE);
CHECK_ERROR(GL_INVALID_OPERATION);
CHECK_ERROR(GL_INVALID_FRAMEBUFFER_OPERATION);
CHECK_ERROR(GL_OUT_OF_MEMORY);
default:
aout << "Unknown GL error: " << error << std::endl;
}
return false;
}
}
float *
Utility::buildOrthographicMatrix(float *outMatrix, float halfHeight, float aspect, float near,
float far) {
float halfWidth = halfHeight * aspect;
// column 1
outMatrix[0] = 1.f / halfWidth;
outMatrix[1] = 0.f;
outMatrix[2] = 0.f;
outMatrix[3] = 0.f;
// column 2
outMatrix[4] = 0.f;
outMatrix[5] = 1.f / halfHeight;
outMatrix[6] = 0.f;
outMatrix[7] = 0.f;
// column 3
outMatrix[8] = 0.f;
outMatrix[9] = 0.f;
outMatrix[10] = -2.f / (far - near);
outMatrix[11] = -(far + near) / (far - near);
// column 4
outMatrix[12] = 0.f;
outMatrix[13] = 0.f;
outMatrix[14] = 0.f;
outMatrix[15] = 1.f;
return outMatrix;
}
float *Utility::buildIdentityMatrix(float *outMatrix) {
// column 1
outMatrix[0] = 1.f;
outMatrix[1] = 0.f;
outMatrix[2] = 0.f;
outMatrix[3] = 0.f;
// column 2
outMatrix[4] = 0.f;
outMatrix[5] = 1.f;
outMatrix[6] = 0.f;
outMatrix[7] = 0.f;
// column 3
outMatrix[8] = 0.f;
outMatrix[9] = 0.f;
outMatrix[10] = 1.f;
outMatrix[11] = 0.f;
// column 4
outMatrix[12] = 0.f;
outMatrix[13] = 0.f;
outMatrix[14] = 0.f;
outMatrix[15] = 1.f;
return outMatrix;
}