From 74e46103c950388af819cd1e967124ce8c8e417b Mon Sep 17 00:00:00 2001 From: Andrew Richards Date: Thu, 24 Oct 2024 10:09:48 +0100 Subject: [PATCH] Added support for loading hdr images. --- CrossPlatform/Texture.cpp | 9 ++++++--- CrossPlatform/Texture.h | 2 +- OpenGL/Texture.cpp | 2 +- Vulkan/Texture.cpp | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CrossPlatform/Texture.cpp b/CrossPlatform/Texture.cpp index d0bda30cb..6805ce952 100644 --- a/CrossPlatform/Texture.cpp +++ b/CrossPlatform/Texture.cpp @@ -158,11 +158,14 @@ bool Texture::EnsureTexture(crossplatform::RenderPlatform* r, crossplatform::Tex return res; } -bool Texture::TranslateLoadedTextureData(void*& target, const void* src, size_t size, int& x, int& y, int& num_channels, int req_num_channels) +bool Texture::TranslateLoadedTextureData(void *&target, const void *src, size_t size, int &x, int &y, int &num_channels, int req_num_channels, const char *filename) { - target = stbi_load_from_memory((const unsigned char*)src, (int)size, &x, &y, &num_channels, 4); + if (stbi_is_hdr(filename)) + target = stbi_loadf_from_memory((const unsigned char *)src, (int)size, &x, &y, &num_channels, 4); + else + target = stbi_load_from_memory((const unsigned char *)src, (int)size, &x, &y, &num_channels, 4); stbi_loaded = true; - return(target!=nullptr); + return (target != nullptr); } void Texture::FreeTranslatedTextureData(void* data) diff --git a/CrossPlatform/Texture.h b/CrossPlatform/Texture.h index 4f4262774..d7386b05e 100644 --- a/CrossPlatform/Texture.h +++ b/CrossPlatform/Texture.h @@ -501,7 +501,7 @@ namespace platform // For API's that don't track resources: bool unfenceable; // a wrapper around stbi_load_from_memory. - bool TranslateLoadedTextureData(void *&target,const void *src,size_t size,int &x,int &y,int &num_channels,int req_num_channels); + bool TranslateLoadedTextureData(void *&target,const void *src,size_t size,int &x,int &y,int &num_channels,int req_num_channels,const char* filename); void FreeTranslatedTextureData(void *data); uint32_t CalculateSubresourceIndex(uint32_t MipSlice, uint32_t ArraySlice, uint32_t PlaneSlice, uint32_t MipLevels, uint32_t ArraySize); tvector3 CalculateSubresourceSlices(uint32_t Index, uint32_t MipSlice, uint32_t ArraySlice); // Returned as { MipSlice, ArraySlice, PlaneSlice } diff --git a/OpenGL/Texture.cpp b/OpenGL/Texture.cpp index 966d94be2..9d5e128a4 100644 --- a/OpenGL/Texture.cpp +++ b/OpenGL/Texture.cpp @@ -675,7 +675,7 @@ GLuint Texture::GetGLMainView() return; } void* data = nullptr; - TranslateLoadedTextureData(data, buffer, size, x, y, n, 4); + TranslateLoadedTextureData(data, buffer, size, x, y, n, 4, path); platform::core::FileLoader::GetFileLoader()->ReleaseFileContents(buffer); lt.data = (unsigned char *)data; lt.x = x; diff --git a/Vulkan/Texture.cpp b/Vulkan/Texture.cpp index 9226f6db1..f2254693d 100644 --- a/Vulkan/Texture.cpp +++ b/Vulkan/Texture.cpp @@ -884,7 +884,7 @@ void Texture::LoadTextureData(LoadedTexture <,const char* path) return; } void* data = nullptr; - TranslateLoadedTextureData(data,buffer,size,x,y,n,4); + TranslateLoadedTextureData(data,buffer,size,x,y,n,4,path); core::FileLoader::GetFileLoader()->ReleaseFileContents(buffer); SetTextureData(lt,data,x,y,1,n,crossplatform::PixelFormat::RGBA_8_UNORM); }