GLSL Struct 1.4.8
glslstruct
Loading...
Searching...
No Matches
mat_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_MAT_TRAITS_CONCEPT_HPP_
12 #define _GLSL_STRUCT_MAT_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 mat_data;
25
26 /**
27 * @brief Contains all static functions needed for layout and struct classes to interpret given mat type as glsl mat value.
28 * @ingroup glslstruct
29 * @tparam T mat 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_columns(); // -> returns number of columns in matrix
33 * size_t get_rows(); // -> returns number of rows in matrix
34 * ValueType get_value_type(); // -> returns scalar type of matrix
35 * mat_data get_data(const T&); // -> returns bytes data in mat_data container
36 * // (preferable is to use already declared type conversions
37 * // glm::mat or mstd::mat)
38 * T get_value(const mat_data&); // -> returns value read from mat_data container
39 * @endcode
40 */
41 template<class T>
42 struct mat_traits {};
43
44 #pragma region CHECKS
45 #pragma region IS_MAT
46 /**
47 * @var is_glsl_mat_v
48 * @brief Bool value which is true if type can be converted to glsl mat type
49 * @ingroup glslstruct
50 * @tparam T type for which converter to glsl mat type should be defined
51 */
52
53 /**
54 * @struct is_glsl_mat
55 * @brief struct with bool_constant which is true if type can be converted to glsl mat type
56 * @ingroup glslstruct
57 * @tparam T type for which converter to glsl mat type should be defined
58 */
59
61 /**
62 * @brief Concept defining which type can be converted to glsl mat type
63 * @ingroup glslstruct
64 * @tparam T type for which converter to glsl mat type should be defined
65 */
66 template<class T>
67 concept glsl_mat = requires {
68 { mat_traits<T>::get_columns() } -> std::convertible_to<size_t>;
69 { mat_traits<T>::get_rows() } -> std::convertible_to<size_t>;
70 { mat_traits<T>::get_value_type() } -> std::convertible_to<ValueType>;
71 { mat_traits<T>::get_data(std::declval<const T&>()) } -> std::convertible_to<mat_data>;
72 { mat_traits<T>::get_value(std::declval<const mat_data&>()) } -> std::convertible_to<T>;
73 };
74
75 template<class T>
76 static _GLSL_STRUCT_CONSTEXPR17 bool is_glsl_mat_v = glsl_mat<T>;
77
78 template<typename T>
79 struct is_glsl_mat : std::bool_constant<is_glsl_mat_v<T> > {};
80
81 #else
82 template<typename T, typename = void>
83 struct is_glsl_mat : std::false_type {};
84
85 template<typename T>
86 struct is_glsl_mat<T,
87 std::void_t<std::enable_if_t<std::is_convertible_v<decltype(mat_traits<T>::get_columns()), size_t> >,
88 std::enable_if_t<std::is_convertible_v<decltype(mat_traits<T>::get_rows()), size_t> >,
89 std::enable_if_t<std::is_convertible_v<decltype(mat_traits<T>::get_value_type()), ValueType> >,
90 std::enable_if_t<std::is_convertible_v<decltype(mat_traits<T>::get_data(std::declval<const T&>())), mat_data> >,
91 std::enable_if_t<std::is_convertible_v<decltype(mat_traits<T>::get_value(std::declval<const mat_data&>())), T> > > >
92 : std::true_type {};
93
94 template<class T>
95 static _GLSL_STRUCT_CONSTEXPR17 bool is_glsl_mat_v = is_glsl_mat<T>::value;
96 #endif
97 #pragma endregion
98
99 namespace utils {
100 #pragma region IS_MATS_ARRAY
101 /**
102 * @brief Bool value which is true if type V is array of types that passes is_glsl_mat test
103 * @ingroup utils
104 * @tparam V type that is checked
105 */
106 template<class V>
107 static _GLSL_STRUCT_CONSTEXPR17 bool is_glsl_mats_array_v = is_array_of_v<is_glsl_mat, V>;
108
109 /**
110 * @brief Bool value which is true if type V is static size array of types that passes is_glsl_mat test
111 * @ingroup utils
112 * @tparam V type that is checked
113 */
114 template<class V>
115 static _GLSL_STRUCT_CONSTEXPR17 bool is_glsl_mats_static_size_array_v = is_static_size_array_of_v<is_glsl_mat, V>;
116
118 /**
119 * @brief Concept which is true if type V is array of types that passes is_glsl_mat test
120 * @ingroup utils
121 * @tparam V type that is checked
122 */
123 template<class V> concept glsl_mats_array = is_glsl_mats_array_v<V>;
124
125 /**
126 * @brief Concept which is true if type V is static size array of types that passes is_glsl_mat test
127 * @ingroup utils
128 * @tparam V type that is checked
129 */
130 template<class V> concept glsl_mats_static_size_array = is_glsl_mats_static_size_array_v<V>;
131 #endif
132 #pragma endregion
133 } // namespace utils
134
135 #pragma endregion
136} // namespace glslstruct
137
138 #endif
139#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