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

Function ProcessTextureBase

Source/Editor/Cooker/Steps/CookAssetsStep.cpp:659–762  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

657}
658
659bool ProcessTextureBase(CookAssetsStep::AssetCookData& data)
660{
661 const auto asset = static_cast<TextureBase*>(data.Asset);
662 const auto& assetHeader = asset->StreamingTexture()->GetHeader();
663 const auto format = asset->Format();
664 auto targetFormat = data.Data.Tools->GetTextureFormat(data.Data, asset, format);
665 CHECK_RETURN(!PixelFormatExtensions::IsTypeless(targetFormat), true);
666 const auto streamingSettings = StreamingSettings::Get();
667 int32 mipLevelsMax = GPU_MAX_TEXTURE_MIP_LEVELS;
668 if (assetHeader->TextureGroup >= 0 && assetHeader->TextureGroup < streamingSettings->TextureGroups.Count())
669 {
670 auto& group = streamingSettings->TextureGroups[assetHeader->TextureGroup];
671 mipLevelsMax = group.MipLevelsMax;
672 group.MipLevelsMaxPerPlatform.TryGet(data.Data.Tools->GetPlatform(), mipLevelsMax);
673 }
674
675 // If texture is smaller than the block size of the target format (eg. 4x4 texture using ASTC_6x6) then fallback to uncompressed
676 int32 blockSize = PixelFormatExtensions::ComputeBlockSize(targetFormat);
677 if (assetHeader->Width < blockSize || assetHeader->Height < blockSize || (blockSize != 1 && mipLevelsMax < 4))
678 targetFormat = PixelFormatExtensions::FindUncompressedFormat(format);
679
680 // Faster path if don't need to modify texture for the target platform
681 if (format == targetFormat && assetHeader->MipLevels <= mipLevelsMax)
682 {
683 return CookAssetsStep::ProcessDefaultAsset(data);
684 }
685
686 // Extract texture data from the asset
687 TextureData textureDataSrc;
688 auto assetLock = asset->LockData();
689 if (asset->GetTextureData(textureDataSrc, false))
690 {
691 LOG(Error, "Failed to load data from texture {0}", asset->ToString());
692 return true;
693 }
694
695 TextureData* textureData = &textureDataSrc;
696 TextureData textureDataTmp1;
697
698 if (format != targetFormat)
699 {
700 // Convert texture data to the target format
701 if (TextureTool::Convert(textureDataTmp1, *textureData, targetFormat))
702 {
703 LOG(Error, "Failed to convert texture {0} from format {1} to {2}", asset->ToString(), ScriptingEnum::ToString(format), ScriptingEnum::ToString(targetFormat));
704 return true;
705 }
706 textureData = &textureDataTmp1;
707 }
708
709 if (assetHeader->MipLevels > mipLevelsMax)
710 {
711 // Reduce texture quality
712 const int32 mipLevelsToStrip = assetHeader->MipLevels - mipLevelsMax;
713 textureData->Width = Math::Max(1, textureData->Width >> mipLevelsToStrip);
714 textureData->Height = Math::Max(1, textureData->Height >> mipLevelsToStrip);
715 textureData->Depth = Math::Max(1, textureData->Depth >> mipLevelsToStrip);
716 for (int32 arrayIndex = 0; arrayIndex < textureData->Items.Count(); arrayIndex++)

Callers

nothing calls this directly

Calls 15

StreamingTextureMethod · 0.80
FormatMethod · 0.80
GetTextureDataMethod · 0.80
GetMipLevelsMethod · 0.80
IsMissingMethod · 0.80
LoadAssetChunkMethod · 0.80
GetFunction · 0.50
ToStringFunction · 0.50
MaxFunction · 0.50
GetTextureFormatMethod · 0.45
CountMethod · 0.45
TryGetMethod · 0.45

Tested by

no test coverage detected