GLSL Struct 1.4.0
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 namespace utils {
45 #pragma region CHECKS
46 #pragma region IS_MAT
47 /**
48 * @var is_glsl_mat_v
49 * @brief Bool value which is true if type can be converted to glsl mat type
50 * @ingroup utils
51 * @tparam T type for which converter to glsl mat type should be defined
52 */
53
54 /**
55 * @struct is_glsl_mat
56 * @brief struct with bool_constant which is true if type can be converted to glsl mat type
57 * @ingroup utils
58 * @tparam T type for which converter to glsl mat type should be defined
59 */
60
62 /**
63 * @brief Concept defining which type can be converted to glsl mat type
64 * @ingroup utils
65 * @tparam T type for which converter to glsl mat type should be defined
66 */
67 template<class T>
68 concept glsl_mat = requires {
69 { mat_traits<T>::get_columns() } -> std::same_as<size_t>;
70 { mat_traits<T>::get_rows() } -> std::same_as<size_t>;
71 { mat_traits<T>::get_value_type() } -> std::same_as<ValueType>;
72 { mat_traits<T>::get_data(std::declval<const T&>()) } -> std::same_as<mat_data>;
73 { mat_traits<T>::get_value(std::declval<const mat_data&>()) } -> std::same_as<T>;
74 };
75
76 template<class T>
77 static _GLSL_STRUCT_CONSTEXPR17 bool is_glsl_mat_v = glsl_mat<T>;
78
79 template<typename T>
80 struct is_glsl_mat : std::bool_constant<is_glsl_mat_v<T> > {};
81
82 #else
83 template<typename T, typename = void>
84 struct is_glsl_mat : std::false_type {};
85
86 template<typename T>
87 struct is_glsl_mat<T,
88 std::void_t<std::enable_if_t<std::is_same_v<size_t, decltype(mat_traits<T>::get_columns())> >,
89 std::enable_if_t<std::is_same_v<size_t, decltype(mat_traits<T>::get_rows())> >,
90 std::enable_if_t<std::is_same_v<ValueType, decltype(mat_traits<T>::get_value_type())> >,
91 std::enable_if_t<std::is_same_v<mat_data, decltype(mat_traits<T>::get_data(std::declval<const T&>()))> >,
92 std::enable_if_t<std::is_same_v<T, decltype(mat_traits<T>::get_value(std::declval<const mat_data&>()))> > > >
93 : std::true_type {};
94
95 template<class T>
96 static _GLSL_STRUCT_CONSTEXPR17 bool is_glsl_mat_v = is_glsl_mat<T>::value;
97 #endif
98 #pragma endregion
99
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 #pragma endregion
134 } // namespace utils
135} // namespace glslstruct
136
137 #endif
138#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