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