GLSL Struct 1.4.8
glslstruct
Loading...
Searching...
No Matches
vec_traits_concept.hpp
1/*
2 * glslstruct - a C++ library designed to easily represent GLSL's Uniform Buffer Objects (UBOs) and Shader Storage Buffer Objects (SSBOs) in C++.
3 *
4 * Licensed under the BSD 3-Clause License with Attribution Requirement.
5 * See the LICENSE file for details: https://github.com/MAIPA01/glslstruct/blob/main/LICENSE
6 *
7 * Copyright (c) 2025, Patryk Antosik (MAIPA01)
8 */
9
10#pragma once
11#ifndef _GLSL_STRUCT_VEC_TRAITS_CONCEPT_HPP
12 #define _GLSL_STRUCT_VEC_TRAITS_CONCEPT_HPP
13
14 #include <glslstruct/config.hpp>
15
17_GLSL_STRUCT_ERROR("This is only available for c++17 and greater!");
18 #else
19
20 #include <glslstruct/utils/array_traits.hpp>
21 #include <glslstruct/utils/ValueType.hpp>
22
23namespace glslstruct {
24 class vec_data;
25
26 /**
27 * @brief Contains all static functions needed for layout and struct classes to interpret given vec type as glsl vec value.
28 * @ingroup glslstruct
29 * @tparam T vec type for which user want to define own glsl converter
30 * @details static functions that need to be declared:
31 * @code{.cpp}
32 * size_t get_length(); // -> returns length of vector
33 * ValueType get_value_type(); // -> returns scalar type of vector
34 * vec_data get_data(const T&); // -> returns bytes data in vec_data container
35 * // (preferable is to use already declared type conversions
36 * // glm::vec or mstd::vec)
37 * T get_value(const vec_data&); // -> returns value read from vec_data container
38 * @endcode
39 */
40 template<class T>
41 struct vec_traits {};
42
43 #pragma region CHECKS
44
45 #pragma region IS_VEC
46 /**
47 * @var is_glsl_vec_v
48 * @brief Bool value which is true if type can be converted to glsl vec type
49 * @ingroup glslstruct
50 * @tparam T type for which converter to glsl vec type should be defined
51 */
52
53 /**
54 * @struct is_glsl_vec
55 * @brief struct with bool_constant which is true if type can be converted to glsl vec type
56 * @ingroup glslstruct
57 * @tparam T type for which converter to glsl vec type should be defined
58 */
59
61 /**
62 * @brief Concept defining which type can be converted to glsl vec type
63 * @ingroup glslstruct
64 * @tparam T type for which converter to glsl vec type should be defined
65 */
66 template<class T>
67 concept glsl_vec = requires {
68 { vec_traits<T>::get_length() } -> std::convertible_to<size_t>;
69 { vec_traits<T>::get_value_type() } -> std::convertible_to<ValueType>;
70 { vec_traits<T>::get_data(std::declval<const T&>()) } -> std::convertible_to<vec_data>;
71 { vec_traits<T>::get_value(std::declval<const vec_data&>()) } -> std::convertible_to<T>;
72 };
73
74 template<class T>
75 static _GLSL_STRUCT_CONSTEXPR17 bool is_glsl_vec_v = glsl_vec<T>;
76
77 template<class T>
78 struct is_glsl_vec : std::bool_constant<is_glsl_vec_v<T> > {};
79
80 #else
81 template<typename T, typename = void>
82 struct is_glsl_vec : std::false_type {};
83
84 template<class T>
85 struct is_glsl_vec<T,
86 std::void_t<std::enable_if_t<std::is_convertible_v<decltype(vec_traits<T>::get_length()), size_t> >,
87 std::enable_if_t<std::is_convertible_v<decltype(vec_traits<T>::get_value_type()), ValueType> >,
88 std::enable_if_t<std::is_convertible_v<decltype(vec_traits<T>::get_data(std::declval<const T&>())), vec_data> >,
89 std::enable_if_t<std::is_convertible_v<decltype(vec_traits<T>::get_value(std::declval<const vec_data&>())), T> > > >
90 : std::true_type {};
91
92 template<class T>
93 static _GLSL_STRUCT_CONSTEXPR17 bool is_glsl_vec_v = is_glsl_vec<T>::value;
94 #endif
95 #pragma endregion
96
97 namespace utils {
98 #pragma region IS_VECS_ARRAY
99 /**
100 * @brief Bool value which is true if type V is array of types that passes is_glsl_vec test
101 * @ingroup utils
102 * @tparam V type that is checked
103 */
104 template<class V>
105 static _GLSL_STRUCT_CONSTEXPR17 bool is_glsl_vecs_array_v = is_array_of_v<is_glsl_vec, V>;
106
107 /**
108 * @brief Bool value which is true if type V is static size array of types that passes is_glsl_vec test
109 * @ingroup utils
110 * @tparam V type that is checked
111 */
112 template<class V>
113 static _GLSL_STRUCT_CONSTEXPR17 bool is_glsl_vecs_static_size_array_v = is_static_size_array_of_v<is_glsl_vec, V>;
114
116 /**
117 * @brief Concept which is true if type V is array of types that passes is_glsl_vec test
118 * @ingroup utils
119 * @tparam V type that is checked
120 */
121 template<class V> concept glsl_vecs_array = is_glsl_vecs_array_v<V>;
122
123 /**
124 * @brief Concept which is true if type V is static size array of types that passes is_glsl_vec test
125 * @ingroup utils
126 * @tparam V type that is checked
127 */
128 template<class V> concept glsl_vecs_static_size_array = is_glsl_vecs_static_size_array_v<V>;
129 #endif
130 #pragma endregion
131 } // namespace utils
132
133 #pragma endregion
134} // namespace glslstruct
135
136 #endif
137#endif
#define _GLSL_STRUCT_HAS_CXX20
check if compiler has c++ version greater or equal to c++20 and if user enabled c++20 features using ...
Definition config.hpp:142
#define _GLSL_STRUCT_HAS_CXX17
check if compiler has c++ version greater or equal to c++17
Definition config.hpp:130
#define _GLSL_STRUCT_CONSTEXPR17
constexpr for c++17 and higher
Definition config.hpp:196