Fix GPUTexture::GetData to properly handle volume textures

This commit is contained in:
Wojtek Figat
2024-05-28 14:56:04 +02:00
parent 054e77be42
commit 8a2acd360d
10 changed files with 49 additions and 118 deletions

View File

@@ -169,6 +169,38 @@ bool TextureMipData::GetPixels(Array<Color>& pixels, int32 width, int32 height,
return false;
}
void TextureMipData::Copy(void* data, uint32 dataRowPitch, uint32 dataDepthPitch, uint32 dataDepthSlices, uint32 targetRowPitch)
{
// Check if target row pitch is the same
if (targetRowPitch == dataRowPitch || targetRowPitch == 0)
{
Lines = dataDepthPitch / dataRowPitch;
DepthPitch = dataDepthPitch;
RowPitch = dataRowPitch;
// Single memory copy
Data.Copy((byte*)data, dataDepthPitch * dataDepthSlices);
}
else
{
Lines = dataDepthPitch / dataRowPitch;
DepthPitch = targetRowPitch * Lines;
RowPitch = targetRowPitch;
// Convert row by row
Data.Allocate(DepthPitch * dataDepthSlices);
for (uint32 depth = 0; depth < dataDepthSlices; depth++)
{
byte* src = (byte*)data + depth * dataDepthPitch;
byte* dst = Data.Get() + depth * DepthPitch;
for (uint32 row = 0; row < Lines; row++)
{
Platform::MemoryCopy(dst + row * RowPitch, src + row * dataRowPitch, RowPitch);
}
}
}
}
REGISTER_BINARY_ASSET_ABSTRACT(TextureBase, "FlaxEngine.TextureBase");
TextureBase::TextureBase(const SpawnParams& params, const AssetInfo* info)