GLSL Struct 1.4.0
glslstruct
Loading...
Searching...
No Matches
struct_checks.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_STRUCT_CHECKS_HPP_
12 #define _GLSL_STRUCT_STRUCT_CHECKS_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/type/checks/layouts_checks.hpp>
21
22namespace glslstruct {
24 template<utils::glsl_layout Layout>
25 #else
26 template<class Layout, std::enable_if_t<utils::is_glsl_layout_v<Layout>, bool> = true>
27 #endif
28 class base_struct;
29
30 /**
31 * @brief std140 struct representation
32 * @ingroup glslstruct
33 */
34 using std140_struct = base_struct<std140_layout>;
35 /**
36 * @brief std430 struct representation
37 * @ingroup glslstruct
38 */
39 using std430_struct = base_struct<std430_layout>;
40 /**
41 * @brief scalar struct representation
42 * @ingroup glslstruct
43 */
44 using scalar_struct = base_struct<scalar_layout>;
45
46 namespace utils {
47 #pragma region IS_STRUCT
48
49 /**
50 * @brief helper struct to check if type is glsl struct
51 * @ingroup utils
52 * @tparam S type which is glsl struct type
53 */
54 template<class S>
55 struct is_glsl_struct : std::false_type {};
56
57 template<class L>
58 struct is_glsl_struct<base_struct<L> > : std::true_type {};
59
60 /**
61 * @brief check if type is glsl struct
62 * @ingroup utils
63 * @tparam S type which is glsl struct type
64 */
65 template<class S>
66 static _GLSL_STRUCT_CONSTEXPR17 bool is_glsl_struct_v = is_glsl_struct<S>::value;
67
69 /**
70 * @brief check if type is glsl struct
71 * @ingroup utils
72 * @tparam S type which is glsl struct type
73 */
74 template<class S> concept glsl_struct = is_glsl_struct_v<S>;
75 #endif
76 #pragma endregion
77
78 #pragma region IS_STRUCTS_VECTOR
79 /**
80 * @brief check if type is array of glsl structs
81 * @ingroup utils
82 */
83 template<class T>
84 static _GLSL_STRUCT_CONSTEXPR17 bool is_glsl_structs_array_v = is_array_of_v<is_glsl_struct, T>;
85
87 /**
88 * @brief check if type is array of glsl structs
89 * @ingroup utils
90 */
91 template<class T> concept glsl_structs_array = is_glsl_structs_array_v<T>;
92 #endif
93 #pragma endregion
94
95 #pragma region IS_LAYOUT_STRUCT
96
97 /**
98 * @brief helper struct to check if type is glsl struct with required layout
99 * @ingroup utils
100 * @tparam S type which is glsl struct with required layout
101 * @tparam Layout required glsl layout type
102 */
103 template<class S, class Layout>
104 struct is_glsl_layout_struct : std::false_type {};
105
106 template<class L, class Layout>
107 struct is_glsl_layout_struct<base_struct<Layout>, L> : std::bool_constant<std::is_same_v<Layout, L> > {};
108
109 /**
110 * @brief check if type is glsl struct with required layout
111 * @ingroup utils
112 * @tparam S type which is glsl struct with required
113 * @tparam Layout required glsl layout type
114 */
115 template<class S, class Layout>
116 static _GLSL_STRUCT_CONSTEXPR17 bool is_glsl_layout_struct_v = is_glsl_layout_struct<S, Layout>::value;
117
119 /**
120 * @brief check if type is glsl struct with required layout
121 * @ingroup utils
122 * @tparam S type which is glsl struct with required
123 * @tparam Layout required glsl layout type
124 */
125 template<class S, class Layout> concept glsl_layout_struct = is_glsl_layout_struct_v<S, Layout>;
126 #endif
127 #pragma endregion
128
129 #pragma region IS_LAYOUT_STRUCTS_VECTOR
130 /**
131 * @brief check if type is array of glsl structs with required layout
132 * @ingroup utils
133 * @tparam VS type which is array of glsl structs with required layout
134 * @tparam Layout required glsl layout type
135 */
136 template<class VS, class Layout>
137 static _GLSL_STRUCT_CONSTEXPR17 bool is_glsl_layout_structs_array_v = is_array_of_v<is_glsl_layout_struct, VS, Layout>;
138
140 /**
141 * @brief check if type is array of glsl structs with required layout
142 * @ingroup utils
143 * @tparam VS type which is array of glsl structs with required layout
144 * @tparam Layout required glsl layout type
145 */
146 template<class VS, class Layout> concept glsl_layout_structs_array = is_glsl_layout_structs_array_v<VS, Layout>;
147 #endif
148 #pragma endregion
149
150 #pragma region IS_SIMPLE_OR_LAYOUT_STRUCT
151 /**
152 * @brief check if type is glsl struct with required layout or simple type
153 * @ingroup utils
154 * @tparam T type which is glsl struct with required layout or simple type
155 * @tparam Layout required glsl layout type
156 */
157 template<class T, class Layout>
158 static _GLSL_STRUCT_CONSTEXPR17 bool is_glsl_simple_or_layout_struct_v =
159 is_glsl_simple_v<T> || is_glsl_layout_struct_v<T, Layout>;
160
162 /**
163 * @brief check if type is glsl struct with required layout or simple type
164 * @ingroup utils
165 * @tparam T type which is glsl struct with required layout or simple type
166 * @tparam Layout required glsl layout type
167 */
168 template<class T, class Layout> concept glsl_simple_or_layout_struct = is_glsl_simple_or_layout_struct_v<T, Layout>;
169 #endif
170 #pragma endregion
171
172 #pragma region IS_SIMPLE_OR_STRUCT
173 /**
174 * @brief check if type is glsl struct or simple type
175 * @ingroup utils
176 * @tparam T type which is glsl struct or simple type
177 */
178 template<class T>
179 static _GLSL_STRUCT_CONSTEXPR17 bool is_glsl_simple_or_struct_v = is_glsl_simple_v<T> || is_glsl_struct_v<T>;
180
182 /**
183 * @brief check if type is glsl struct or simple type
184 * @ingroup utils
185 * @tparam T type which is glsl struct or simple type
186 */
187 template<class T> concept glsl_simple_or_struct = is_glsl_simple_or_struct_v<T>;
188 #endif
189 #pragma endregion
190 } // namespace utils
191} // namespace glslstruct
192 #endif
193#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