OGLplus  (0.59.0) a C++ wrapper for rendering APIs

type_utils.hpp
Go to the documentation of this file.
1 #ifndef OGLPLUS_GL_API_TYPE_UTILS_HPP
9 #define OGLPLUS_GL_API_TYPE_UTILS_HPP
10 
11 #include "../math/vector.hpp"
12 #include "config.hpp"
13 #include "enum_types.hpp"
14 #include <eagine/type_identity.hpp>
15 #include <type_traits>
16 
17 namespace eagine::oglp {
18 //------------------------------------------------------------------------------
21 template <typename T>
22 constexpr const bool is_gl_data_type_v =
23  (std::is_same_v<T, gl_types::ubyte_type> ||
24  std::is_same_v<T, gl_types::byte_type> ||
25  std::is_same_v<T, gl_types::ushort_type> ||
26  std::is_same_v<T, gl_types::short_type> ||
27  std::is_same_v<T, gl_types::uint_type> ||
28  std::is_same_v<T, gl_types::int_type> ||
29  std::is_same_v<T, gl_types::float_type> ||
30  std::is_same_v<T, gl_types::double_type>);
31 //------------------------------------------------------------------------------
32 // data_type_of
33 //------------------------------------------------------------------------------
36 #ifdef GL_UNSIGNED_BYTE
37  return GL_UNSIGNED_BYTE;
38 #else
39  return 0;
40 #endif
41 }
42 //------------------------------------------------------------------------------
43 constexpr auto data_type_of(type_identity<gl_types::byte_type>) noexcept
45 #ifdef GL_BYTE
46  return GL_BYTE;
47 #else
48  return 0;
49 #endif
50 }
51 //------------------------------------------------------------------------------
52 constexpr auto data_type_of(type_identity<gl_types::ushort_type>) noexcept
54 #ifdef GL_UNSIGNED_SHORT
55  return GL_UNSIGNED_SHORT;
56 #else
57  return 0;
58 #endif
59 }
60 //------------------------------------------------------------------------------
61 constexpr auto data_type_of(type_identity<gl_types::short_type>) noexcept
63 #ifdef GL_SHORT
64  return GL_SHORT;
65 #else
66  return 0;
67 #endif
68 }
69 //------------------------------------------------------------------------------
70 constexpr auto data_type_of(type_identity<gl_types::uint_type>) noexcept
72 #ifdef GL_UNSIGNED_INT
73  return GL_UNSIGNED_INT;
74 #else
75  return 0;
76 #endif
77 }
78 //------------------------------------------------------------------------------
79 constexpr auto data_type_of(type_identity<gl_types::int_type>) noexcept
81 #ifdef GL_INT
82  return GL_INT;
83 #else
84  return 0;
85 #endif
86 }
87 //------------------------------------------------------------------------------
88 constexpr auto data_type_of(type_identity<gl_types::float_type>) noexcept
90 #ifdef GL_FLOAT
91  return GL_FLOAT;
92 #else
93  return 0;
94 #endif
95 }
96 //------------------------------------------------------------------------------
97 constexpr auto data_type_of(type_identity<gl_types::double_type>) noexcept
99 #ifdef GL_DOUBLE
100  return GL_DOUBLE;
101 #else
102  return 0;
103 #endif
104 }
105 //------------------------------------------------------------------------------
106 template <typename T, int N, bool V>
107 constexpr auto data_type_of(type_identity<vector<T, N, V>>) noexcept {
108  return data_type_of(type_identity<T>{});
109 }
110 //------------------------------------------------------------------------------
111 template <typename T, int N, bool V>
112 constexpr auto data_type_of(type_identity<tvec<T, N, V>>) noexcept {
113  return data_type_of(type_identity<T>{});
114 }
115 //------------------------------------------------------------------------------
120 template <typename T>
121 constexpr auto data_type_of() noexcept -> data_type {
123 }
124 //------------------------------------------------------------------------------
131 template <typename T>
132 constexpr auto pixel_data_type_of() noexcept -> pixel_data_type {
134 }
135 //------------------------------------------------------------------------------
140 template <typename T>
141 constexpr auto sl_data_type_of() noexcept -> sl_data_type {
143 }
144 //------------------------------------------------------------------------------
145 // pixel_format_of
146 //------------------------------------------------------------------------------
147 template <typename T>
148 constexpr auto pixel_format_of(type_identity<T>) noexcept -> std::enable_if_t<
149  is_gl_data_type_v<T> && std::is_integral_v<T>,
151 #ifdef GL_RED_INTEGER
152  return GL_RED_INTEGER;
153 #else
154  return 0;
155 #endif
156 }
157 //------------------------------------------------------------------------------
158 template <typename T>
159 constexpr auto pixel_format_of(type_identity<T>) noexcept -> std::enable_if_t<
160  is_gl_data_type_v<T> && !std::is_integral_v<T>,
162 #ifdef GL_RED
163  return GL_RED;
164 #else
165  return 0;
166 #endif
167 }
168 //------------------------------------------------------------------------------
169 template <typename T, bool V>
170 constexpr auto pixel_format_of(type_identity<vector<T, 2, V>>) noexcept
171  -> std::enable_if_t<
172  is_gl_data_type_v<T> && std::is_integral_v<T>,
173  gl_types::enum_type> {
174 #ifdef GL_RG_INTEGER
175  return GL_RG_INTEGER;
176 #else
177  return 0;
178 #endif
179 }
180 //------------------------------------------------------------------------------
181 template <typename T, bool V>
182 constexpr auto pixel_format_of(type_identity<vector<T, 2, V>>) noexcept
183  -> std::enable_if_t<
184  is_gl_data_type_v<T> && !std::is_integral_v<T>,
185  gl_types::enum_type> {
186 #ifdef GL_RG
187  return GL_RG;
188 #else
189  return 0;
190 #endif
191 }
192 //------------------------------------------------------------------------------
193 template <typename T, bool V>
194 constexpr auto pixel_format_of(type_identity<vector<T, 3, V>>) noexcept
195  -> std::enable_if_t<
196  is_gl_data_type_v<T> && std::is_integral_v<T>,
197  gl_types::enum_type> {
198 #ifdef GL_RGB_INTEGER
199  return GL_RGB_INTEGER;
200 #else
201  return 0;
202 #endif
203 }
204 //------------------------------------------------------------------------------
205 template <typename T, bool V>
206 constexpr auto pixel_format_of(type_identity<vector<T, 3, V>>) noexcept
207  -> std::enable_if_t<
208  is_gl_data_type_v<T> && !std::is_integral_v<T>,
209  gl_types::enum_type> {
210 #ifdef GL_RGB
211  return GL_RGB;
212 #else
213  return 0;
214 #endif
215 }
216 //------------------------------------------------------------------------------
217 template <typename T, bool V>
218 constexpr auto pixel_format_of(type_identity<vector<T, 4, V>>) noexcept
219  -> std::enable_if_t<
220  is_gl_data_type_v<T> && std::is_integral_v<T>,
221  gl_types::enum_type> {
222 #ifdef GL_RGBA_INTEGER
223  return GL_RGBA_INTEGER;
224 #else
225  return 0;
226 #endif
227 }
228 //------------------------------------------------------------------------------
229 template <typename T, bool V>
230 constexpr auto pixel_format_of(type_identity<vector<T, 4, V>>) noexcept
231  -> std::enable_if_t<
232  is_gl_data_type_v<T> && !std::is_integral_v<T>,
233  gl_types::enum_type> {
234 #ifdef GL_RGBA
235  return GL_RGBA;
236 #else
237  return 0;
238 #endif
239 }
240 //------------------------------------------------------------------------------
241 template <
242  typename T,
243  int N,
244  bool V,
245  typename = std::enable_if_t<is_gl_data_type_v<T>>>
246 constexpr auto pixel_format_of(type_identity<tvec<T, N, V>>) noexcept
247  -> gl_types::enum_type {
248  return pixel_format_of(type_identity<vector<T, N, V>>{});
249 }
250 //------------------------------------------------------------------------------
255 template <typename T>
256 constexpr auto pixel_format_of() noexcept -> pixel_format {
258 }
259 //------------------------------------------------------------------------------
260 // internal_format_of
261 //------------------------------------------------------------------------------
264 #ifdef GL_R8UI
265  return GL_R8UI;
266 #else
267  return 0;
268 #endif
269 }
270 //------------------------------------------------------------------------------
271 template <bool V>
272 constexpr auto
273 internal_format_of(type_identity<vector<gl_types::ubyte_type, 2, V>>) noexcept
274  -> gl_types::enum_type {
275 #ifdef GL_RG8UI
276  return GL_RG8UI;
277 #else
278  return 0;
279 #endif
280 }
281 //------------------------------------------------------------------------------
282 template <bool V>
283 constexpr auto
284 internal_format_of(type_identity<vector<gl_types::ubyte_type, 4, V>>) noexcept
285  -> gl_types::enum_type {
286 #ifdef GL_RGBA8UI
287  return GL_RGBA8UI;
288 #else
289  return 0;
290 #endif
291 }
292 //------------------------------------------------------------------------------
293 constexpr auto internal_format_of(type_identity<gl_types::byte_type>) noexcept
295 #ifdef GL_R8I
296  return GL_R8I;
297 #else
298  return 0;
299 #endif
300 }
301 //------------------------------------------------------------------------------
302 template <bool V>
303 constexpr auto
304 internal_format_of(type_identity<vector<gl_types::byte_type, 2, V>>) noexcept
305  -> gl_types::enum_type {
306 #ifdef GL_RG8I
307  return GL_RG8I;
308 #else
309  return 0;
310 #endif
311 }
312 //------------------------------------------------------------------------------
313 template <bool V>
314 constexpr auto
315 internal_format_of(type_identity<vector<gl_types::byte_type, 4, V>>) noexcept
316  -> gl_types::enum_type {
317 #ifdef GL_RGBA8I
318  return GL_RGBA8I;
319 #else
320  return 0;
321 #endif
322 }
323 //------------------------------------------------------------------------------
324 constexpr auto internal_format_of(type_identity<gl_types::ushort_type>) noexcept
326 #ifdef GL_R16UI
327  return GL_R16UI;
328 #else
329  return 0;
330 #endif
331 }
332 //------------------------------------------------------------------------------
333 template <bool V>
334 constexpr auto
335 internal_format_of(type_identity<vector<gl_types::ushort_type, 2, V>>) noexcept
336  -> gl_types::enum_type {
337 #ifdef GL_RG16UI
338  return GL_RG16UI;
339 #else
340  return 0;
341 #endif
342 }
343 //------------------------------------------------------------------------------
344 template <bool V>
345 constexpr auto
346 internal_format_of(type_identity<vector<gl_types::ushort_type, 4, V>>) noexcept
347  -> gl_types::enum_type {
348 #ifdef GL_RGBA16UI
349  return GL_RGBA16UI;
350 #else
351  return 0;
352 #endif
353 }
354 //------------------------------------------------------------------------------
355 constexpr auto internal_format_of(type_identity<gl_types::short_type>) noexcept
357 #ifdef GL_R16I
358  return GL_R16I;
359 #else
360  return 0;
361 #endif
362 }
363 //------------------------------------------------------------------------------
364 template <bool V>
365 constexpr auto
366 internal_format_of(type_identity<vector<gl_types::short_type, 2, V>>) noexcept
367  -> gl_types::enum_type {
368 #ifdef GL_RG16I
369  return GL_RG16I;
370 #else
371  return 0;
372 #endif
373 }
374 //------------------------------------------------------------------------------
375 template <bool V>
376 constexpr auto
377 internal_format_of(type_identity<vector<gl_types::short_type, 4, V>>) noexcept
378  -> gl_types::enum_type {
379 #ifdef GL_RGBA16I
380  return GL_RGBA16I;
381 #else
382  return 0;
383 #endif
384 }
385 //------------------------------------------------------------------------------
386 constexpr auto internal_format_of(type_identity<gl_types::uint_type>) noexcept
388 #ifdef GL_R32UI
389  return GL_R32UI;
390 #else
391  return 0;
392 #endif
393 }
394 //------------------------------------------------------------------------------
395 template <bool V>
396 constexpr auto
397 internal_format_of(type_identity<vector<gl_types::uint_type, 2, V>>) noexcept
398  -> gl_types::enum_type {
399 #ifdef GL_RG32UI
400  return GL_RG32UI;
401 #else
402  return 0;
403 #endif
404 }
405 //------------------------------------------------------------------------------
406 template <bool V>
407 constexpr auto
408 internal_format_of(type_identity<vector<gl_types::uint_type, 3, V>>) noexcept
409  -> gl_types::enum_type {
410 #ifdef GL_RGB32UI
411  return GL_RGB32UI;
412 #else
413  return 0;
414 #endif
415 }
416 //------------------------------------------------------------------------------
417 template <bool V>
418 constexpr auto
419 internal_format_of(type_identity<vector<gl_types::uint_type, 4, V>>) noexcept
420  -> gl_types::enum_type {
421 #ifdef GL_RGBA32UI
422  return GL_RGBA32UI;
423 #else
424  return 0;
425 #endif
426 }
427 //------------------------------------------------------------------------------
428 constexpr auto internal_format_of(type_identity<gl_types::int_type>) noexcept
430 #ifdef GL_R32I
431  return GL_R32I;
432 #else
433  return 0;
434 #endif
435 }
436 //------------------------------------------------------------------------------
437 template <bool V>
438 constexpr auto
439 internal_format_of(type_identity<vector<gl_types::int_type, 2, V>>) noexcept
440  -> gl_types::enum_type {
441 #ifdef GL_RG32I
442  return GL_RG32I;
443 #else
444  return 0;
445 #endif
446 }
447 //------------------------------------------------------------------------------
448 template <bool V>
449 constexpr auto
450 internal_format_of(type_identity<vector<gl_types::int_type, 3, V>>) noexcept
451  -> gl_types::enum_type {
452 #ifdef GL_RGB32I
453  return GL_RGB32I;
454 #else
455  return 0;
456 #endif
457 }
458 //------------------------------------------------------------------------------
459 template <bool V>
460 constexpr auto
461 internal_format_of(type_identity<vector<gl_types::int_type, 4, V>>) noexcept
462  -> gl_types::enum_type {
463 #ifdef GL_RGBA32I
464  return GL_RGBA32I;
465 #else
466  return 0;
467 #endif
468 }
469 //------------------------------------------------------------------------------
470 constexpr auto internal_format_of(type_identity<gl_types::float_type>) noexcept
472 #ifdef GL_R32F
473  return GL_R32F;
474 #else
475  return 0;
476 #endif
477 }
478 //------------------------------------------------------------------------------
479 template <bool V>
480 constexpr auto
481 internal_format_of(type_identity<vector<gl_types::float_type, 2, V>>) noexcept
482  -> gl_types::enum_type {
483 #ifdef GL_RG32F
484  return GL_RG32F;
485 #else
486  return 0;
487 #endif
488 }
489 //------------------------------------------------------------------------------
490 template <bool V>
491 constexpr auto
492 internal_format_of(type_identity<vector<gl_types::float_type, 3, V>>) noexcept
493  -> gl_types::enum_type {
494 #ifdef GL_RGB32F
495  return GL_RGB32F;
496 #else
497  return 0;
498 #endif
499 }
500 //------------------------------------------------------------------------------
501 template <bool V>
502 constexpr auto
503 internal_format_of(type_identity<vector<gl_types::float_type, 4, V>>) noexcept
504  -> gl_types::enum_type {
505 #ifdef GL_RGBA32F
506  return GL_RGBA32F;
507 #else
508  return 0;
509 #endif
510 }
511 //------------------------------------------------------------------------------
512 template <typename T, int N, bool V>
513 constexpr auto internal_format_of(type_identity<tvec<T, N, V>>) noexcept {
514  return internal_format_of(type_identity<vector<T, N, V>>{});
515 }
516 //------------------------------------------------------------------------------
521 template <typename T>
522 constexpr auto internal_format_of() noexcept -> pixel_internal_format {
524 }
525 //------------------------------------------------------------------------------
526 } // namespace eagine::oglp
527 
528 #endif // OGLPLUS_GL_API_TYPE_UTILS_HPP
Typed enumeration for GL pixel data type constants.
Definition: enum_types.hpp:639
constexpr auto pixel_data_type_of() noexcept -> pixel_data_type
Returns a pixel data type for the specified C++ type T.
Definition: type_utils.hpp:132
GLenum enum_type
Enumeration type.
Definition: config.hpp:52
constexpr const bool is_gl_data_type_v
Trait indicating that T is one of GL basic (pixel) data types.
Definition: type_utils.hpp:22
constexpr auto sl_data_type_of() noexcept -> sl_data_type
Returns a shading language data type for the specified C++ type T.
Definition: type_utils.hpp:141
constexpr auto internal_format_of() noexcept -> pixel_internal_format
Returns the default pixel internal format for the specified C++ type T.
Definition: type_utils.hpp:522
Typed enumeration for GL data type constants.
Definition: enum_types.hpp:568
Typed enumeration for GL pixel internal format constants.
Definition: enum_types.hpp:659
Typed enumeration for GL pixel format constants.
Definition: enum_types.hpp:646
Template type used mostly for function type-tag dispatching.
Definition: type_identity.hpp:19
constexpr auto pixel_format_of() noexcept -> pixel_format
Returns the default pixel format for the specified C++ type T.
Definition: type_utils.hpp:256
constexpr auto data_type_of() noexcept -> data_type
Returns a data type for the specified C++ type T.
Definition: type_utils.hpp:121
Typed enumeration for GL shading language data type constants.
Definition: enum_types.hpp:581

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).