1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:37:35 +00:00

LibSoftGPU: Add method to copy texels between images

Adds a method `copy_texels()` to class `Image` that copies a rect of
texels from source image to destination.
This commit is contained in:
Stephan Unverwerth 2021-12-23 14:13:09 +01:00 committed by Brian Gianforcaro
parent 5e9d99474d
commit c72a996542
2 changed files with 24 additions and 0 deletions

View file

@ -79,4 +79,27 @@ void Image::read_texels(unsigned layer, unsigned level, Vector3<unsigned> const&
}
}
void Image::copy_texels(Image const& source, unsigned source_layer, unsigned source_level, Vector3<unsigned> const& source_offset, Vector3<unsigned> const& size, unsigned destination_layer, unsigned destination_level, Vector3<unsigned> const& destination_offset)
{
VERIFY(source_layer < source.num_layers());
VERIFY(source_level < source.num_levels());
VERIFY(source_offset.x() + size.x() <= source.level_width(source_level));
VERIFY(source_offset.y() + size.y() <= source.level_height(source_level));
VERIFY(source_offset.z() + size.z() <= source.level_depth(source_level));
VERIFY(destination_layer < num_layers());
VERIFY(destination_level < num_levels());
VERIFY(destination_offset.x() + size.x() <= level_width(destination_level));
VERIFY(destination_offset.y() + size.y() <= level_height(destination_level));
VERIFY(destination_offset.z() + size.z() <= level_depth(destination_level));
for (unsigned z = 0; z < size.z(); ++z) {
for (unsigned y = 0; y < size.y(); ++y) {
for (unsigned x = 0; x < size.x(); ++x) {
auto color = source.texel(source_layer, source_level, source_offset.x() + x, source_offset.y() + y, source_offset.z() + z);
set_texel(destination_layer, destination_level, destination_offset.x() + x, destination_offset.y() + y, destination_offset.z() + z, color);
}
}
}
}
}