mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-25 00:58:30 -05:00
Use TextureInfo for caclTextureSize.
This commit is contained in:
parent
28d0d973b3
commit
96199abe81
3 changed files with 23 additions and 15 deletions
|
@ -428,9 +428,12 @@ namespace bgfx
|
|||
struct TextureInfo
|
||||
{
|
||||
TextureFormat::Enum format;
|
||||
uint32_t storageSize;
|
||||
uint16_t width;
|
||||
uint16_t height;
|
||||
uint16_t depth;
|
||||
uint8_t numMips;
|
||||
uint8_t bitsPerPixel;
|
||||
};
|
||||
|
||||
/// Vertex declaration.
|
||||
|
@ -605,11 +608,8 @@ namespace bgfx
|
|||
/// Destroy program.
|
||||
void destroyProgram(ProgramHandle _handle);
|
||||
|
||||
/// Returns number of bits per pixel.
|
||||
uint32_t getBitsPerPixel(TextureFormat::Enum _format);
|
||||
|
||||
/// Calculate amount of memory required for texture.
|
||||
uint32_t calcTextureSize(uint16_t _width, uint16_t _height, uint16_t _depth, uint8_t _numMips, TextureFormat::Enum _format);
|
||||
void calcTextureSize(TextureInfo& _info, uint16_t _width, uint16_t _height, uint16_t _depth, uint8_t _numMips, TextureFormat::Enum _format);
|
||||
|
||||
/// Create texture from memory buffer.
|
||||
TextureHandle createTexture(const Memory* _mem, uint32_t _flags = BGFX_TEXTURE_NONE, TextureInfo* _info = NULL);
|
||||
|
|
16
src/bgfx.cpp
16
src/bgfx.cpp
|
@ -909,16 +909,12 @@ namespace bgfx
|
|||
32, // RGB10A2
|
||||
};
|
||||
|
||||
uint32_t getBitsPerPixel(TextureFormat::Enum _format)
|
||||
{
|
||||
return s_bitsPerPixel[_format];
|
||||
}
|
||||
|
||||
uint32_t calcTextureSize(uint16_t _width, uint16_t _height, uint16_t _depth, uint8_t _numMips, TextureFormat::Enum _format)
|
||||
void calcTextureSize(TextureInfo& _info, uint16_t _width, uint16_t _height, uint16_t _depth, uint8_t _numMips, TextureFormat::Enum _format)
|
||||
{
|
||||
uint32_t width = _width;
|
||||
uint32_t height = _height;
|
||||
uint32_t depth = _depth;
|
||||
|
||||
uint32_t bpp = s_bitsPerPixel[_format];
|
||||
uint32_t size = 0;
|
||||
|
||||
|
@ -935,7 +931,13 @@ namespace bgfx
|
|||
depth >>= 1;
|
||||
}
|
||||
|
||||
return size;
|
||||
_info.format = _format;
|
||||
_info.storageSize = size;
|
||||
_info.width = _width;
|
||||
_info.height = _height;
|
||||
_info.depth = _depth;
|
||||
_info.numMips = _numMips;
|
||||
_info.bitsPerPixel = bpp;
|
||||
}
|
||||
|
||||
TextureHandle createTexture(const Memory* _mem, uint32_t _flags, TextureInfo* _info)
|
||||
|
|
14
src/bgfx_p.h
14
src/bgfx_p.h
|
@ -1950,17 +1950,23 @@ namespace bgfx
|
|||
Dds dds;
|
||||
if (parseDds(dds, _mem) )
|
||||
{
|
||||
_info->format = dds.m_type;
|
||||
_info->width = (uint16_t)dds.m_width;
|
||||
_info->height = (uint16_t)dds.m_height;
|
||||
_info->depth = (uint16_t)dds.m_depth;
|
||||
calcTextureSize(*_info
|
||||
, (uint16_t)dds.m_width
|
||||
, (uint16_t)dds.m_height
|
||||
, (uint16_t)dds.m_depth
|
||||
, dds.m_numMips
|
||||
, dds.m_type
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
_info->format = TextureFormat::Unknown;
|
||||
_info->storageSize = 0;
|
||||
_info->width = 0;
|
||||
_info->height = 0;
|
||||
_info->depth = 0;
|
||||
_info->numMips = 0;
|
||||
_info->bitsPerPixel = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue