... | ... |
@@ -113,24 +113,25 @@ struct GLTraitsTest : protected GLBase |
113 | 113 |
template< |
114 | 114 |
typename T, |
115 | 115 |
typename Value, |
116 |
- typename... Values |
|
116 |
+ std::size_t offset, |
|
117 |
+ typename... Members |
|
117 | 118 |
> |
118 | 119 |
void static test_members( |
119 |
- GLTraits::Members<T, Value, Values...>, |
|
120 |
- std::size_t offset = 0 |
|
120 |
+ GLTraits::Members<T, GLTraits::Member<Value, offset>, Members...> |
|
121 | 121 |
) |
122 | 122 |
{ |
123 |
- auto unaligned = offset % alignof(Value); |
|
124 |
- if (unaligned) |
|
125 |
- offset += alignof(Value) - unaligned; |
|
126 |
- auto end = offset + sizeof(Value); |
|
123 |
+ auto constexpr end = offset + sizeof(Value); |
|
127 | 124 |
using Traits = GLTraits::Value<Value>; |
128 | 125 |
static_assert( |
129 | 126 |
std::is_empty<GLTraits::Members< |
130 |
- T, Value, Values... |
|
127 |
+ T, GLTraits::Member<Value, offset>, Members... |
|
131 | 128 |
>>::value, |
132 | 129 |
"GLTraits::Members must be empty" |
133 | 130 |
); |
131 |
+ static_assert( |
|
132 |
+ std::is_empty<GLTraits::Member<Value, offset>>::value, |
|
133 |
+ "GLTraits::Member must be empty" |
|
134 |
+ ); |
|
134 | 135 |
#define GLTRAITS_TEST_MEMBERS(IND, NAME, OFFSET, END) \ |
135 | 136 |
std::cout \ |
136 | 137 |
<< std::left << std::setw(IND) << "" \ |
... | ... |
@@ -138,10 +139,10 @@ struct GLTraitsTest : protected GLBase |
138 | 139 |
<< std::right << std::setw(2) << std::dec << OFFSET << " " \ |
139 | 140 |
<< std::right << std::setw(3) << std::dec << END << "\n"; |
140 | 141 |
GLTRAITS_TEST_MEMBERS(2, Traits::name, offset, end) |
141 |
- test_members(GLTraits::Members<T, Values...>{}, end); |
|
142 |
+ test_members(GLTraits::Members<T, Members...>{}); |
|
142 | 143 |
} |
143 | 144 |
template<typename T> |
144 |
- void static test_members(GLTraits::Members<T>, std::size_t) |
|
145 |
+ void static test_members(GLTraits::Members<T>) |
|
145 | 146 |
{} |
146 | 147 |
#endif |
147 | 148 |
|
... | ... |
@@ -111,11 +111,12 @@ struct GLTraitsTest : protected GLBase |
111 | 111 |
|
112 | 112 |
#if __cplusplus >= 201402L |
113 | 113 |
template< |
114 |
+ typename T, |
|
114 | 115 |
typename Value, |
115 | 116 |
typename... Values |
116 | 117 |
> |
117 | 118 |
void static test_members( |
118 |
- GLTraits::Members<Value, Values...>, |
|
119 |
+ GLTraits::Members<T, Value, Values...>, |
|
119 | 120 |
std::size_t offset = 0 |
120 | 121 |
) |
121 | 122 |
{ |
... | ... |
@@ -126,7 +127,7 @@ struct GLTraitsTest : protected GLBase |
126 | 127 |
using Traits = GLTraits::Value<Value>; |
127 | 128 |
static_assert( |
128 | 129 |
std::is_empty<GLTraits::Members< |
129 |
- Value, Values... |
|
130 |
+ T, Value, Values... |
|
130 | 131 |
>>::value, |
131 | 132 |
"GLTraits::Members must be empty" |
132 | 133 |
); |
... | ... |
@@ -137,9 +138,10 @@ struct GLTraitsTest : protected GLBase |
137 | 138 |
<< std::right << std::setw(2) << std::dec << OFFSET << " " \ |
138 | 139 |
<< std::right << std::setw(3) << std::dec << END << "\n"; |
139 | 140 |
GLTRAITS_TEST_MEMBERS(2, Traits::name, offset, end) |
140 |
- test_members(GLTraits::Members<Values...>{}, end); |
|
141 |
+ test_members(GLTraits::Members<T, Values...>{}, end); |
|
141 | 142 |
} |
142 |
- void static test_members(GLTraits::Members<>, std::size_t) |
|
143 |
+ template<typename T> |
|
144 |
+ void static test_members(GLTraits::Members<T>, std::size_t) |
|
143 | 145 |
{} |
144 | 146 |
#endif |
145 | 147 |
|
... | ... |
@@ -1,3 +1,4 @@ |
1 |
+#include <cstddef> |
|
1 | 2 |
#include <iomanip> |
2 | 3 |
#include <iostream> |
3 | 4 |
#include <string> |
... | ... |
@@ -108,6 +109,40 @@ struct GLTraitsTest : protected GLBase |
108 | 109 |
GLTRAITS_TEST_TEXTURE(compressed_texture_sub_image); |
109 | 110 |
} |
110 | 111 |
|
112 |
+ #if __cplusplus >= 201402L |
|
113 |
+ template< |
|
114 |
+ typename Value, |
|
115 |
+ typename... Values |
|
116 |
+ > |
|
117 |
+ void static test_members( |
|
118 |
+ GLTraits::Members<Value, Values...>, |
|
119 |
+ std::size_t offset = 0 |
|
120 |
+ ) |
|
121 |
+ { |
|
122 |
+ auto unaligned = offset % alignof(Value); |
|
123 |
+ if (unaligned) |
|
124 |
+ offset += alignof(Value) - unaligned; |
|
125 |
+ auto end = offset + sizeof(Value); |
|
126 |
+ using Traits = GLTraits::Value<Value>; |
|
127 |
+ static_assert( |
|
128 |
+ std::is_empty<GLTraits::Members< |
|
129 |
+ Value, Values... |
|
130 |
+ >>::value, |
|
131 |
+ "GLTraits::Members must be empty" |
|
132 |
+ ); |
|
133 |
+ #define GLTRAITS_TEST_MEMBERS(IND, NAME, OFFSET, END) \ |
|
134 |
+ std::cout \ |
|
135 |
+ << std::left << std::setw(IND) << "" \ |
|
136 |
+ << std::left << std::setw(12 - IND) << NAME << " " \ |
|
137 |
+ << std::right << std::setw(2) << std::dec << OFFSET << " " \ |
|
138 |
+ << std::right << std::setw(3) << std::dec << END << "\n"; |
|
139 |
+ GLTRAITS_TEST_MEMBERS(2, Traits::name, offset, end) |
|
140 |
+ test_members(GLTraits::Members<Values...>{}, end); |
|
141 |
+ } |
|
142 |
+ void static test_members(GLTraits::Members<>, std::size_t) |
|
143 |
+ {} |
|
144 |
+ #endif |
|
145 |
+ |
|
111 | 146 |
}; |
112 | 147 |
|
113 | 148 |
|
... | ... |
@@ -135,4 +170,36 @@ int main() |
135 | 170 |
GLTraitsTest::test_texture<1>(); |
136 | 171 |
GLTraitsTest::test_texture<2>(); |
137 | 172 |
GLTraitsTest::test_texture<3>(); |
173 |
+ |
|
174 |
+ #if __cplusplus >= 201402L |
|
175 |
+ struct Vertex |
|
176 |
+ { |
|
177 |
+ glm::vec3 position; |
|
178 |
+ glm::vec2 tex_coord; |
|
179 |
+ glm::mat3 tbn; |
|
180 |
+ glm::ivec4 bone_indices; |
|
181 |
+ glm::vec4 bone_weights; |
|
182 |
+ GLubyte flags; |
|
183 |
+ GLdouble unaligned; |
|
184 |
+ }; |
|
185 |
+ #define GLTRAITS_TEST_MEMBERS_T(T) \ |
|
186 |
+ GLTRAITS_TEST_MEMBERS(0, #T, 0, sizeof(T)) |
|
187 |
+ #define GLTRAITS_TEST_MEMBERS_OFFSETOF(T, MEMBER) \ |
|
188 |
+ GLTRAITS_TEST_MEMBERS( \ |
|
189 |
+ 2, \ |
|
190 |
+ GLTraits::Value<decltype(T::MEMBER)>::name, \ |
|
191 |
+ offsetof(T, MEMBER), \ |
|
192 |
+ offsetof(T, MEMBER) + sizeof(T::MEMBER) \ |
|
193 |
+ ) |
|
194 |
+ GLTRAITS_TEST_MEMBERS_T(Vertex) |
|
195 |
+ GLTRAITS_TEST_MEMBERS_OFFSETOF(Vertex, position) |
|
196 |
+ GLTRAITS_TEST_MEMBERS_OFFSETOF(Vertex, tex_coord) |
|
197 |
+ GLTRAITS_TEST_MEMBERS_OFFSETOF(Vertex, tbn) |
|
198 |
+ GLTRAITS_TEST_MEMBERS_OFFSETOF(Vertex, bone_indices) |
|
199 |
+ GLTRAITS_TEST_MEMBERS_OFFSETOF(Vertex, bone_weights) |
|
200 |
+ GLTRAITS_TEST_MEMBERS_OFFSETOF(Vertex, flags) |
|
201 |
+ GLTRAITS_TEST_MEMBERS_OFFSETOF(Vertex, unaligned) |
|
202 |
+ GLTRAITS_TEST_MEMBERS_T(Vertex) |
|
203 |
+ GLTraitsTest::test_members(GLTraits::members<Vertex>()); |
|
204 |
+ #endif |
|
138 | 205 |
} |
... | ... |
@@ -81,6 +81,33 @@ struct GLTraitsTest : protected GLBase |
81 | 81 |
GLTRAITS_TEST_OBJECT(info_log); |
82 | 82 |
} |
83 | 83 |
|
84 |
+ template<std::size_t N> |
|
85 |
+ void static test_texture() |
|
86 |
+ { |
|
87 |
+ using Traits = GLTraits::Texture<N>; |
|
88 |
+ static_assert( |
|
89 |
+ std::is_empty<Traits>::value, |
|
90 |
+ "GLTraits::Texture must be empty" |
|
91 |
+ ); |
|
92 |
+ #define GLTRAITS_TEST_TEXTURE(NAME) \ |
|
93 |
+ << std::left << std::setw(32) \ |
|
94 |
+ << " " #NAME ":" \ |
|
95 |
+ << (void *)Traits::NAME \ |
|
96 |
+ << "\n" |
|
97 |
+ std::cout |
|
98 |
+ << "Texture<" << N << ">" << "\n" |
|
99 |
+ GLTRAITS_TEST_TEXTURE(template tex_image<>) |
|
100 |
+ GLTRAITS_TEST_TEXTURE(template tex_storage<>) |
|
101 |
+ GLTRAITS_TEST_TEXTURE(template texture_storage<>) |
|
102 |
+ GLTRAITS_TEST_TEXTURE(template tex_sub_image<>) |
|
103 |
+ GLTRAITS_TEST_TEXTURE(template texture_sub_image<>) |
|
104 |
+ GLTRAITS_TEST_TEXTURE(copy_tex_sub_image) |
|
105 |
+ GLTRAITS_TEST_TEXTURE(copy_texture_sub_image) |
|
106 |
+ GLTRAITS_TEST_TEXTURE(compressed_tex_image) |
|
107 |
+ GLTRAITS_TEST_TEXTURE(compressed_tex_sub_image) |
|
108 |
+ GLTRAITS_TEST_TEXTURE(compressed_texture_sub_image); |
|
109 |
+ } |
|
110 |
+ |
|
84 | 111 |
}; |
85 | 112 |
|
86 | 113 |
|
... | ... |
@@ -104,4 +131,8 @@ int main() |
104 | 131 |
|
105 | 132 |
GLTraitsTest::test_object<GL_SHADER, GLenum>(); |
106 | 133 |
GLTraitsTest::test_object<GL_PROGRAM_PIPELINE>(); |
134 |
+ |
|
135 |
+ GLTraitsTest::test_texture<1>(); |
|
136 |
+ GLTraitsTest::test_texture<2>(); |
|
137 |
+ GLTraitsTest::test_texture<3>(); |
|
107 | 138 |
} |
... | ... |
@@ -61,6 +61,26 @@ struct GLTraitsTest : protected GLBase |
61 | 61 |
<< " " << GLTraits::Value<typename Traits::Value>::name << "\n"; |
62 | 62 |
} |
63 | 63 |
|
64 |
+ template<GLenum object_type, typename... Args> |
|
65 |
+ void static test_object() |
|
66 |
+ { |
|
67 |
+ using Traits = GLTraits::Object<object_type>; |
|
68 |
+ static_assert( |
|
69 |
+ std::is_empty<Traits>::value, |
|
70 |
+ "GLTraits::Object must be empty" |
|
71 |
+ ); |
|
72 |
+ #define GLTRAITS_TEST_OBJECT(NAME) \ |
|
73 |
+ << std::left << std::setw(33) \ |
|
74 |
+ << " " #NAME ":" \ |
|
75 |
+ << (void *)Traits::NAME \ |
|
76 |
+ << "\n" |
|
77 |
+ std::cout |
|
78 |
+ << "Object<" << Traits::name << ">" << "\n" |
|
79 |
+ GLTRAITS_TEST_OBJECT(template gen_objects<Args...>) |
|
80 |
+ GLTRAITS_TEST_OBJECT(delete_objects) |
|
81 |
+ GLTRAITS_TEST_OBJECT(info_log); |
|
82 |
+ } |
|
83 |
+ |
|
64 | 84 |
}; |
65 | 85 |
|
66 | 86 |
|
... | ... |
@@ -81,4 +101,7 @@ int main() |
81 | 101 |
GLTraitsTest::test_value_id<GL_FLOAT_MAT4x3>(); |
82 | 102 |
GLTraitsTest::test_value_id<GL_UNSIGNED_INT_VEC2>(); |
83 | 103 |
GLTraitsTest::test_value_id<GL_DOUBLE_VEC2>(); |
104 |
+ |
|
105 |
+ GLTraitsTest::test_object<GL_SHADER, GLenum>(); |
|
106 |
+ GLTraitsTest::test_object<GL_PROGRAM_PIPELINE>(); |
|
84 | 107 |
} |
... | ... |
@@ -26,6 +26,8 @@ struct GLTraitsTest : protected GLBase |
26 | 26 |
GLTRAITS_TEST_VALUE(#NAME, std::dec << Traits::NAME) |
27 | 27 |
#define GLTRAITS_TEST_VALUE_BOOL(NAME) \ |
28 | 28 |
GLTRAITS_TEST_VALUE(#NAME, std::boolalpha << Traits::NAME) |
29 |
+ #define GLTRAITS_TEST_VALUE_HEX(NAME) \ |
|
30 |
+ GLTRAITS_TEST_VALUE(#NAME, str_enum_(Traits::NAME)) |
|
29 | 31 |
#define GLTRAITS_TEST_VALUE_ENUM(NAME, SUFFIX) \ |
30 | 32 |
GLTRAITS_TEST_VALUE( \ |
31 | 33 |
#NAME #SUFFIX, \ |
... | ... |
@@ -42,7 +44,21 @@ struct GLTraitsTest : protected GLBase |
42 | 44 |
GLTRAITS_TEST_VALUE_ENUM(internal_format, _srgb) |
43 | 45 |
GLTRAITS_TEST_VALUE_ENUM(internal_format, _compressed) |
44 | 46 |
GLTRAITS_TEST_VALUE_ENUM(internal_format, _compressed_srgb) |
45 |
- GLTRAITS_TEST_VALUE_BOOL(integer); |
|
47 |
+ GLTRAITS_TEST_VALUE_BOOL(integer) |
|
48 |
+ GLTRAITS_TEST_VALUE_HEX(id); |
|
49 |
+ } |
|
50 |
+ |
|
51 |
+ template<GLenum id> |
|
52 |
+ void static test_value_id() |
|
53 |
+ { |
|
54 |
+ using Traits = GLTraits::ValueID<id>; |
|
55 |
+ static_assert( |
|
56 |
+ std::is_empty<Traits>::value, |
|
57 |
+ "GLTraits::ValueID must be empty" |
|
58 |
+ ); |
|
59 |
+ std::cout |
|
60 |
+ << "ValueID<" << str_enum_(id) << ">" << "\n" |
|
61 |
+ << " " << GLTraits::Value<typename Traits::Value>::name << "\n"; |
|
46 | 62 |
} |
47 | 63 |
|
48 | 64 |
}; |
... | ... |
@@ -57,4 +73,12 @@ int main() |
57 | 73 |
GLTraitsTest::test_value<glm::mat4x3>(); |
58 | 74 |
GLTraitsTest::test_value<glm::uvec2>(); |
59 | 75 |
GLTraitsTest::test_value<glm::dvec2>(); |
76 |
+ |
|
77 |
+ GLTraitsTest::test_value_id<GL_FLOAT>(); |
|
78 |
+ GLTraitsTest::test_value_id<GL_BOOL>(); |
|
79 |
+ GLTraitsTest::test_value_id<GL_SHORT>(); |
|
80 |
+ GLTraitsTest::test_value_id<GL_DOUBLE>(); |
|
81 |
+ GLTraitsTest::test_value_id<GL_FLOAT_MAT4x3>(); |
|
82 |
+ GLTraitsTest::test_value_id<GL_UNSIGNED_INT_VEC2>(); |
|
83 |
+ GLTraitsTest::test_value_id<GL_DOUBLE_VEC2>(); |
|
60 | 84 |
} |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,60 @@ |
1 |
+#include <iomanip> |
|
2 |
+#include <iostream> |
|
3 |
+#include <string> |
|
4 |
+#include <type_traits> |
|
5 |
+ |
|
6 |
+#include <glm/glm.hpp> |
|
7 |
+ |
|
8 |
+#include <glbase.hpp> |
|
9 |
+#include <gltraits.hpp> |
|
10 |
+ |
|
11 |
+ |
|
12 |
+struct GLTraitsTest : protected GLBase |
|
13 |
+{ |
|
14 |
+ |
|
15 |
+ template<typename Value> |
|
16 |
+ void static test_value() |
|
17 |
+ { |
|
18 |
+ using Traits = GLTraits::Value<Value>; |
|
19 |
+ static_assert( |
|
20 |
+ std::is_empty<Traits>::value, |
|
21 |
+ "GLTraits::Value must be empty" |
|
22 |
+ ); |
|
23 |
+ #define GLTRAITS_TEST_VALUE(NAME, VALUE) \ |
|
24 |
+ << std::left << std::setw(35) << " " NAME ":" << VALUE << "\n" |
|
25 |
+ #define GLTRAITS_TEST_VALUE_DEC(NAME) \ |
|
26 |
+ GLTRAITS_TEST_VALUE(#NAME, std::dec << Traits::NAME) |
|
27 |
+ #define GLTRAITS_TEST_VALUE_BOOL(NAME) \ |
|
28 |
+ GLTRAITS_TEST_VALUE(#NAME, std::boolalpha << Traits::NAME) |
|
29 |
+ #define GLTRAITS_TEST_VALUE_ENUM(NAME, SUFFIX) \ |
|
30 |
+ GLTRAITS_TEST_VALUE( \ |
|
31 |
+ #NAME #SUFFIX, \ |
|
32 |
+ str_##NAME##_(Traits::NAME##SUFFIX) \ |
|
33 |
+ ) |
|
34 |
+ std::cout |
|
35 |
+ << "Value<" << Traits::name << ">" << "\n" |
|
36 |
+ GLTRAITS_TEST_VALUE_DEC(columns) |
|
37 |
+ GLTRAITS_TEST_VALUE_DEC(rows) |
|
38 |
+ GLTRAITS_TEST_VALUE_ENUM(glsl,) |
|
39 |
+ GLTRAITS_TEST_VALUE_ENUM(format,) |
|
40 |
+ GLTRAITS_TEST_VALUE_ENUM(type,) |
|
41 |
+ GLTRAITS_TEST_VALUE_ENUM(internal_format,) |
|
42 |
+ GLTRAITS_TEST_VALUE_ENUM(internal_format, _srgb) |
|
43 |
+ GLTRAITS_TEST_VALUE_ENUM(internal_format, _compressed) |
|
44 |
+ GLTRAITS_TEST_VALUE_ENUM(internal_format, _compressed_srgb) |
|
45 |
+ GLTRAITS_TEST_VALUE_BOOL(integer); |
|
46 |
+ } |
|
47 |
+ |
|
48 |
+}; |
|
49 |
+ |
|
50 |
+ |
|
51 |
+int main() |
|
52 |
+{ |
|
53 |
+ GLTraitsTest::test_value<GLfloat>(); |
|
54 |
+ GLTraitsTest::test_value<bool>(); |
|
55 |
+ GLTraitsTest::test_value<GLshort>(); |
|
56 |
+ GLTraitsTest::test_value<GLdouble>(); |
|
57 |
+ GLTraitsTest::test_value<glm::mat4x3>(); |
|
58 |
+ GLTraitsTest::test_value<glm::uvec2>(); |
|
59 |
+ GLTraitsTest::test_value<glm::dvec2>(); |
|
60 |
+} |