Skip to content

Commit

Permalink
Rename get_channel_raw => get_channel_as_bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
Zylann committed Jun 9, 2024
1 parent d3fd716 commit 15b2f86
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion editor/vox/vox_mesh_importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ void extract_model_instances(const Data &vox_data, StdVector<ModelInstance> &out
voxels->decompress_channel(VoxelBuffer::CHANNEL_COLOR);

Span<uint8_t> dst_color_indices;
ERR_FAIL_COND(!voxels->get_channel_raw(VoxelBuffer::CHANNEL_COLOR, dst_color_indices));
ERR_FAIL_COND(!voxels->get_channel_as_bytes(VoxelBuffer::CHANNEL_COLOR, dst_color_indices));

CRASH_COND(src_color_indices.size() != dst_color_indices.size());
memcpy(dst_color_indices.data(), src_color_indices.data(), dst_color_indices.size() * sizeof(uint8_t));
Expand Down
2 changes: 1 addition & 1 deletion editor/vox/vox_scene_importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ Error VoxelVoxSceneImporter::_zn_import(const String &p_source_file, const Strin
voxels.decompress_channel(VoxelBuffer::CHANNEL_COLOR);

Span<uint8_t> dst_color_indices;
ERR_FAIL_COND_V(!voxels.get_channel_raw(VoxelBuffer::CHANNEL_COLOR, dst_color_indices), ERR_BUG);
ERR_FAIL_COND_V(!voxels.get_channel_as_bytes(VoxelBuffer::CHANNEL_COLOR, dst_color_indices), ERR_BUG);
Span<const uint8_t> src_color_indices = to_span_const(model.color_indexes);
copy_3d_region_zxy(dst_color_indices, voxels.get_size(), Vector3iUtil::create(VoxelMesherCubes::PADDING),
src_color_indices, model.size, Vector3i(), model.size);
Expand Down
4 changes: 2 additions & 2 deletions generators/graph/voxel_generator_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ void fill_zx_sdf_slice(
out_buffer.decompress_channel(channel);
}
Span<uint8_t> channel_bytes;
ERR_FAIL_COND(!out_buffer.get_channel_raw(channel, channel_bytes));
ERR_FAIL_COND(!out_buffer.get_channel_as_bytes(channel, channel_bytes));
const Vector3i buffer_size = out_buffer.get_size();
const unsigned int x_stride = Vector3iUtil::get_zxy_index(Vector3i(1, 0, 0), buffer_size) -
Vector3iUtil::get_zxy_index(Vector3i(0, 0, 0), buffer_size);
Expand Down Expand Up @@ -434,7 +434,7 @@ void fill_zx_integer_slice(
out_buffer.decompress_channel(channel);
}
Span<uint8_t> channel_bytes;
ERR_FAIL_COND(!out_buffer.get_channel_raw(channel, channel_bytes));
ERR_FAIL_COND(!out_buffer.get_channel_as_bytes(channel, channel_bytes));
const Vector3i buffer_size = out_buffer.get_size();
const unsigned int x_stride = Vector3iUtil::get_zxy_index(Vector3i(1, 0, 0), buffer_size) -
Vector3iUtil::get_zxy_index(Vector3i(0, 0, 0), buffer_size);
Expand Down
2 changes: 1 addition & 1 deletion meshers/blocky/voxel_mesher_blocky.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ void VoxelMesherBlocky::build(VoxelMesher::Output &output, const VoxelMesher::In
}

Span<const uint8_t> raw_channel;
if (!voxels.get_channel_raw_read_only(channel, raw_channel)) {
if (!voxels.get_channel_as_bytes_read_only(channel, raw_channel)) {
// Case supposedly handled before...
ERR_PRINT("Something wrong happened");
return;
Expand Down
2 changes: 1 addition & 1 deletion meshers/cubes/voxel_mesher_cubes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ void VoxelMesherCubes::build(VoxelMesher::Output &output, const VoxelMesher::Inp
}

Span<uint8_t> raw_channel;
if (!voxels.get_channel_raw(channel, raw_channel)) {
if (!voxels.get_channel_as_bytes(channel, raw_channel)) {
// Case supposedly handled before...
ERR_PRINT("Something wrong happened");
return;
Expand Down
8 changes: 4 additions & 4 deletions meshers/transvoxel/transvoxel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1373,7 +1373,7 @@ Span<const T> get_or_decompress_channel(const VoxelBuffer &voxels, StdVector<T>

} else {
Span<uint8_t> data_bytes;
ZN_ASSERT(voxels.get_channel_raw(channel, data_bytes) == true);
ZN_ASSERT(voxels.get_channel_as_bytes(channel, data_bytes) == true);
return data_bytes.reinterpret_cast_to<const T>();
}
}
Expand All @@ -1398,7 +1398,7 @@ TextureIndicesData get_texture_indices_data(

} else {
Span<uint8_t> data_bytes;
ZN_ASSERT(voxels.get_channel_raw(channel, data_bytes) == true);
ZN_ASSERT(voxels.get_channel_as_bytes(channel, data_bytes) == true);
data.buffer = data_bytes.reinterpret_cast_to<const uint16_t>();

out_default_texture_indices_data.use = false;
Expand Down Expand Up @@ -1499,7 +1499,7 @@ DefaultTextureIndicesData build_regular_mesh(
// From this point, we expect the buffer to contain allocated data in the relevant channels.

Span<uint8_t> sdf_data_raw;
ZN_ASSERT(voxels.get_channel_raw(sdf_channel, sdf_data_raw) == true);
ZN_ASSERT(voxels.get_channel_as_bytes(sdf_channel, sdf_data_raw) == true);

const unsigned int voxels_count = Vector3iUtil::get_volume(voxels.get_size());

Expand Down Expand Up @@ -1619,7 +1619,7 @@ void build_transition_mesh(
// From this point, we expect the buffer to contain allocated data in the relevant channels.

Span<uint8_t> sdf_data_raw;
ZN_ASSERT(voxels.get_channel_raw(sdf_channel, sdf_data_raw) == true);
ZN_ASSERT(voxels.get_channel_as_bytes(sdf_channel, sdf_data_raw) == true);

const unsigned int voxels_count = Vector3iUtil::get_volume(voxels.get_size());

Expand Down
6 changes: 3 additions & 3 deletions storage/voxel_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ void VoxelBuffer::move_to(VoxelBuffer &dst) {
}
}

bool VoxelBuffer::get_channel_raw(unsigned int channel_index, Span<uint8_t> &slice) const {
bool VoxelBuffer::get_channel_as_bytes(unsigned int channel_index, Span<uint8_t> &slice) const {
const Channel &channel = _channels[channel_index];
if (channel.compression != COMPRESSION_UNIFORM) {
#ifdef DEV_ENABLED
Expand All @@ -730,9 +730,9 @@ bool VoxelBuffer::get_channel_raw(unsigned int channel_index, Span<uint8_t> &sli
return false;
}

bool VoxelBuffer::get_channel_raw_read_only(unsigned int channel_index, Span<const uint8_t> &slice) const {
bool VoxelBuffer::get_channel_as_bytes_read_only(unsigned int channel_index, Span<const uint8_t> &slice) const {
Span<uint8_t> slice_w;
const bool success = get_channel_raw(channel_index, slice_w);
const bool success = get_channel_as_bytes(channel_index, slice_w);
slice = slice_w;
return success;
}
Expand Down
6 changes: 3 additions & 3 deletions storage/voxel_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -435,13 +435,13 @@ class VoxelBuffer {
return Vector3iUtil::get_volume(_size);
}

bool get_channel_raw(unsigned int channel_index, Span<uint8_t> &slice) const;
bool get_channel_raw_read_only(unsigned int channel_index, Span<const uint8_t> &slice) const;
bool get_channel_as_bytes(unsigned int channel_index, Span<uint8_t> &slice) const;
bool get_channel_as_bytes_read_only(unsigned int channel_index, Span<const uint8_t> &slice) const;

template <typename T>
bool get_channel_data(unsigned int channel_index, Span<T> &dst) const {
Span<uint8_t> dst8;
ZN_ASSERT_RETURN_V(get_channel_raw(channel_index, dst8), false);
ZN_ASSERT_RETURN_V(get_channel_as_bytes(channel_index, dst8), false);
dst = dst8.reinterpret_cast_to<T>();
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion storage/voxel_buffer_gd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void VoxelBuffer::remap_values(unsigned int channel_index, PackedInt32Array map)
switch (depth) {
case zylann::voxel::VoxelBuffer::DEPTH_8_BIT: {
Span<uint8_t> values;
ZN_ASSERT_RETURN(_buffer->get_channel_raw(channel_index, values));
ZN_ASSERT_RETURN(_buffer->get_channel_as_bytes(channel_index, values));
for (uint8_t &v : values) {
if (v < map_r.size()) {
v = map_r[v];
Expand Down
2 changes: 1 addition & 1 deletion streams/vox/vox_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ int /*Error*/ VoxelVoxLoader::load_from_file(
Span<uint8_t> dst_raw;
voxels.create(model.size);
voxels.decompress_channel(dst_channel);
CRASH_COND(!voxels.get_channel_raw(dst_channel, dst_raw));
CRASH_COND(!voxels.get_channel_as_bytes(dst_channel, dst_raw));

if (palette.is_valid()) {
for (size_t i = 0; i < src_palette.size(); ++i) {
Expand Down
6 changes: 4 additions & 2 deletions streams/voxel_block_serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,9 @@ SerializeResult serialize(const VoxelBuffer &voxel_buffer) {
switch (compression) {
case VoxelBuffer::COMPRESSION_NONE: {
Span<uint8_t> data;
ERR_FAIL_COND_V(!voxel_buffer.get_channel_raw(channel_index, data), SerializeResult(dst_data, false));
ERR_FAIL_COND_V(
!voxel_buffer.get_channel_as_bytes(channel_index, data), SerializeResult(dst_data, false)
);
f.store_buffer(data);
} break;

Expand Down Expand Up @@ -639,7 +641,7 @@ bool deserialize(Span<const uint8_t> p_data, VoxelBuffer &out_voxel_buffer) {
out_voxel_buffer.decompress_channel(channel_index);

Span<uint8_t> buffer;
CRASH_COND(!out_voxel_buffer.get_channel_raw(channel_index, buffer));
CRASH_COND(!out_voxel_buffer.get_channel_as_bytes(channel_index, buffer));

const size_t read_len = f.get_buffer(buffer);
if (read_len != buffer.size()) {
Expand Down

0 comments on commit 15b2f86

Please sign in to comment.