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

Method GenerateMip

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

Source from the content-addressed store, hash-verified

868}
869
870bool TextureBase::InitData::GenerateMip(int32 mipIndex, bool linear)
871{
872 // Validate input
873 if (mipIndex < 1 || mipIndex >= Mips.Count())
874 {
875 LOG(Warning, "Invalid mip map to generate.");
876 return true;
877 }
878 if (ArraySize < 1)
879 {
880 LOG(Warning, "Invalid array size.");
881 return true;
882 }
883 if (PixelFormatExtensions::IsCompressed(Format))
884 {
885 LOG(Warning, "Cannot generate mip map for compressed format data.");
886 return true;
887 }
888 const auto& srcMip = Mips[mipIndex - 1];
889 auto& dstMip = Mips[mipIndex];
890 if (srcMip.RowPitch == 0 || srcMip.SlicePitch == 0 || srcMip.Data.IsInvalid())
891 {
892 LOG(Warning, "Missing data for source mip map.");
893 return true;
894 }
895
896 PROFILE_CPU_NAMED("Texture.GenerateMip");
897
898 // Allocate data
899 const int32 dstMipWidth = Math::Max(1, Width >> mipIndex);
900 const int32 dstMipHeight = Math::Max(1, Height >> mipIndex);
901 const int32 pixelStride = PixelFormatExtensions::SizeInBytes(Format);
902 dstMip.RowPitch = dstMipWidth * pixelStride;
903 dstMip.SlicePitch = dstMip.RowPitch * dstMipHeight;
904 dstMip.Data.Allocate(dstMip.SlicePitch * ArraySize);
905
906 // Perform filtering
907 if (linear)
908 {
909 switch (Format)
910 {
911 // 4 component, 32 bit with 8 bits per component - use Color32 type
912 case PixelFormat::R8G8B8A8_SInt:
913 case PixelFormat::R8G8B8A8_Typeless:
914 case PixelFormat::R8G8B8A8_SNorm:
915 case PixelFormat::R8G8B8A8_UInt:
916 case PixelFormat::R8G8B8A8_UNorm:
917 case PixelFormat::R8G8B8A8_UNorm_sRGB:
918 case PixelFormat::R8G8_B8G8_UNorm:
919 case PixelFormat::B8G8R8A8_Typeless:
920 case PixelFormat::B8G8R8A8_UNorm:
921 case PixelFormat::B8G8R8A8_UNorm_sRGB:
922 case PixelFormat::B8G8R8X8_Typeless:
923 case PixelFormat::B8G8R8X8_UNorm:
924 case PixelFormat::B8G8R8X8_UNorm_sRGB:
925 {
926 // Linear downscale filter
927 for (int32 arrayIndex = 0; arrayIndex < ArraySize; arrayIndex++)

Callers 3

SetPixelsMethod · 0.80
InitCSharpMethod · 0.80
GenerateMipsFunction · 0.80

Calls 7

ToStringFunction · 0.70
MaxFunction · 0.50
Color32Class · 0.50
CountMethod · 0.45
IsInvalidMethod · 0.45
AllocateMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected