GLSL Struct 1.4.0
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 namespace utils {
44 #pragma region CHECKS
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 utils
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 utils
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 utils
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::same_as<size_t>;
69 { vec_traits<T>::get_value_type() } -> std::same_as<ValueType>;
70 { vec_traits<T>::get_data(std::declval<const T&>()) } -> std::same_as<vec_data>;
71 { vec_traits<T>::get_value(std::declval<const vec_data&>()) } -> std::same_as<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_same_v<size_t, decltype(vec_traits<T>::get_length())> >,
87 std::enable_if_t<std::is_same_v<ValueType, decltype(vec_traits<T>::get_value_type())> >,
88 std::enable_if_t<std::is_same_v<vec_data, decltype(vec_traits<T>::get_data(std::declval<const T&>()))> >,
89 std::enable_if_t<std::is_same_v<T, decltype(vec_traits<T>::get_value(std::declval<const vec_data&>()))> > > >
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 #pragma region IS_VECS_ARRAY
98 /**
99 * @brief Bool value which is true if type V is array of types that passes is_glsl_vec test
100 * @ingroup utils
101 * @tparam V type that is checked
102 */
103 template<class V>
104 static _GLSL_STRUCT_CONSTEXPR17 bool is_glsl_vecs_array_v = is_array_of_v<is_glsl_vec, V>;
105
106 /**
107 * @brief Bool value which is true if type V is static size array of types that passes is_glsl_vec test
108 * @ingroup utils
109 * @tparam V type that is checked
110 */
111 template<class V>
112 static _GLSL_STRUCT_CONSTEXPR17 bool is_glsl_vecs_static_size_array_v = is_static_size_array_of_v<is_glsl_vec, V>;
113
115 /**
116 * @brief Concept which is true if type V is array of types that passes is_glsl_vec test
117 * @ingroup utils
118 * @tparam V type that is checked
119 */
120 template<class V> concept glsl_vecs_array = is_glsl_vecs_array_v<V>;
121
122 /**
123 * @brief Concept which is true if type V is static size array of types that passes is_glsl_vec test
124 * @ingroup utils
125 * @tparam V type that is checked
126 */
127 template<class V> concept glsl_vecs_static_size_array = is_glsl_vecs_static_size_array_v<V>;
128 #endif
129 #pragma endregion
130 #pragma endregion
131 } // namespace utils
132} // namespace glslstruct
133
134 #endif
135#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