21class TOAST_API Volume {
24 uint8_t previous_material = k_empty_palette_index;
28 bool brick_became_occupied =
false;
30 bool brick_became_empty =
false;
33 Volume(
BrickPool& pool, glm::uvec3 brick_dims);
37 Volume(
const Volume&) =
delete;
38 auto operator=(
const Volume&) -> Volume& =
delete;
39 Volume(Volume&& other)
noexcept;
40 auto operator=(Volume&& other)
noexcept -> Volume&;
44 static auto instanceOf(
const Volume& source) -> Volume;
47 static auto adoptResized(Volume& source, glm::ivec3 brick_offset, glm::uvec3 brick_dims) -> Volume;
50 auto brickDims() const noexcept -> glm::uvec3 {
55 auto voxelDims() const noexcept -> glm::uvec3 {
56 return m_brick_dims * k_brick_dim;
60 auto brickCount() const noexcept -> uint32_t {
61 return static_cast<uint32_t
>(m_entries.size());
65 auto containsBrick(glm::ivec3 brick)
const noexcept -> bool;
68 auto containsVoxel(glm::ivec3 voxel)
const noexcept -> bool;
71 auto entryAt(glm::ivec3 brick)
const noexcept -> BrickEntry;
74 auto materialAt(glm::ivec3 voxel)
const noexcept -> uint8_t;
77 auto isSolidAt(glm::ivec3 voxel)
const noexcept -> bool;
79 auto setVoxel(glm::ivec3 voxel, uint8_t material) -> VoxelWrite;
81 void setBrickUniform(glm::ivec3 brick, uint8_t material);
83 auto tryCollapseUniform(glm::ivec3 brick) -> bool;
86 auto setBrickMaterial(glm::ivec3 brick, std::span<const uint8_t, k_brick_material_bytes> material) -> bool;
90 auto takeBrick(glm::ivec3 brick) -> BrickEntry;
93 void adoptBrick(glm::ivec3 brick, BrickEntry entry);
96 auto clearVoxels(glm::ivec3 brick,
const BrickOccupancy& mask) -> bool;
102 auto copyBrickFrom(glm::ivec3 brick,
const Volume& source, glm::ivec3 source_brick) -> bool;
105 std::span<uint8_t, k_brick_material_bytes> material;
106 BrickOccupancy* occupancy =
nullptr;
109 auto beginBrickWrite(glm::ivec3 brick) -> std::optional<WritableBrick>;
110 void finishBrickWrite(glm::ivec3 brick,
bool changed);
114 auto occupancyPointer(glm::ivec3 brick)
const noexcept ->
const BrickOccupancy*;
117 auto neighbourhoodOf(glm::ivec3 brick)
const noexcept -> BrickNeighbourhood;
120 auto solidVoxelCount() const -> uint32_t;
123 auto ownedBrickCount() const -> uint32_t;
126 auto sharedBrickCount() const -> uint32_t;
135 auto pool() const noexcept ->
BrickPool* {
141 auto id() const noexcept -> uint64_t {
147 auto dirtyBricksSince(uint32_t revision)
const noexcept -> std::optional<std::span<const uint32_t>>;
150 auto brickAtIndex(uint32_t index)
const noexcept -> glm::ivec3;
153 void discardDirty() const noexcept;
156 void markDirty(glm::ivec3 brick);
159 auto entryIndex(glm::ivec3 brick) const noexcept -> uint32_t;
161 auto makeWritable(uint32_t entry_index) -> uint32_t;
166 glm::uvec3 m_brick_dims {0};
168 std::vector<BrickEntry> m_entries;
170 uint32_t m_revision = 0;
175 mutable std::vector<uint64_t> m_dirty_mask;
176 mutable std::vector<uint32_t> m_dirty_list;
177 mutable uint32_t m_dirty_since = 0;