2
3
4
5
6
7
8
11#ifndef _GLSL_STRUCT_BASE_LAYOUT_HPP_
12 #define _GLSL_STRUCT_BASE_LAYOUT_HPP_
14 #include <glslstruct/config.hpp>
17_GLSL_STRUCT_ERROR(
"This is only available for c++17 and greater!");
20 #include <glslstruct/types.hpp>
22 #include <glslstruct/layout/traits/concept.hpp>
24 #include <glslstruct/type/containers/array_type.hpp>
25 #include <glslstruct/type/containers/mat_type.hpp>
26 #include <glslstruct/type/containers/scalar_type.hpp>
27 #include <glslstruct/type/containers/struct_type.hpp>
28 #include <glslstruct/type/containers/vec_type.hpp>
29 #include <glslstruct/type/visitors/is_of_type_visitor.hpp>
31 #include <glslstruct/utils/assert.hpp>
32 #include <glslstruct/utils/functions.hpp>
33 #include <glslstruct/utils/hash.hpp>
34 #include <glslstruct/utils/ValueType.hpp>
35 #include <glslstruct/var_data/var_data.hpp>
36 #include <glslstruct/variable/glsl_variable.hpp>
41
42
43
44
45 template<
class Traits>
58 std::enable_if_t<std::is_default_constructible_v<context_type> && std::is_same_v<C, context_type>,
bool> =
true>
61 std::is_default_constructible_v<context_type>
71
72
73
78
79
80
81
108 #pragma region VARIABLE_SET
131 const size_t baseAlignment)
noexcept {
146 const size_t baseAlignment)
noexcept {
152 const size_t distance)
noexcept {
160 #pragma region COMMON_CHECKS
182 const mstd::ordered_map<std::string, var_data>& values
193 #pragma region STANDARD_ADD
197 const size_t baseOffset)
noexcept {
235 #pragma region VARIABLE_ADD
375 #pragma region BEFORE_ADD_EVENTS
444 #pragma region AFTER_ADD_EVENTS
515 #pragma region GET_ALIGNMENT
558 #pragma region SPECIALIZED_ADD
643 const ValueType valueType) {
983 #pragma region CONSTRUCTORS_WITHOUT_CONTEXT
993 std::is_default_constructible_v<base_struct>))
1006 )
noexcept _GLSL_STRUCT_REQUIRES(!has_context || (has_context && std::is_default_constructible_v<base_struct>))
1013 #pragma region CONSTRUCTORS_WITH_CONTEXT
1089 if (
i != 0) {
return i; }
1133 #if _GLSL_STRUCT_HAS_CXX20
1202 #pragma region ADD_SCALAR
1207 template<
class S, std::enable_if_t<is_glsl_scalar_v<S>,
bool> =
true>
1215 #pragma region ADD_SCALARS_ARRAY
1221 template<
class S, std::enable_if_t<is_glsl_scalar_v<S>,
bool> =
true>
1250 #pragma region ADD_VEC
1263 #pragma region ADD_VECS_ARRAY
1298 #pragma region ADD_MAT
1311 #pragma region ADD_MATS_ARRAY
1346 #pragma region ADD_STRUCT
1355 #pragma region ADD_STRUCTS_ARRAY
1376 return !(*
this ==
other);
1383
1384
1385
1386
1387template<
class Traits>
1388struct std::hash<glslstruct::base_layout<Traits> > {
1390 size_t seed = std::hash<size_t> {}(layout._currentOffset);
1392 glslstruct::utils::is_hashable_v<
typename glslstruct::base_layout<Traits>::context_type>) {
1393 mstd::hash_append(seed, layout._context);
1395 for (
const auto& [name, data] : layout._variables) { mstd::hash_append(seed, name, data); }
base layout container
Definition base_layout.hpp:88
_GLSL_STRUCT_CONSTEXPR20 const mstd::ordered_map< std::string, var_data > & get_variables() const noexcept
returns all variables and their data
Definition base_layout.hpp:1173
_GLSL_STRUCT_CONSTEXPR20 std::vector< std::string > get_names() const noexcept
returns all variables names
Definition base_layout.hpp:1159
_GLSL_STRUCT_CONSTEXPR17 size_t add(const std::string_view name)
adds scalar
Definition base_layout.hpp:1209
_GLSL_STRUCT_CONSTEXPR17 var_data & _add_variable(const std::string_view name, const size_t alignmentOffset, const bool isTopLevel, const base_type_handle &type)
sets variable data
Definition base_layout.hpp:238
_GLSL_STRUCT_CONSTEXPR17 size_t get_array_count(const std::string_view name) const noexcept
returns array count (if single value then returns 1 else if value doesn't exist returns 0 else array ...
Definition base_layout.hpp:1072
_GLSL_STRUCT_CONSTEXPR17 void _before_add_struct()
calls before add struct event
Definition base_layout.hpp:432
_GLSL_STRUCT_CONSTEXPR17 var_data & _add_mat_variable(const std::string_view name, const std::vector< size_t > &alignmentOffsets, const bool isTopLevel, const ValueType valueType, const size_t columns, const size_t rows, const size_t vecBaseOffset, const size_t matBaseOffset)
sets mat variable
Definition base_layout.hpp:313
_GLSL_STRUCT_CONSTEXPR17 size_t get_array_elem_size(const std::string_view name) const noexcept
returns elem size of array
Definition base_layout.hpp:1095
static _GLSL_STRUCT_CONSTEXPR17 size_t _calculate_padding(const size_t currentOffset, const size_t baseAlignment) noexcept
returns padding value
Definition base_layout.hpp:145
_GLSL_STRUCT_CONSTEXPR17 size_t _add_vec(const std::string_view name, const size_t length, const ValueType valueType)
adds vec
Definition base_layout.hpp:642
_GLSL_STRUCT_CONSTEXPR17 size_t get_offset(const std::string_view name) const noexcept
returns offset of variable with given name
Definition base_layout.hpp:1106
_GLSL_STRUCT_CONSTEXPR17 size_t get_total_size(const std::string_view name) const noexcept
returns total size of variable (size + padding)
Definition base_layout.hpp:1144
static _GLSL_STRUCT_CONSTEXPR20 std::vector< size_t > _add_array(size_t ¤tOffset, const size_t arrayBaseAlignment, const size_t elemBaseOffset, const size_t count) noexcept
returns alignment offsets of array variables and moves current offset
Definition base_layout.hpp:213
static _GLSL_STRUCT_CONSTEXPR17 bool _is_struct_not_empty(const mstd::ordered_map< std::string, var_data > &values) noexcept
checks if struct is not empty
Definition base_layout.hpp:181
_GLSL_STRUCT_CONSTEXPR17 void _before_add_scalar()
calls before add scalar event
Definition base_layout.hpp:399
_GLSL_STRUCT_CONSTEXPR20 std::vector< size_t > _add_vec_array(const std::string_view name, const size_t length, const ValueType valueType, const size_t count)
adds array of vecs
Definition base_layout.hpp:679
_GLSL_STRUCT_CONSTEXPR17 base_layout & operator=(const base_layout &other) noexcept=default
default copy assign operator
Traits traits_type
traits type
Definition base_layout.hpp:91
_GLSL_STRUCT_CONSTEXPR17 void _after_add(const size_t baseOffset, const size_t baseAlignment)
calls after add event
Definition base_layout.hpp:447
_GLSL_STRUCT_CONSTEXPR20 std::vector< size_t > add(const std::string_view name, const size_t count)
adds array of scalars
Definition base_layout.hpp:1223
_GLSL_STRUCT_CONSTEXPR17 size_t _get_scalar_alignment(const ValueType valueType)
returns scalar alignment
Definition base_layout.hpp:526
_GLSL_STRUCT_CONSTEXPR17 void clear() noexcept
clears layout and all variables
Definition base_layout.hpp:1197
_GLSL_STRUCT_CONSTEXPR17 void _after_add_mat(const size_t baseOffset, const size_t baseAlignment)
calls after add mat event
Definition base_layout.hpp:490
_GLSL_STRUCT_CONSTEXPR17 void _after_add_struct(const size_t baseOffset, const size_t baseAlignment)
calls after add struct event
Definition base_layout.hpp:503
static _GLSL_STRUCT_CONSTEXPR17 size_t _add(size_t ¤tOffset, const size_t baseAlignment, const size_t baseOffset) noexcept
returns alignment offset of variable and moves current offset
Definition base_layout.hpp:196
_GLSL_STRUCT_CONSTEXPR17 void _after_add_array(const size_t baseOffset, const size_t baseAlignment)
calls after add array event
Definition base_layout.hpp:457
static _GLSL_STRUCT_CONSTEXPR17 bool has_context
value indicating if traits has context defined
Definition base_layout.hpp:94
_GLSL_STRUCT_CONSTEXPR17 size_t _add_scalar(const std::string_view name, const ValueType valueType)
adds scalar
Definition base_layout.hpp:561
static _GLSL_STRUCT_CONSTEXPR17 size_t _calculate_alignment_offset(const size_t currentOffset, const size_t baseAlignment) noexcept
calculates alignment offset
Definition base_layout.hpp:130
mstd::ordered_map< std::string, var_data > _variables
variables data
Definition base_layout.hpp:104
_GLSL_STRUCT_CONSTEXPR17 size_t _get_scalar_array_alignment(const ValueType valueType)
returns array of scalars alignment
Definition base_layout.hpp:534
_GLSL_STRUCT_CONSTEXPR17 void _after_add_vec(const size_t baseOffset, const size_t baseAlignment)
calls after add vec event
Definition base_layout.hpp:479
_GLSL_STRUCT_CONSTEXPR17 size_t get_size(const std::string_view name) const noexcept
returns size of variable
Definition base_layout.hpp:1149
_GLSL_STRUCT_CONSTEXPR20 std::vector< size_t > _add_mat(const std::string_view name, const size_t columns, const size_t rows, const ValueType valueType)
adds mat
Definition base_layout.hpp:730
_GLSL_STRUCT_CONSTEXPR17 size_t _get_array_alignment(const size_t elemBaseAlignment)
returns array of elements alignment
Definition base_layout.hpp:518
_GLSL_STRUCT_CONSTEXPR20 std::vector< size_t > get_array_offsets(const std::string_view name) const noexcept
returns offsets of array elements
Definition base_layout.hpp:1111
_GLSL_STRUCT_CONSTEXPR17 size_t _get_mat_alignment(const ValueType valueType, const size_t rows)
returns mat alignment
Definition base_layout.hpp:552
static _GLSL_STRUCT_CONSTEXPR17 bool _is_array_count_good(const size_t count)
checks if array count is not zero
Definition base_layout.hpp:172
_GLSL_STRUCT_CONSTEXPR17 size_t _get_vec_alignment(const ValueType valueType, const size_t length)
returns vec alignment
Definition base_layout.hpp:539
_GLSL_STRUCT_CONSTEXPR17 void _before_add_vec()
calls before add vec event
Definition base_layout.hpp:410
_GLSL_STRUCT_CONSTEXPR20 ~base_layout() noexcept=default
default destructor
static _GLSL_STRUCT_CONSTEXPR17 bool _move_current_offset(size_t ¤tOffset, const size_t distance) noexcept
moves current offset to end of variable
Definition base_layout.hpp:151
_GLSL_STRUCT_CONSTEXPR17 var_data & _set_variable(const std::string_view name, const size_t offset, const base_type_handle &type, const bool isTopLevel, const size_t padding=0)
sets variable data
Definition base_layout.hpp:111
_GLSL_STRUCT_CONSTEXPR17 const var_data & get(const std::string_view name) const noexcept
returns variable data
Definition base_layout.hpp:1062
_GLSL_STRUCT_CONSTEXPR17 size_t size() const noexcept
returns size of layout
Definition base_layout.hpp:1194
size_t _currentOffset
current offset
Definition base_layout.hpp:106
_GLSL_STRUCT_CONSTEXPR17 base_layout(base_layout &&other) noexcept=default
default move constructor
_GLSL_STRUCT_CONSTEXPR20 std::vector< size_t > _add_scalar_array(const std::string_view name, const ValueType valueType, const size_t count)
adds array of scalars
Definition base_layout.hpp:594
static _GLSL_STRUCT_CONSTEXPR17 size_t bad_offset() noexcept
value indicating error while returning offset
Definition base_layout.hpp:1054
_GLSL_STRUCT_CONSTEXPR17 void _after_add_scalar(const size_t baseOffset, const size_t baseAlignment)
calls after add scalar event
Definition base_layout.hpp:468
var_data & _add_mat_array_variable(const std::string_view name, const std::vector< std::vector< size_t > > &alignmentOffsets, const bool isTopLevel, const size_t count, const ValueType valueType, const size_t columns, const size_t rows, const size_t vecBaseOffset, const size_t matBaseOffset, const size_t arrayBaseOffset, const size_t matPadding)
sets array of mats variable
Definition base_layout.hpp:331
_GLSL_STRUCT_CONSTEXPR17 size_t _get_vec_array_alignment(const ValueType valueType, const size_t length)
returns array of vecs alignment
Definition base_layout.hpp:547
mstd::ordered_map< std::string, var_data > get_top_level_variables() const noexcept
returns all top level variables and their data
Definition base_layout.hpp:1178
_GLSL_STRUCT_CONSTEXPR17 size_t base_alignment() const noexcept
returns base alignment of layout
Definition base_layout.hpp:1188
static _GLSL_STRUCT_CONSTEXPR17 bool _is_vec_length_good(const size_t length) noexcept
checks if vec length is between 2 and 4
Definition base_layout.hpp:163
_GLSL_STRUCT_CONSTEXPR17 void _before_add_mat()
calls before add mat event
Definition base_layout.hpp:421
_GLSL_STRUCT_CONSTEXPR17 base_layout & operator=(base_layout &&other) noexcept=default
default move assign operator
_GLSL_STRUCT_CONSTEXPR17 var_data & _add_array_variable(const std::string_view name, const std::vector< size_t > &alignmentOffsets, const bool isTopLevel, const base_type_handle &elemType, const base_type_handle &arrayType)
sets array variables data
Definition base_layout.hpp:261
_GLSL_STRUCT_CONSTEXPR17 size_t get_padding(const std::string_view name) const noexcept
returns padding of variable
Definition base_layout.hpp:1154
_GLSL_STRUCT_CONSTEXPR17 bool contains(const std::string_view name) const noexcept
returns true if layout contains variable with given name
Definition base_layout.hpp:1057
_GLSL_STRUCT_CONSTEXPR17 void _before_add_array()
calls before add array event
Definition base_layout.hpp:388
_GLSL_STRUCT_CONSTEXPR17 void _before_add()
calls before add event
Definition base_layout.hpp:378
#define _GLSL_STRUCT_TYPENAME17
Definition config.hpp:216
#define _GLSL_STRUCT_EXPORT
This is for exporting symbols in shared library setup.
Definition config.hpp:251
#define _GLSL_STRUCT_CONSTEXPR20
constexpr keyword for c++20 and higher
Definition config.hpp:213
#define glsl_struct_assert(expression,...)
glslstruct assert
Definition assert.hpp:33
#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_HAS_TYPES
check if user not disabled type containers using GLSL_STRUCT_DISABLE_TYPES
Definition config.hpp:162
#define _GLSL_STRUCT_CONSTEXPR17
constexpr for c++17 and higher
Definition config.hpp:196
Main namespace of glslstruct library.
Definition contexts.hpp:20
Context container for layout.
Definition base_layout.hpp:46
_GLSL_STRUCT_CONSTEXPR17 layout_with_context(const context_type &ctx)
constructor with context value
Definition base_layout.hpp:67
context_type _context
context value
Definition base_layout.hpp:52
_GLSL_STRUCT_CONSTEXPR17 layout_with_context() noexcept _GLSL_STRUCT_REQUIRES(std
default constructor
Definition base_layout.hpp:60
_GLSL_STRUCT_TYPENAME17 Traits::context_type context_type
context type
Definition base_layout.hpp:48
empty container for layout
Definition base_layout.hpp:74