GLSL Struct 1.4.0
glslstruct
Loading...
Searching...
No Matches
glsl_variable.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_VARIABLE_HPP_
12 #define _GLSL_STRUCT_VARIABLE_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/types.hpp>
21
22namespace glslstruct {
23 namespace utils {
24 /**
25 * @brief container for standard variables
26 * @ingroup utils
27 */
28 struct standard_variable {};
29
30 /**
31 * @brief container for layout variables
32 * @ingroup utils
33 * @tparam Layout layout type
34 */
35 template<class Layout>
36 struct layout_variable {
37 /// @brief layout value
38 const Layout layout;
39
40 /// @brief constructor with layout value
41 explicit layout_variable(const Layout& layout) : layout(layout) {}
42 };
43 } // namespace utils
44
45 /**
46 * @brief container for variables for easier initialization of layouts
47 * @ingroup glslstruct
48 * @tparam T variable type
49 * @tparam num number of elements in array (default is 0. if it is 0 then it is not array but a single value)
50 */
52 template<utils::glsl_simple_or_layout T, size_t Num>
53 #else
54 template<class T, size_t Num, std::enable_if_t<utils::is_glsl_simple_or_layout_v<T>, bool> >
55 #endif
56 struct glsl_variable
57 : public std::conditional_t<utils::is_glsl_layout_v<T>, utils::layout_variable<T>, utils::standard_variable> {
58 public:
59 /// @brief var type
60 using var_type = T;
61 /// @brief size of array
62 static _GLSL_STRUCT_CONSTEXPR17 size_t array_size = Num;
63 /// @brief value indicating if it is array or not
64 static _GLSL_STRUCT_CONSTEXPR17 bool is_array = array_size > 0;
65 /// @brief value indicating if it is layout variable or not
66 static _GLSL_STRUCT_CONSTEXPR17 bool is_layout = utils::is_glsl_layout_v<T>;
67
68 #pragma region VARIABLES
69 /// @brief variable name
70 const std::string varName;
71 #pragma endregion
72
73 #pragma region NORMAL_CONSTRUCTOR
74 /// @brief standard constructor with variable name
76 template<class Type = var_type,
77 std::enable_if_t<utils::is_glsl_simple_v<Type> && std::is_same_v<Type, var_type>, bool> = true>
78 #endif
79 explicit _GLSL_STRUCT_CONSTEXPR20 glsl_variable(
80 const std::string_view name
81 ) noexcept _GLSL_STRUCT_REQUIRES(utils::is_glsl_simple_v<T>)
82 : varName(name) {
83 }
84
85 #pragma endregion
86
87 #pragma region LAYOUT_CONSTRUCTOR
88 /// @brief standard constructor with variable name and layout
90 template<class Type = var_type,
91 std::enable_if_t<utils::is_glsl_layout_v<Type> && std::is_same_v<Type, var_type>, bool> = true>
92 #endif
93 _GLSL_STRUCT_CONSTEXPR20 glsl_variable(const std::string_view name,
94 const T& layout) noexcept _GLSL_STRUCT_REQUIRES(utils::is_glsl_layout_v<T>)
95 : utils::layout_variable<T>(layout), varName(name) {
96 }
97
98 #pragma endregion
99 };
100} // namespace glslstruct
101
102 #endif
103#endif
#define _GLSL_STRUCT_CONSTEXPR20
constexpr keyword for c++20 and higher
Definition config.hpp:213
#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_REQUIRES(condition)
requires keyword for c++20 and higher
Definition config.hpp:214
#define _GLSL_STRUCT_CONSTEXPR17
constexpr for c++17 and higher
Definition config.hpp:196