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/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/ValueType.hpp>
34 #include <glslstruct/var_data/var_data.hpp>
35 #include <glslstruct/variable/glsl_variable.hpp>
40
41
42
43
44 template<
class Traits>
57 std::enable_if_t<std::is_default_constructible_v<context_type> && std::is_same_v<C, context_type>,
bool> =
true>
60 std::is_default_constructible_v<context_type>
70
71
72
77
78
79
80
107 #pragma region VARIABLE_SET
130 const size_t baseAlignment)
noexcept {
145 const size_t baseAlignment)
noexcept {
151 const size_t distance)
noexcept {
159 #pragma region COMMON_CHECKS
181 const mstd::ordered_map<std::string, var_data>& values
192 #pragma region STANDARD_ADD
196 const size_t baseOffset)
noexcept {
234 #pragma region VARIABLE_ADD
374 #pragma region BEFORE_ADD_EVENTS
443 #pragma region AFTER_ADD_EVENTS
514 #pragma region GET_ALIGNMENT
557 #pragma region SPECIALIZED_ADD
642 const ValueType valueType) {
982 #pragma region CONSTRUCTORS_WITHOUT_CONTEXT
992 std::is_default_constructible_v<base_struct>))
1005 )
noexcept _GLSL_STRUCT_REQUIRES(!has_context || (has_context && std::is_default_constructible_v<base_struct>))
1012 #pragma region CONSTRUCTORS_WITH_CONTEXT
1088 if (
i != 0) {
return i; }
1132 #if _GLSL_STRUCT_HAS_CXX20
1201 #pragma region ADD_SCALAR
1214 #pragma region ADD_SCALARS_ARRAY
1249 #pragma region ADD_VEC
1262 #pragma region ADD_VECS_ARRAY
1297 #pragma region ADD_MAT
1310 #pragma region ADD_MATS_ARRAY
1345 #pragma region ADD_STRUCT
1354 #pragma region ADD_STRUCTS_ARRAY
1375 return !(*
this ==
other);
1382
1383
1384
1385
1386template<
class Traits>
1387struct std::hash<glslstruct::base_layout<Traits> > {
1389 size_t seed = mstd::hash_combine(layout._currentOffset, layout._maxAlignment);
1390 for (
const auto& [name, data] : layout._variables) { mstd::hash_append(seed, name, data); }
base layout container
Definition base_layout.hpp:87
_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:1172
_GLSL_STRUCT_CONSTEXPR20 std::vector< std::string > get_names() const noexcept
returns all variables names
Definition base_layout.hpp:1158
_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:237
_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:1071
_GLSL_STRUCT_CONSTEXPR17 void _before_add_struct()
calls before add struct event
Definition base_layout.hpp:431
_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:312
_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:1094
static _GLSL_STRUCT_CONSTEXPR17 size_t _calculate_padding(const size_t currentOffset, const size_t baseAlignment) noexcept
returns padding value
Definition base_layout.hpp:144
_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:641
_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:1105
_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:1143
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:212
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:180
_GLSL_STRUCT_CONSTEXPR17 void _before_add_scalar()
calls before add scalar event
Definition base_layout.hpp:398
_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:678
_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:90
_GLSL_STRUCT_CONSTEXPR17 void _after_add(const size_t baseOffset, const size_t baseAlignment)
calls after add event
Definition base_layout.hpp:446
_GLSL_STRUCT_CONSTEXPR17 size_t _get_scalar_alignment(const ValueType valueType)
returns scalar alignment
Definition base_layout.hpp:525
_GLSL_STRUCT_CONSTEXPR17 void clear() noexcept
clears layout and all variables
Definition base_layout.hpp:1196
_GLSL_STRUCT_CONSTEXPR17 void _after_add_mat(const size_t baseOffset, const size_t baseAlignment)
calls after add mat event
Definition base_layout.hpp:489
_GLSL_STRUCT_CONSTEXPR17 void _after_add_struct(const size_t baseOffset, const size_t baseAlignment)
calls after add struct event
Definition base_layout.hpp:502
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:195
_GLSL_STRUCT_CONSTEXPR17 void _after_add_array(const size_t baseOffset, const size_t baseAlignment)
calls after add array event
Definition base_layout.hpp:456
static _GLSL_STRUCT_CONSTEXPR17 bool has_context
value indicating if traits has context defined
Definition base_layout.hpp:93
_GLSL_STRUCT_CONSTEXPR17 size_t _add_scalar(const std::string_view name, const ValueType valueType)
adds scalar
Definition base_layout.hpp:560
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:129
mstd::ordered_map< std::string, var_data > _variables
variables data
Definition base_layout.hpp:103
_GLSL_STRUCT_CONSTEXPR17 size_t _get_scalar_array_alignment(const ValueType valueType)
returns array of scalars alignment
Definition base_layout.hpp:533
_GLSL_STRUCT_CONSTEXPR17 void _after_add_vec(const size_t baseOffset, const size_t baseAlignment)
calls after add vec event
Definition base_layout.hpp:478
_GLSL_STRUCT_CONSTEXPR17 size_t get_size(const std::string_view name) const noexcept
returns size of variable
Definition base_layout.hpp:1148
_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:729
_GLSL_STRUCT_CONSTEXPR17 size_t _get_array_alignment(const size_t elemBaseAlignment)
returns array of elements alignment
Definition base_layout.hpp:517
_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:1110
_GLSL_STRUCT_CONSTEXPR17 size_t _get_mat_alignment(const ValueType valueType, const size_t rows)
returns mat alignment
Definition base_layout.hpp:551
static _GLSL_STRUCT_CONSTEXPR17 bool _is_array_count_good(const size_t count)
checks if array count is not zero
Definition base_layout.hpp:171
_GLSL_STRUCT_CONSTEXPR17 size_t _get_vec_alignment(const ValueType valueType, const size_t length)
returns vec alignment
Definition base_layout.hpp:538
_GLSL_STRUCT_CONSTEXPR17 void _before_add_vec()
calls before add vec event
Definition base_layout.hpp:409
_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:150
_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:110
_GLSL_STRUCT_CONSTEXPR17 const var_data & get(const std::string_view name) const noexcept
returns variable data
Definition base_layout.hpp:1061
_GLSL_STRUCT_CONSTEXPR17 size_t size() const noexcept
returns size of layout
Definition base_layout.hpp:1193
size_t _currentOffset
current offset
Definition base_layout.hpp:105
_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:593
static _GLSL_STRUCT_CONSTEXPR17 size_t bad_offset() noexcept
value indicating error while returning offset
Definition base_layout.hpp:1053
_GLSL_STRUCT_CONSTEXPR17 void _after_add_scalar(const size_t baseOffset, const size_t baseAlignment)
calls after add scalar event
Definition base_layout.hpp:467
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:330
_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:546
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:1177
_GLSL_STRUCT_CONSTEXPR17 size_t base_alignment() const noexcept
returns base alignment of layout
Definition base_layout.hpp:1187
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:162
_GLSL_STRUCT_CONSTEXPR17 void _before_add_mat()
calls before add mat event
Definition base_layout.hpp:420
_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:260
_GLSL_STRUCT_CONSTEXPR17 size_t get_padding(const std::string_view name) const noexcept
returns padding of variable
Definition base_layout.hpp:1153
_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:1056
_GLSL_STRUCT_CONSTEXPR17 void _before_add_array()
calls before add array event
Definition base_layout.hpp:387
_GLSL_STRUCT_CONSTEXPR17 void _before_add()
calls before add event
Definition base_layout.hpp:377
#define _GLSL_STRUCT_TYPENAME17
Definition config.hpp:216
#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 scalar_layout_traits.hpp:23
Context container for layout.
Definition base_layout.hpp:45
_GLSL_STRUCT_CONSTEXPR17 layout_with_context(const context_type &ctx)
constructor with context value
Definition base_layout.hpp:66
context_type _context
context value
Definition base_layout.hpp:51
_GLSL_STRUCT_CONSTEXPR17 layout_with_context() noexcept _GLSL_STRUCT_REQUIRES(std
default constructor
Definition base_layout.hpp:59
_GLSL_STRUCT_TYPENAME17 Traits::context_type context_type
context type
Definition base_layout.hpp:47
empty container for layout
Definition base_layout.hpp:73