Merge pull request #1078 from dariomanesku/image_loader
Don't force stb image loader to use RGBA8.
This commit is contained in:
commit
092efd4d81
@ -33,7 +33,9 @@ BX_PRAGMA_DIAGNOSTIC_POP()
|
|||||||
#include <lodepng/lodepng.h>
|
#include <lodepng/lodepng.h>
|
||||||
|
|
||||||
typedef unsigned char stbi_uc;
|
typedef unsigned char stbi_uc;
|
||||||
|
extern "C" int stbi_is_hdr_from_memory(stbi_uc const* _buffer, int _len);
|
||||||
extern "C" stbi_uc* stbi_load_from_memory(stbi_uc const* _buffer, int _len, int* _x, int* _y, int* _comp, int _req_comp);
|
extern "C" stbi_uc* stbi_load_from_memory(stbi_uc const* _buffer, int _len, int* _x, int* _y, int* _comp, int _req_comp);
|
||||||
|
extern "C" float* stbi_loadf_from_memory(stbi_uc const* _buffer, int _len, int* _x, int* _y, int* _comp, int _req_comp);
|
||||||
extern "C" void stbi_image_free(void* _ptr);
|
extern "C" void stbi_image_free(void* _ptr);
|
||||||
extern void lodepng_free(void* _ptr);
|
extern void lodepng_free(void* _ptr);
|
||||||
|
|
||||||
@ -336,18 +338,33 @@ namespace bgfx
|
|||||||
|
|
||||||
static ImageContainer* imageParseStbImage(bx::AllocatorI* _allocator, const void* _data, uint32_t _size)
|
static ImageContainer* imageParseStbImage(bx::AllocatorI* _allocator, const void* _data, uint32_t _size)
|
||||||
{
|
{
|
||||||
TextureFormat::Enum format = TextureFormat::RGBA8;
|
const int isHdr = stbi_is_hdr_from_memory((const uint8_t*)_data, (int)_size);
|
||||||
|
|
||||||
|
void* data;
|
||||||
uint32_t width = 0;
|
uint32_t width = 0;
|
||||||
uint32_t height = 0;
|
uint32_t height = 0;
|
||||||
|
|
||||||
int comp = 0;
|
int comp = 0;
|
||||||
void* data = stbi_load_from_memory( (uint8_t*)_data, _size, (int*)&width, (int*)&height, &comp, 4);
|
if (isHdr) { data = stbi_loadf_from_memory((const uint8_t*)_data, (int)_size, (int*)&width, (int*)&height, &comp, 4); }
|
||||||
|
else { data = stbi_load_from_memory ((const uint8_t*)_data, (int)_size, (int*)&width, (int*)&height, &comp, 0); }
|
||||||
|
|
||||||
if (NULL == data)
|
if (NULL == data)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bgfx::TextureFormat::Enum format;
|
||||||
|
if (isHdr)
|
||||||
|
{
|
||||||
|
format = bgfx::TextureFormat::RGBA32F;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (1 == comp) { format = bgfx::TextureFormat::R8; }
|
||||||
|
else if (2 == comp) { format = bgfx::TextureFormat::RG8; }
|
||||||
|
else if (3 == comp) { format = bgfx::TextureFormat::RGB8; }
|
||||||
|
else/*if (4 == comp)*/ { format = bgfx::TextureFormat::RGBA8; }
|
||||||
|
}
|
||||||
|
|
||||||
ImageContainer* output = imageAlloc(_allocator
|
ImageContainer* output = imageAlloc(_allocator
|
||||||
, format
|
, format
|
||||||
, uint16_t(width)
|
, uint16_t(width)
|
||||||
|
@ -4684,6 +4684,7 @@ namespace bgfx { namespace gl
|
|||||||
GL_CHECK(glGenTextures(1, &m_id) );
|
GL_CHECK(glGenTextures(1, &m_id) );
|
||||||
BX_CHECK(0 != m_id, "Failed to generate texture id.");
|
BX_CHECK(0 != m_id, "Failed to generate texture id.");
|
||||||
GL_CHECK(glBindTexture(_target, m_id) );
|
GL_CHECK(glBindTexture(_target, m_id) );
|
||||||
|
GL_CHECK(glPixelStorei(GL_UNPACK_ALIGNMENT, 1) );
|
||||||
|
|
||||||
const TextureFormatInfo& tfi = s_textureFormat[m_textureFormat];
|
const TextureFormatInfo& tfi = s_textureFormat[m_textureFormat];
|
||||||
m_fmt = tfi.m_fmt;
|
m_fmt = tfi.m_fmt;
|
||||||
|
Loading…
Reference in New Issue
Block a user