mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-28 10:35:43 -05:00
Updated texture loading.
This commit is contained in:
parent
d58d62401e
commit
7461299271
1 changed files with 48 additions and 31 deletions
|
@ -76,7 +76,6 @@ static void* loadMem(bx::FileReaderI* _reader, bx::ReallocatorI* _allocator, con
|
|||
{
|
||||
*_size = size;
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
@ -138,8 +137,12 @@ extern "C" stbi_uc *stbi_load_from_memory(stbi_uc const *buffer, int len, int *x
|
|||
|
||||
bgfx::TextureHandle loadTexture(bx::FileReaderI* _reader, const char* _name, uint32_t _flags, uint8_t _skip, bgfx::TextureInfo* _info)
|
||||
{
|
||||
char filePath[512];
|
||||
char filePath[512] = { '\0' };
|
||||
if (NULL == strchr(_name, '/') )
|
||||
{
|
||||
strcpy(filePath, "textures/");
|
||||
}
|
||||
|
||||
strcat(filePath, _name);
|
||||
|
||||
if (NULL != bx::stristr(_name, ".dds")
|
||||
|
@ -147,14 +150,23 @@ bgfx::TextureHandle loadTexture(bx::FileReaderI* _reader, const char* _name, uin
|
|||
|| NULL != bx::stristr(_name, ".ktx") )
|
||||
{
|
||||
const bgfx::Memory* mem = loadMem(_reader, filePath);
|
||||
if (NULL != mem)
|
||||
{
|
||||
return bgfx::createTexture(mem, _flags, _skip, _info);
|
||||
}
|
||||
|
||||
bgfx::TextureHandle handle = BGFX_INVALID_HANDLE;
|
||||
DBG("Failed to load %s.", filePath);
|
||||
return handle;
|
||||
}
|
||||
|
||||
bgfx::TextureHandle handle = BGFX_INVALID_HANDLE;
|
||||
bx::ReallocatorI* allocator = entry::getAllocator();
|
||||
|
||||
uint32_t size = 0;
|
||||
void* data = loadMem(_reader, allocator, filePath, &size);
|
||||
|
||||
if (NULL != data)
|
||||
{
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
int comp = 0;
|
||||
|
@ -164,7 +176,7 @@ bgfx::TextureHandle loadTexture(bx::FileReaderI* _reader, const char* _name, uin
|
|||
|
||||
BX_FREE(allocator, data);
|
||||
|
||||
bgfx::TextureHandle handle = bgfx::createTexture2D(uint16_t(width), uint16_t(height), 1
|
||||
handle = bgfx::createTexture2D(uint16_t(width), uint16_t(height), 1
|
||||
, bgfx::TextureFormat::RGBA8
|
||||
, _flags
|
||||
, bgfx::copy(img, width*height*4)
|
||||
|
@ -183,6 +195,11 @@ bgfx::TextureHandle loadTexture(bx::FileReaderI* _reader, const char* _name, uin
|
|||
, bgfx::TextureFormat::RGBA8
|
||||
);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG("Failed to load %s.", filePath);
|
||||
}
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue