mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-28 18:45:54 -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;
|
*_size = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
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)
|
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' };
|
||||||
strcpy(filePath, "textures/");
|
if (NULL == strchr(_name, '/') )
|
||||||
|
{
|
||||||
|
strcpy(filePath, "textures/");
|
||||||
|
}
|
||||||
|
|
||||||
strcat(filePath, _name);
|
strcat(filePath, _name);
|
||||||
|
|
||||||
if (NULL != bx::stristr(_name, ".dds")
|
if (NULL != bx::stristr(_name, ".dds")
|
||||||
|
@ -147,41 +150,55 @@ bgfx::TextureHandle loadTexture(bx::FileReaderI* _reader, const char* _name, uin
|
||||||
|| NULL != bx::stristr(_name, ".ktx") )
|
|| NULL != bx::stristr(_name, ".ktx") )
|
||||||
{
|
{
|
||||||
const bgfx::Memory* mem = loadMem(_reader, filePath);
|
const bgfx::Memory* mem = loadMem(_reader, filePath);
|
||||||
return bgfx::createTexture(mem, _flags, _skip, _info);
|
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();
|
bx::ReallocatorI* allocator = entry::getAllocator();
|
||||||
|
|
||||||
uint32_t size = 0;
|
uint32_t size = 0;
|
||||||
void* data = loadMem(_reader, allocator, filePath, &size);
|
void* data = loadMem(_reader, allocator, filePath, &size);
|
||||||
|
if (NULL != data)
|
||||||
int width = 0;
|
|
||||||
int height = 0;
|
|
||||||
int comp = 0;
|
|
||||||
|
|
||||||
uint8_t* img = NULL;
|
|
||||||
img = stbi_load_from_memory( (uint8_t*)data, size, &width, &height, &comp, 4);
|
|
||||||
|
|
||||||
BX_FREE(allocator, data);
|
|
||||||
|
|
||||||
bgfx::TextureHandle handle = bgfx::createTexture2D(uint16_t(width), uint16_t(height), 1
|
|
||||||
, bgfx::TextureFormat::RGBA8
|
|
||||||
, _flags
|
|
||||||
, bgfx::copy(img, width*height*4)
|
|
||||||
);
|
|
||||||
|
|
||||||
free(img);
|
|
||||||
|
|
||||||
if (NULL != _info)
|
|
||||||
{
|
{
|
||||||
bgfx::calcTextureSize(*_info
|
int width = 0;
|
||||||
, uint16_t(width)
|
int height = 0;
|
||||||
, uint16_t(height)
|
int comp = 0;
|
||||||
, 0
|
|
||||||
, false
|
uint8_t* img = NULL;
|
||||||
, 1
|
img = stbi_load_from_memory( (uint8_t*)data, size, &width, &height, &comp, 4);
|
||||||
, bgfx::TextureFormat::RGBA8
|
|
||||||
);
|
BX_FREE(allocator, data);
|
||||||
|
|
||||||
|
handle = bgfx::createTexture2D(uint16_t(width), uint16_t(height), 1
|
||||||
|
, bgfx::TextureFormat::RGBA8
|
||||||
|
, _flags
|
||||||
|
, bgfx::copy(img, width*height*4)
|
||||||
|
);
|
||||||
|
|
||||||
|
free(img);
|
||||||
|
|
||||||
|
if (NULL != _info)
|
||||||
|
{
|
||||||
|
bgfx::calcTextureSize(*_info
|
||||||
|
, uint16_t(width)
|
||||||
|
, uint16_t(height)
|
||||||
|
, 0
|
||||||
|
, false
|
||||||
|
, 1
|
||||||
|
, bgfx::TextureFormat::RGBA8
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DBG("Failed to load %s.", filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
return handle;
|
return handle;
|
||||||
|
|
Loading…
Reference in a new issue