-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVertexSpecification.hpp
119 lines (110 loc) · 4.52 KB
/
VertexSpecification.hpp
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Copyright Ptolom 2022
// This file is part of Trophic.
//
// Trophic is free software: you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the Free Software
// Foundation, either version 3 of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with this
// program. If not, see <https://www.gnu.org/licenses/>.
#include<glm/glm.hpp>
#include "metafunction.hpp"
#include<GL/gl.h>
template<typename T>
constexpr GLenum GLType;
template<>
constexpr GLenum GLType<float> = GL_FLOAT;
template<>
constexpr GLenum GLType<double> = GL_DOUBLE;
template<>
constexpr GLenum GLType<int> = GL_INT;
template<>
constexpr GLenum GLType<unsigned int> = GL_UNSIGNED_INT;
template<>
constexpr GLenum GLType<GLboolean> = GL_BOOL;
template<GLenum format>
void attribFormat(GLuint vao, GLuint attribIndex, GLint size, GLenum type,
GLboolean normalized, GLuint offset);
template<>
void attribFormat<GL_INT>(GLuint vao, GLuint attribIndex, GLint size, GLenum type,
GLboolean normalized, GLuint offset)
{
glVertexArrayAttribFormat(vao, attribIndex, size, type, normalized, offset);
}
template<>
void attribFormat<GL_FLOAT>(GLuint vao, GLuint attribIndex, GLint size, GLenum type,
GLboolean normalized, GLuint offset)
{
glVertexArrayAttribFormat(vao, attribIndex, size, type, normalized, offset);
}
template<>
void attribFormat<GL_DOUBLE>(GLuint vao, GLuint attribIndex, GLint size, GLenum type,
GLboolean normalized, GLuint offset)
{
glVertexArrayAttribLFormat(vao, attribIndex, size, type, offset);
}
template<typename Type, GLenum format, GLboolean normalized=false>
struct attribute {
using value=Type;
};
template<typename... Attrs>
struct attributes {
using types = meta::concat<Attrs...>::value;
attributes(GLuint vao) : value(vao) {}
private:
template<GLuint attribIndex, GLuint offset, typename... As>
struct attributes_ { attributes_(GLuint vao) {} };
template<GLuint attribIndex, GLuint offset,
glm::length_t L, typename T, glm::qualifier Q, GLenum format, GLboolean normalized, typename... As>
struct attributes_<attribIndex, offset,
attribute<glm::vec<L,T,Q>, format, normalized>, As...> {
attributes_(GLuint vao) : a(vao)
{
glEnableVertexArrayAttrib(vao, attribIndex);
attribFormat<format>(vao, attribIndex, L, GLType<T>, normalized, offset);
glVertexArrayAttribBinding(vao,attribIndex,0);
}
attributes_<attribIndex+1, offset+sizeof(glm::vec<L,T,Q>), As...> a;
};
template<GLuint attribIndex, GLuint offset,
glm::length_t R, typename T, glm::qualifier Q,
GLenum format, GLboolean normalized, typename... As>
struct attributes_<attribIndex,offset,
attribute<glm::mat<1,R,T,Q>, format, normalized>, As...> {
attributes_(GLuint vao) : a(vao) {}
using Vec=attribute<glm::vec<R,T,Q>, format, normalized>;
attributes_<attribIndex, offset, Vec, As...> a;
};
template<GLuint attribIndex, GLuint offset,
glm::length_t R, typename T, glm::qualifier Q,
GLenum format, GLboolean normalized, typename... As>
struct attributes_<attribIndex,offset,
attribute<glm::mat<2,R,T,Q>, format, normalized>, As...> {
attributes_(GLuint vao) : a(vao) {}
using Vec=attribute<glm::vec<R,T,Q>, format, normalized>;
attributes_<attribIndex, offset, Vec, Vec, As...> a;
};
template<GLuint attribIndex, GLuint offset,
glm::length_t R, typename T, glm::qualifier Q,
GLenum format, GLboolean normalized, typename... As>
struct attributes_<attribIndex,offset,
attribute<glm::mat<3,R,T,Q>, format, normalized>, As...> {
attributes_(GLuint vao) : a(vao) {}
using Vec=attribute<glm::vec<R,T,Q>, format, normalized>;
attributes_<attribIndex, offset, Vec, Vec, Vec, As...> a;
};
template<GLuint attribIndex, GLuint offset,
glm::length_t R, typename T, glm::qualifier Q,
GLenum format, GLboolean normalized, typename... As>
struct attributes_<attribIndex,offset,
attribute<glm::mat<4,R,T,Q>, format, normalized>, As...> {
attributes_(GLuint vao) : a(vao) {}
using Vec=attribute<glm::vec<R,T,Q>, format>;
attributes_<attribIndex, offset, Vec, Vec, Vec, Vec, As...> a;
};
attributes_<0,0,Attrs...> value;
};