Fix GPUTexture::GetData to properly handle volume textures
This commit is contained in:
@@ -545,12 +545,12 @@ public:
|
||||
/// <summary>
|
||||
/// Gets texture mipmap data (raw bytes). Can be used only with textures created with Staging flag.
|
||||
/// </summary>
|
||||
/// <param name="arrayOrDepthSliceIndex">Array or depth slice index.</param>
|
||||
/// <param name="arrayIndex">Array slice index.</param>
|
||||
/// <param name="mipMapIndex">Mip map index.</param>
|
||||
/// <param name="data">Output mip data.</param>
|
||||
/// <param name="mipRowPitch">Output mip data row pitch to use. Use 0 to use the pitch from the internal GPU storage.</param>
|
||||
/// <returns>True if failed, otherwise false.</returns>
|
||||
virtual bool GetData(int32 arrayOrDepthSliceIndex, int32 mipMapIndex, TextureMipData& data, uint32 mipRowPitch = 0) = 0;
|
||||
virtual bool GetData(int32 arrayIndex, int32 mipMapIndex, TextureMipData& data, uint32 mipRowPitch = 0) = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the number of resident mipmap levels in the texture (already uploaded to the GPU).
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -26,6 +26,7 @@ public:
|
||||
|
||||
bool GetPixels(Array<Color32>& pixels, int32 width, int32 height, PixelFormat format) const;
|
||||
bool GetPixels(Array<Color>& pixels, int32 width, int32 height, PixelFormat format) const;
|
||||
void Copy(void* data, uint32 dataRowPitch, uint32 dataDepthPitch, uint32 dataDepthSlices, uint32 targetRowPitch);
|
||||
|
||||
template<typename T>
|
||||
T& Get(int32 x, int32 y)
|
||||
|
||||
Reference in New Issue
Block a user