Toast Engine
Toggle main menu visibility
Loading...
Searching...
No Matches
voxel_constants.hpp
Go to the documentation of this file.
1
6
7
#pragma once
8
9
#include <cstdint>
10
11
namespace
voxel {
12
13
inline
constexpr
float
k_voxel_size = 0.1f;
14
15
inline
constexpr
uint32_t k_brick_dim = 8;
16
17
inline
constexpr
uint32_t k_brick_voxel_count = k_brick_dim * k_brick_dim * k_brick_dim;
18
19
inline
constexpr
float
k_brick_size =
static_cast<
float
>
(k_brick_dim) * k_voxel_size;
20
21
inline
constexpr
uint32_t k_region_dim_bricks = 32;
22
23
inline
constexpr
uint32_t k_region_dim_voxels = k_region_dim_bricks * k_brick_dim;
24
25
inline
constexpr
float
k_region_size =
static_cast<
float
>
(k_region_dim_bricks) * k_brick_size;
26
27
inline
constexpr
uint32_t k_palette_size = 256;
28
29
inline
constexpr
uint8_t k_empty_palette_index = 0;
30
31
enum class
BrickTag
: uint8_t {
32
empty = 0,
34
uniform
= 1,
36
shared
= 2,
37
owned = 3,
38
};
39
40
inline
constexpr
uint32_t k_brick_tag_bits = 2;
41
42
inline
constexpr
uint32_t k_brick_payload_mask = (1u << (32 - k_brick_tag_bits)) - 1u;
43
44
struct
BrickEntry
{
45
uint32_t value = 0;
46
47
[[nodiscard]]
48
static
constexpr
auto
make(
BrickTag
tag, uint32_t
payload
)
noexcept
->
BrickEntry
{
49
return
BrickEntry
{(
payload
& k_brick_payload_mask) << k_brick_tag_bits |
static_cast<
uint32_t
>
(tag)};
50
}
51
52
[[nodiscard]]
53
constexpr
auto
tag()
const
noexcept
->
BrickTag
{
54
return
static_cast<
BrickTag
>
(value & ((1u << k_brick_tag_bits) - 1u));
55
}
56
58
[[nodiscard]]
59
constexpr
auto
payload
() const noexcept -> uint32_t {
60
return
value >> k_brick_tag_bits;
61
}
62
63
[[nodiscard]]
64
constexpr
auto
isPooled() const noexcept ->
bool
{
65
const
auto
t = tag();
66
return
t ==
BrickTag::shared
|| t == BrickTag::owned;
67
}
68
69
[[nodiscard]]
70
constexpr
auto
operator==(
const
BrickEntry&)
const
noexcept
->
bool
=
default
;
71
};
72
73
static_assert
(k_brick_dim * k_brick_dim == 64,
"a brick z-slice must be exactly 64 bits"
);
74
static_assert
(k_brick_voxel_count == 512,
"a brick must be 512 voxels"
);
75
static_assert
(
sizeof
(
BrickEntry
) == 4,
"an indirection entry must be four bytes"
);
76
static_assert
(
BrickEntry
{}.tag() == BrickTag::empty,
"a zeroed indirection grid must read as empty"
);
77
78
}
assets::BrickEntry::payload
constexpr auto payload() const noexcept -> uint32_t
Definition
voxel_constants.hpp:59
voxel::BrickEntry
Definition
voxel_constants.hpp:44
voxel::BrickEntry::payload
constexpr auto payload() const noexcept -> uint32_t
Definition
voxel_constants.hpp:59
voxel::BrickTag
BrickTag
Definition
voxel_constants.hpp:31
voxel::BrickTag::shared
@ shared
Owned by the source asset so copy before writing.
Definition
voxel_constants.hpp:36
voxel::BrickTag::uniform
@ uniform
The payload is a palette index not a brick id.
Definition
voxel_constants.hpp:34
engine
src
toast
voxel
voxel_constants.hpp
Generated by
1.17.0