MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / GetTextureData

Method GetTextureData

Source/Engine/Graphics/Textures/TextureBase.cpp:349–397  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

347}
348
349bool TextureBase::GetTextureData(TextureData& result, bool copyData)
350{
351 PROFILE_CPU_NAMED("Texture.GetTextureData");
352 if (!IsVirtual() && WaitForLoaded())
353 {
354 LOG(Error, "Asset load failed.");
355 return true;
356 }
357 auto dataLock = LockData();
358
359 // Setup description
360 result.Width = _texture.TotalWidth();
361 result.Height = _texture.TotalHeight();
362 result.Depth = 1;
363 result.Format = _texture.GetHeader()->Format;
364 result.Items.Resize(_texture.TotalArraySize());
365
366 // Setup mips data
367 for (int32 arraySlice = 0; arraySlice < result.Items.Count(); arraySlice++)
368 {
369 auto& slice = result.Items[arraySlice];
370 slice.Mips.Resize(_texture.TotalMipLevels());
371 for (int32 mipIndex = 0; mipIndex < slice.Mips.Count(); mipIndex++)
372 {
373 auto& mip = slice.Mips[mipIndex];
374 int32 rowPitch, slicePitch;
375 BytesContainer mipData = GetMipData(mipIndex, rowPitch, slicePitch);
376 if (mipData.IsInvalid())
377 {
378 LOG(Error, "Failed to get texture mip data.");
379 return true;
380 }
381 if (mipData.Length() != slicePitch * _texture.TotalArraySize())
382 {
383 LOG(Error, "Invalid custom texture data (slice pitch * array size is different than data bytes count).");
384 return true;
385 }
386 mip.RowPitch = rowPitch;
387 mip.DepthPitch = slicePitch;
388 mip.Lines = Math::Max(1, Height() >> mipIndex);
389 if (copyData)
390 mip.Data.Copy(mipData.Get() + (arraySlice * slicePitch), slicePitch);
391 else
392 mip.Data.Link(mipData.Get() + (arraySlice * slicePitch), slicePitch);
393 }
394 }
395
396 return false;
397}
398
399bool TextureBase::GetTextureMipData(TextureMipData& result, int32 mipIndex, int32 arrayIndex, bool copyData)
400{

Callers 2

GetTextureMethod · 0.80
ProcessTextureBaseFunction · 0.80

Calls 11

IsVirtualFunction · 0.85
LockDataClass · 0.85
HeightFunction · 0.70
MaxFunction · 0.50
ResizeMethod · 0.45
CountMethod · 0.45
IsInvalidMethod · 0.45
LengthMethod · 0.45
CopyMethod · 0.45
GetMethod · 0.45
LinkMethod · 0.45

Tested by

no test coverage detected