Skip to content

Commit 40bc9a6

Browse files
committed
fixed UE4 build
1 parent 61ec6cf commit 40bc9a6

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

Source/glTFRuntime/Private/glTFRuntimeAsset.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,13 @@ UTexture2DArray* UglTFRuntimeAsset::LoadImageArrayFromBlob(const FglTFRuntimeIma
788788

789789
if (Width > 0 && Height > 0)
790790
{
791+
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 1
791792
int64 ImageSize = GPixelFormats[PixelFormat].Get2DImageSizeInBytes(Width, Height);
793+
#else
794+
const int64 BlockWidth = (Width + GPixelFormats[PixelFormat].BlockSizeX - 1) / GPixelFormats[PixelFormat].BlockSizeX;
795+
const int64 BlockHeight = (Width + GPixelFormats[PixelFormat].BlockSizeY - 1) / GPixelFormats[PixelFormat].BlockSizeY;
796+
int64 ImageSize = BlockWidth * BlockHeight * GPixelFormats[PixelFormat].BlockBytes;
797+
#endif
792798
int32 NumberOfSlices = UncompressedBytes.Num() / ImageSize;
793799
TArray<FglTFRuntimeMipMap> Mips;
794800

@@ -852,7 +858,11 @@ UTextureCube* UglTFRuntimeAsset::LoadCubeMapFromBlob(const bool bSpherical, cons
852858
if (bSpherical)
853859
{
854860
const int32 Resolution = Height;
861+
#if ENGINE_MAJOR_VERSION >= 5
855862
auto GetCubemapFace = [Resolution, Width, Height, PixelFormat](const TArray64<uint8>& Pixels, const FVector3f Start, const FVector3f Right, const FVector3f Up, TArray64<uint8>& OutPixels)
863+
#else
864+
auto GetCubemapFace = [Resolution, Width, Height, PixelFormat](const TArray64<uint8>& Pixels, const FVector Start, const FVector Right, const FVector Up, TArray64<uint8>& OutPixels)
865+
#endif
856866
{
857867
const int64 Pitch = Resolution * GPixelFormats[PixelFormat].BlockBytes;
858868
OutPixels.AddUninitialized(Pitch * Resolution);
@@ -913,6 +923,7 @@ UTextureCube* UglTFRuntimeAsset::LoadCubeMapFromBlob(const bool bSpherical, cons
913923
FX = FMath::Abs(FX);
914924
FY = FMath::Abs(FY);
915925

926+
#if ENGINE_MAJOR_VERSION >= 5
916927
if (PixelFormat == EPixelFormat::PF_FloatRGB)
917928
{
918929
const FFloat16* Colors = reinterpret_cast<const FFloat16*>(Pixels.GetData());
@@ -952,6 +963,48 @@ UTextureCube* UglTFRuntimeAsset::LoadCubeMapFromBlob(const bool bSpherical, cons
952963

953964
FMemory::Memcpy(OutPixels.GetData() + Offset, &Color16, sizeof(FFloat16) * 4);
954965
}
966+
967+
#else
968+
if (PixelFormat == EPixelFormat::PF_FloatRGB)
969+
{
970+
const FFloat16* Colors = reinterpret_cast<const FFloat16*>(Pixels.GetData());
971+
const int64 Offset00 = Y2 * (Width * 3) + (X2 * 3);
972+
const FVector Color00 = FVector(Colors[Offset00], Colors[Offset00 + 1], Colors[Offset00 + 2]);
973+
const int64 Offset10 = Y2 * (Width * 3) + (X3 * 3);
974+
const FVector Color10 = FVector(Colors[Offset10], Colors[Offset10 + 1], Colors[Offset10 + 2]);
975+
976+
const int64 Offset01 = Y3 * (Width * 3) + (X2 * 3);
977+
const FVector Color01 = FVector(Colors[Offset01], Colors[Offset01 + 1], Colors[Offset01 + 2]);
978+
const int64 Offset11 = Y3 * (Width * 3) + (X3 * 3);
979+
const FVector Color11 = FVector(Colors[Offset11], Colors[Offset11 + 1], Colors[Offset11 + 2]);
980+
981+
FVector Color = FMath::BiLerp(Color00, Color10, Color01, Color11, FX, FY);
982+
983+
FFloat16Color Color16 = FLinearColor(Color);
984+
985+
986+
FMemory::Memcpy(OutPixels.GetData() + Offset, &Color16, sizeof(FFloat16) * 3);
987+
}
988+
else if (PixelFormat == EPixelFormat::PF_FloatRGBA)
989+
{
990+
const FFloat16* Colors = reinterpret_cast<const FFloat16*>(Pixels.GetData());
991+
const int64 Offset00 = Y2 * (Width * 4) + (X2 * 4);
992+
const FVector4 Color00 = FVector4(Colors[Offset00], Colors[Offset00 + 1], Colors[Offset00 + 2], Colors[Offset00 + 3]);
993+
const int64 Offset10 = Y2 * (Width * 4) + (X3 * 4);
994+
const FVector4 Color10 = FVector4(Colors[Offset10], Colors[Offset10 + 1], Colors[Offset10 + 2], Colors[Offset10 + 3]);
995+
996+
const int64 Offset01 = Y3 * (Width * 4) + (X2 * 4);
997+
const FVector4 Color01 = FVector4(Colors[Offset01], Colors[Offset01 + 1], Colors[Offset01 + 2], Colors[Offset01 + 3]);
998+
const int64 Offset11 = Y3 * (Width * 4) + (X3 * 4);
999+
const FVector4 Color11 = FVector4(Colors[Offset11], Colors[Offset11 + 1], Colors[Offset11 + 2], Colors[Offset11 + 3]);
1000+
1001+
FVector4 Color = FMath::BiLerp(Color00, Color10, Color01, Color11, FX, FY);
1002+
1003+
FFloat16Color Color16 = FLinearColor(Color);
1004+
1005+
FMemory::Memcpy(OutPixels.GetData() + Offset, &Color16, sizeof(FFloat16) * 4);
1006+
}
1007+
#endif
9551008
else
9561009
{
9571010

@@ -986,7 +1039,13 @@ UTextureCube* UglTFRuntimeAsset::LoadCubeMapFromBlob(const bool bSpherical, cons
9861039
}
9871040
else
9881041
{
1042+
#if ENGINE_MAJOR_VERSION >= 5 && ENGINE_MINOR_VERSION >= 1
9891043
int64 ImageSize = GPixelFormats[PixelFormat].Get2DImageSizeInBytes(Width, Height);
1044+
#else
1045+
const int64 BlockWidth = (Width + GPixelFormats[PixelFormat].BlockSizeX - 1) / GPixelFormats[PixelFormat].BlockSizeX;
1046+
const int64 BlockHeight = (Width + GPixelFormats[PixelFormat].BlockSizeY - 1) / GPixelFormats[PixelFormat].BlockSizeY;
1047+
int64 ImageSize = BlockWidth * BlockHeight * GPixelFormats[PixelFormat].BlockBytes;
1048+
#endif
9901049
int32 NumberOfSlices = UncompressedBytes.Num() / ImageSize;
9911050
if (NumberOfSlices != 6)
9921051
{

Source/glTFRuntime/Private/glTFRuntimeParserMaterials.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,12 +627,14 @@ bool FglTFRuntimeParser::LoadImageFromBlob(TArray64<uint8>& Blob, TSharedRef<FJs
627627
ERGBFormat RGBFormat = ERGBFormat::BGRA;
628628
int32 BitDepth = 8;
629629

630+
#if ENGINE_MAJOR_VERSION >= 5
630631
if (ImageFormat == EImageFormat::EXR)
631632
{
632633
RGBFormat = ERGBFormat::RGBAF;
633634
BitDepth = 16;
634635
PixelFormat = EPixelFormat::PF_FloatRGBA;
635636
}
637+
#endif
636638

637639
TSharedPtr<IImageWrapper> ImageWrapper = ImageWrapperModule.CreateImageWrapper(ImageFormat);
638640
if (!ImageWrapper.IsValid())
@@ -646,7 +648,11 @@ bool FglTFRuntimeParser::LoadImageFromBlob(TArray64<uint8>& Blob, TSharedRef<FJs
646648
return false;
647649
}
648650

651+
#if ENGINE_MAJOR_VERSION >= 5
649652
if (!ImageWrapper->GetRaw(ImagesConfig.bForceHDR ? ERGBFormat::RGBAF : RGBFormat, ImagesConfig.bForceHDR ? 16 : BitDepth, UncompressedBytes))
653+
#else
654+
if (!ImageWrapper->GetRaw(RGBFormat, ImagesConfig.bForceHDR ? 16 : BitDepth, UncompressedBytes))
655+
#endif
650656
{
651657
AddError("LoadImageFromBlob()", "Unable to get raw image data");
652658
return false;

0 commit comments

Comments
 (0)