Skip to content

Commit

Permalink
Added support for loading hdr images.
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewRichards-Code committed Oct 24, 2024
1 parent 6567171 commit 74e4610
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
9 changes: 6 additions & 3 deletions CrossPlatform/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion CrossPlatform/Texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t> CalculateSubresourceSlices(uint32_t Index, uint32_t MipSlice, uint32_t ArraySlice); // Returned as { MipSlice, ArraySlice, PlaneSlice }
Expand Down
2 changes: 1 addition & 1 deletion OpenGL/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Vulkan/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ void Texture::LoadTextureData(LoadedTexture &lt,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);
}
Expand Down

0 comments on commit 74e4610

Please sign in to comment.