From 892a9ba2999384ab069ad74110573434733e3b10 Mon Sep 17 00:00:00 2001 From: Yannis Vogel Date: Sun, 19 Apr 2026 13:54:59 +0200 Subject: [PATCH] fix non-animated webp-colors - non-animated webp handling on windows was using wrong color-interpretation (switching blue & red), fixed that by taking same approach as animated webp - also fixed some deprecated parameters --- .../RuntimeImageLoader/Private/Helpers/WEBPGIFLoader.cpp | 8 +++++++- .../Texture2DAnimation/AnimatedTextureResource.cpp | 2 +- .../Private/TextureFactory/RuntimeRHITexture2DFactory.cpp | 2 +- .../TextureFactory/RuntimeRHITextureCubeFactory.cpp | 2 +- .../Private/TextureFactory/RuntimeTextureResource.cpp | 2 +- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Source/RuntimeImageLoader/Private/Helpers/WEBPGIFLoader.cpp b/Source/RuntimeImageLoader/Private/Helpers/WEBPGIFLoader.cpp index fb47103..53754b0 100644 --- a/Source/RuntimeImageLoader/Private/Helpers/WEBPGIFLoader.cpp +++ b/Source/RuntimeImageLoader/Private/Helpers/WEBPGIFLoader.cpp @@ -158,7 +158,13 @@ bool FWEBPGIFLoader::DecodeGIF(TArray&& GifBytes) TextureData.SetNumZeroed(GetWidth() * GetHeight()); - uint8_t* DecodedData = WebPDecodeRGBA(GifBytes.GetData(), GifBytes.Num(), &Width, &Height); + uint8_t* DecodedData = nullptr; + +#if PLATFORM_WINDOWS + DecodedData = WebPDecodeBGRA(GifBytes.GetData(), GifBytes.Num(), &Width, &Height); // Unreal on Windows will most often use DirectX so prefer BGRA, otherwise devs should change this line! +#else + DecodedData = WebPDecodeRGBA(GifBytes.GetData(), GifBytes.Num(), &Width, &Height); // Default to RGBA for other platforms (Mobile, Vulkan, etc.) +#endif if (DecodedData == nullptr) { SetError("Failed to decode .webp file. Please check input data is valid!"); diff --git a/Source/RuntimeImageLoader/Private/Texture2DAnimation/AnimatedTextureResource.cpp b/Source/RuntimeImageLoader/Private/Texture2DAnimation/AnimatedTextureResource.cpp index bc63c9a..150af6d 100644 --- a/Source/RuntimeImageLoader/Private/Texture2DAnimation/AnimatedTextureResource.cpp +++ b/Source/RuntimeImageLoader/Private/Texture2DAnimation/AnimatedTextureResource.cpp @@ -129,7 +129,7 @@ void FAnimatedTextureResource::InitRHI(FRHICommandListBase& RHICmdList) .SetNumSamples(1) .SetFlags(Flags) .SetInitialState(ERHIAccess::Unknown) - .SetBulkData(FirstFrameData ? &GifBulkData : nullptr) + .SetInitActionBulkData(FirstFrameData ? &GifBulkData : nullptr) ); #elif (ENGINE_MAJOR_VERSION == 5) && (ENGINE_MINOR_VERSION > 0) FRHIResourceCreateInfo CreateInfo(*Name); diff --git a/Source/RuntimeImageLoader/Private/TextureFactory/RuntimeRHITexture2DFactory.cpp b/Source/RuntimeImageLoader/Private/TextureFactory/RuntimeRHITexture2DFactory.cpp index bfbceab..5fb0b54 100644 --- a/Source/RuntimeImageLoader/Private/TextureFactory/RuntimeRHITexture2DFactory.cpp +++ b/Source/RuntimeImageLoader/Private/TextureFactory/RuntimeRHITexture2DFactory.cpp @@ -118,7 +118,7 @@ FTexture2DRHIRef FRuntimeRHITexture2DFactory::CreateRHITexture2D_Windows() .SetNumSamples(1) .SetFlags(TextureFlags) .SetInitialState(ERHIAccess::Unknown) - .SetBulkData(&TextureData) + .SetInitActionBulkData(&TextureData) ); #elif (ENGINE_MAJOR_VERSION == 5) && (ENGINE_MINOR_VERSION > 0) FRHIResourceCreateInfo CreateInfo(TEXT("RuntimeImageReaderTextureData")); diff --git a/Source/RuntimeImageLoader/Private/TextureFactory/RuntimeRHITextureCubeFactory.cpp b/Source/RuntimeImageLoader/Private/TextureFactory/RuntimeRHITextureCubeFactory.cpp index 6427b9e..2d77cf8 100644 --- a/Source/RuntimeImageLoader/Private/TextureFactory/RuntimeRHITextureCubeFactory.cpp +++ b/Source/RuntimeImageLoader/Private/TextureFactory/RuntimeRHITextureCubeFactory.cpp @@ -80,7 +80,7 @@ FTextureCubeRHIRef FRuntimeRHITextureCubeFactory::CreateTextureCubeRHI_Windows() .SetNumMips(1) .SetFlags(TextureFlags) .SetInitialState(ERHIAccess::Unknown) - .SetBulkData(&TextureCubeData) + .SetInitActionBulkData(&TextureCubeData) ); #elif (ENGINE_MAJOR_VERSION == 5) && (ENGINE_MINOR_VERSION > 0) FRHIResourceCreateInfo CreateInfo(TEXT("RuntimeImageReader_TextureCubeData")); diff --git a/Source/RuntimeImageLoader/Private/TextureFactory/RuntimeTextureResource.cpp b/Source/RuntimeImageLoader/Private/TextureFactory/RuntimeTextureResource.cpp index f0adf78..a97d4f8 100644 --- a/Source/RuntimeImageLoader/Private/TextureFactory/RuntimeTextureResource.cpp +++ b/Source/RuntimeImageLoader/Private/TextureFactory/RuntimeTextureResource.cpp @@ -44,7 +44,7 @@ void FRuntimeTextureResource::ReleaseRHI() { if (IsValid(Owner)) { - RHIUpdateTextureReference(Owner->TextureReference.TextureReferenceRHI, nullptr); + RHIClearTextureReference(Owner->TextureReference.TextureReferenceRHI); } FTextureResource::ReleaseRHI();