Browse code

Add uniform GLM

Robert Cranston authored on 16/05/2020 10:39:49
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,73 @@
1
+#ifndef GLSHADER_GLM_HPP_
2
+#define GLSHADER_GLM_HPP_
3
+
4
+
5
+#include <GL/glew.h>
6
+
7
+#include <glm/glm.hpp>
8
+#include <glm/gtc/type_ptr.hpp>
9
+
10
+#include <glshader.hpp>
11
+
12
+
13
+#define GLSHADER_UNIFORM_GLM_N_(N, GLM_TYPE, SUFFIX) \
14
+    GLSHADER_UNIFORM( \
15
+        glm::GLM_TYPE##N, \
16
+        glUniform##N##SUFFIX##v( \
17
+            location, 1, glm::value_ptr(value) \
18
+        ); \
19
+    )
20
+
21
+#define GLSHADER_UNIFORM_GLM_N_BOOL_(N) \
22
+    GLSHADER_UNIFORM( \
23
+        glm::bvec##N, \
24
+        GLint int_value[N]; \
25
+        for (auto i = 0; i < N; ++i) \
26
+            int_value[i] = value[i]; \
27
+        glUniform##N##iv( \
28
+            location, 1, &int_value[0] \
29
+        ); \
30
+    )
31
+
32
+#define GLSHADER_UNIFORM_GLM_MATRIX_N_(N) \
33
+    GLSHADER_UNIFORM( \
34
+        glm::mat##N, \
35
+        glUniformMatrix##N##fv( \
36
+            location, 1, GL_FALSE, glm::value_ptr(value) \
37
+        ); \
38
+    )
39
+
40
+#define GLSHADER_UNIFORM_GLM_MATRIX_N_M_(N, M) \
41
+    GLSHADER_UNIFORM( \
42
+        glm::mat##N##x##M, \
43
+        glUniformMatrix##N##x##M##fv( \
44
+            location, 1, GL_FALSE, glm::value_ptr(value) \
45
+        ); \
46
+    )
47
+
48
+GLSHADER_UNIFORM_GLM_N_BOOL_(2)
49
+GLSHADER_UNIFORM_GLM_N_BOOL_(3)
50
+GLSHADER_UNIFORM_GLM_N_BOOL_(4)
51
+GLSHADER_UNIFORM_GLM_N_(2, ivec, i)
52
+GLSHADER_UNIFORM_GLM_N_(3, ivec, i)
53
+GLSHADER_UNIFORM_GLM_N_(4, ivec, i)
54
+GLSHADER_UNIFORM_GLM_N_(2, uvec, ui)
55
+GLSHADER_UNIFORM_GLM_N_(3, uvec, ui)
56
+GLSHADER_UNIFORM_GLM_N_(4, uvec, ui)
57
+GLSHADER_UNIFORM_GLM_N_(2, vec, f)
58
+GLSHADER_UNIFORM_GLM_N_(3, vec, f)
59
+GLSHADER_UNIFORM_GLM_N_(4, vec, f)
60
+
61
+GLSHADER_UNIFORM_GLM_MATRIX_N_(2)
62
+GLSHADER_UNIFORM_GLM_MATRIX_N_(3)
63
+GLSHADER_UNIFORM_GLM_MATRIX_N_(4)
64
+
65
+GLSHADER_UNIFORM_GLM_MATRIX_N_M_(2, 3)
66
+GLSHADER_UNIFORM_GLM_MATRIX_N_M_(2, 4)
67
+GLSHADER_UNIFORM_GLM_MATRIX_N_M_(3, 2)
68
+GLSHADER_UNIFORM_GLM_MATRIX_N_M_(3, 4)
69
+GLSHADER_UNIFORM_GLM_MATRIX_N_M_(4, 2)
70
+GLSHADER_UNIFORM_GLM_MATRIX_N_M_(4, 3)
71
+
72
+
73
+#endif // GLSHADER_GLM_HPP_