]> git.localhorst.tv Git - blobs.git/blob - src/graphics/gl_traits.hpp
a399893a17ab6c363c05c75bdc2380f5999f7a38
[blobs.git] / src / graphics / gl_traits.hpp
1 #ifndef BLOBS_GRAPHICS_GL_TRAITS_HPP_
2 #define BLOBS_GRAPHICS_GL_TRAITS_HPP_
3
4 #include "glm.hpp"
5
6 #include <GL/glew.h>
7
8
9 namespace blobs {
10 namespace graphics {
11
12 template<class T>
13 struct gl_traits {
14
15         /// number of components per generic attribute
16         /// must be 1, 2, 3, 4
17         // static constexpr GLint size;
18
19         /// component type
20         /// accepted values are:
21         ///   GL_BYTE, GL_UNSIGNED_BYTE,
22         ///   GL_SHORT, GL_UNSIGNED_SHORT,
23         ///   GL_INT, GL_UNSIGNED_INT,
24         ///   GL_HALF_FLOAT, GL_FLOAT, GL_DOUBLE,
25         ///   GL_FIXED, GL_INT_2_10_10_10_REV, GL_UNSIGNED_INT_2_10_10_10_REV
26         // static constexpr GLenum type;
27
28 };
29
30
31 // basic types
32
33 template<> struct gl_traits<signed char> {
34         static constexpr GLint size = 1;
35         static constexpr GLenum type = GL_BYTE;
36 };
37
38 template<> struct gl_traits<unsigned char> {
39         static constexpr GLint size = 1;
40         static constexpr GLenum type = GL_UNSIGNED_BYTE;
41 };
42
43 template<> struct gl_traits<short> {
44         static constexpr GLint size = 1;
45         static constexpr GLenum type = GL_SHORT;
46 };
47
48 template<> struct gl_traits<unsigned short> {
49         static constexpr GLint size = 1;
50         static constexpr GLenum type = GL_UNSIGNED_SHORT;
51 };
52
53 template<> struct gl_traits<int> {
54         static constexpr GLint size = 1;
55         static constexpr GLenum type = GL_INT;
56 };
57
58 template<> struct gl_traits<unsigned int> {
59         static constexpr GLint size = 1;
60         static constexpr GLenum type = GL_UNSIGNED_INT;
61 };
62
63 template<> struct gl_traits<float> {
64         static constexpr GLint size = 1;
65         static constexpr GLenum type = GL_FLOAT;
66 };
67
68 template<> struct gl_traits<double> {
69         static constexpr GLint size = 1;
70         static constexpr GLenum type = GL_DOUBLE;
71 };
72
73 // composite types
74
75 template<>
76 template<class T, glm::precision P>
77 struct gl_traits<glm::tvec1<T, P>> {
78         static constexpr GLint size = 1;
79         static constexpr GLenum type = gl_traits<T>::type;
80 };
81 template<class T, glm::precision P>
82 constexpr GLint gl_traits<glm::tvec1<T, P>>::size;
83 template<class T, glm::precision P>
84 constexpr GLenum gl_traits<glm::tvec1<T, P>>::type;
85
86 template<>
87 template<class T, glm::precision P>
88 struct gl_traits<glm::tvec2<T, P>> {
89         static constexpr GLint size = 2;
90         static constexpr GLenum type = gl_traits<T>::type;
91 };
92 template<class T, glm::precision P>
93 constexpr GLint gl_traits<glm::tvec2<T, P>>::size;
94 template<class T, glm::precision P>
95 constexpr GLenum gl_traits<glm::tvec2<T, P>>::type;
96
97 template<>
98 template<class T, glm::precision P>
99 struct gl_traits<glm::tvec3<T, P>> {
100         static constexpr GLint size = 3;
101         static constexpr GLenum type = gl_traits<T>::type;
102 };
103 template<class T, glm::precision P>
104 constexpr GLint gl_traits<glm::tvec3<T, P>>::size;
105 template<class T, glm::precision P>
106 constexpr GLenum gl_traits<glm::tvec3<T, P>>::type;
107
108 template<>
109 template<class T, glm::precision P>
110 struct gl_traits<glm::tvec4<T, P>> {
111         static constexpr GLint size = 4;
112         static constexpr GLenum type = gl_traits<T>::type;
113 };
114 template<class T, glm::precision P>
115 constexpr GLint gl_traits<glm::tvec4<T, P>>::size;
116 template<class T, glm::precision P>
117 constexpr GLenum gl_traits<glm::tvec4<T, P>>::type;
118
119 }
120 }
121
122 #endif