|
|
@@ -472,7 +472,7 @@ namespace bgfx
|
|
|
uint8_t* rgba = mem->data;
|
|
|
charsetFillTexture(vga8x8, rgba, 8, pitch, bpp);
|
|
|
charsetFillTexture(vga8x16, &rgba[8*pitch], 16, pitch, bpp);
|
|
|
- m_texture = createTexture2D(width, height, 1, TextureFormat::R8
|
|
|
+ m_texture = createTexture2D(width, height, false, 1, TextureFormat::R8
|
|
|
, BGFX_TEXTURE_MIN_POINT
|
|
|
| BGFX_TEXTURE_MAG_POINT
|
|
|
| BGFX_TEXTURE_MIP_POINT
|
|
|
@@ -2882,7 +2882,7 @@ error:
|
|
|
s_ctx->destroyProgram(_handle);
|
|
|
}
|
|
|
|
|
|
- void calcTextureSize(TextureInfo& _info, uint16_t _width, uint16_t _height, uint16_t _depth, bool _cubeMap, uint8_t _numMips, TextureFormat::Enum _format)
|
|
|
+ void calcTextureSize(TextureInfo& _info, uint16_t _width, uint16_t _height, uint16_t _depth, bool _cubeMap, bool _hasMips, uint16_t _numLayers, TextureFormat::Enum _format)
|
|
|
{
|
|
|
const ImageBlockInfo& blockInfo = getBlockInfo(_format);
|
|
|
const uint8_t bpp = blockInfo.bitsPerPixel;
|
|
|
@@ -2894,32 +2894,15 @@ error:
|
|
|
_width = bx::uint16_max(blockWidth * minBlockX, ( (_width + blockWidth - 1) / blockWidth)*blockWidth);
|
|
|
_height = bx::uint16_max(blockHeight * minBlockY, ( (_height + blockHeight - 1) / blockHeight)*blockHeight);
|
|
|
_depth = bx::uint16_max(1, _depth);
|
|
|
- _numMips = uint8_t(bx::uint16_max(1, _numMips) );
|
|
|
-
|
|
|
- uint32_t width = _width;
|
|
|
- uint32_t height = _height;
|
|
|
- uint32_t depth = _depth;
|
|
|
- uint32_t sides = _cubeMap ? 6 : 1;
|
|
|
- uint32_t size = 0;
|
|
|
-
|
|
|
- for (uint32_t lod = 0; lod < _numMips; ++lod)
|
|
|
- {
|
|
|
- width = bx::uint32_max(blockWidth * minBlockX, ( (width + blockWidth - 1) / blockWidth )*blockWidth);
|
|
|
- height = bx::uint32_max(blockHeight * minBlockY, ( (height + blockHeight - 1) / blockHeight)*blockHeight);
|
|
|
- depth = bx::uint32_max(1, depth);
|
|
|
-
|
|
|
- size += width*height*depth*bpp/8 * sides;
|
|
|
-
|
|
|
- width >>= 1;
|
|
|
- height >>= 1;
|
|
|
- depth >>= 1;
|
|
|
- }
|
|
|
+ const uint8_t numMips = calcNumMips(_hasMips, _width, _height, _depth);
|
|
|
+ const uint32_t sides = _cubeMap ? 6 : 1;
|
|
|
+ const uint32_t size = _width*_height*_depth*numMips*bpp/8 * sides * _numLayers;
|
|
|
|
|
|
_info.format = _format;
|
|
|
_info.width = _width;
|
|
|
_info.height = _height;
|
|
|
_info.depth = _depth;
|
|
|
- _info.numMips = _numMips;
|
|
|
+ _info.numMips = numMips;
|
|
|
_info.cubeMap = _cubeMap;
|
|
|
_info.storageSize = size;
|
|
|
_info.bitsPerPixel = bpp;
|
|
|
@@ -2950,7 +2933,7 @@ error:
|
|
|
_height = bx::uint16_max(1, _height);
|
|
|
}
|
|
|
|
|
|
- static TextureHandle createTexture2D(BackbufferRatio::Enum _ratio, uint16_t _width, uint16_t _height, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags, const Memory* _mem)
|
|
|
+ static TextureHandle createTexture2D(BackbufferRatio::Enum _ratio, uint16_t _width, uint16_t _height, bool _hasMips, uint16_t _numLayers, TextureFormat::Enum _format, uint32_t _flags, const Memory* _mem)
|
|
|
{
|
|
|
BGFX_CHECK_MAIN_THREAD();
|
|
|
|
|
|
@@ -2969,13 +2952,13 @@ error:
|
|
|
getTextureSizeFromRatio(_ratio, _width, _height);
|
|
|
}
|
|
|
|
|
|
- _numMips = calcNumMips(_numMips, _width, _height);
|
|
|
+ const uint8_t numMips = calcNumMips(_hasMips, _width, _height);
|
|
|
|
|
|
if (BX_ENABLED(BGFX_CONFIG_DEBUG)
|
|
|
&& NULL != _mem)
|
|
|
{
|
|
|
TextureInfo ti;
|
|
|
- calcTextureSize(ti, _width, _height, 1, false, _numMips, _format);
|
|
|
+ calcTextureSize(ti, _width, _height, 1, false, _hasMips, _numLayers, _format);
|
|
|
BX_CHECK(ti.storageSize == _mem->size
|
|
|
, "createTexture2D: Texture storage size doesn't match passed memory size (storage size: %d, memory size: %d)"
|
|
|
, ti.storageSize
|
|
|
@@ -2995,7 +2978,7 @@ error:
|
|
|
tc.m_height = _height;
|
|
|
tc.m_sides = 0;
|
|
|
tc.m_depth = 0;
|
|
|
- tc.m_numMips = _numMips;
|
|
|
+ tc.m_numMips = numMips;
|
|
|
tc.m_format = _format;
|
|
|
tc.m_cubeMap = false;
|
|
|
tc.m_mem = _mem;
|
|
|
@@ -3004,19 +2987,19 @@ error:
|
|
|
return s_ctx->createTexture(mem, _flags, 0, NULL, _ratio);
|
|
|
}
|
|
|
|
|
|
- TextureHandle createTexture2D(uint16_t _width, uint16_t _height, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags, const Memory* _mem)
|
|
|
+ TextureHandle createTexture2D(uint16_t _width, uint16_t _height, bool _hasMips, uint16_t _numLayers, TextureFormat::Enum _format, uint32_t _flags, const Memory* _mem)
|
|
|
{
|
|
|
BX_CHECK(_width > 0 && _height > 0, "Invalid texture size (width %d, height %d).", _width, _height);
|
|
|
- return createTexture2D(BackbufferRatio::Count, _width, _height, _numMips, _format, _flags, _mem);
|
|
|
+ return createTexture2D(BackbufferRatio::Count, _width, _height, _hasMips, _numLayers, _format, _flags, _mem);
|
|
|
}
|
|
|
|
|
|
- TextureHandle createTexture2D(BackbufferRatio::Enum _ratio, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags)
|
|
|
+ TextureHandle createTexture2D(BackbufferRatio::Enum _ratio, bool _hasMips, uint16_t _numLayers, TextureFormat::Enum _format, uint32_t _flags)
|
|
|
{
|
|
|
BX_CHECK(_ratio < BackbufferRatio::Count, "Invalid back buffer ratio.");
|
|
|
- return createTexture2D(_ratio, 0, 0, _numMips, _format, _flags, NULL);
|
|
|
+ return createTexture2D(_ratio, 0, 0, _hasMips, _numLayers, _format, _flags, NULL);
|
|
|
}
|
|
|
|
|
|
- TextureHandle createTexture3D(uint16_t _width, uint16_t _height, uint16_t _depth, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags, const Memory* _mem)
|
|
|
+ TextureHandle createTexture3D(uint16_t _width, uint16_t _height, uint16_t _depth, bool _hasMips, TextureFormat::Enum _format, uint32_t _flags, const Memory* _mem)
|
|
|
{
|
|
|
BGFX_CHECK_MAIN_THREAD();
|
|
|
BGFX_CHECK_CAPS(BGFX_CAPS_TEXTURE_3D, "Texture3D is not supported!");
|
|
|
@@ -3025,13 +3008,13 @@ error:
|
|
|
, getName(_format)
|
|
|
);
|
|
|
|
|
|
- _numMips = calcNumMips(_numMips, _width, _height, _depth);
|
|
|
+ const uint8_t numMips = calcNumMips(_hasMips, _width, _height, _depth);
|
|
|
|
|
|
if (BX_ENABLED(BGFX_CONFIG_DEBUG)
|
|
|
&& NULL != _mem)
|
|
|
{
|
|
|
TextureInfo ti;
|
|
|
- calcTextureSize(ti, _width, _height, _depth, false, _numMips, _format);
|
|
|
+ calcTextureSize(ti, _width, _height, _depth, false, _hasMips, 1, _format);
|
|
|
BX_CHECK(ti.storageSize == _mem->size
|
|
|
, "createTexture3D: Texture storage size doesn't match passed memory size (storage size: %d, memory size: %d)"
|
|
|
, ti.storageSize
|
|
|
@@ -3051,7 +3034,7 @@ error:
|
|
|
tc.m_height = _height;
|
|
|
tc.m_sides = 0;
|
|
|
tc.m_depth = _depth;
|
|
|
- tc.m_numMips = _numMips;
|
|
|
+ tc.m_numMips = numMips;
|
|
|
tc.m_format = _format;
|
|
|
tc.m_cubeMap = false;
|
|
|
tc.m_mem = _mem;
|
|
|
@@ -3060,7 +3043,7 @@ error:
|
|
|
return s_ctx->createTexture(mem, _flags, 0, NULL, BackbufferRatio::Count);
|
|
|
}
|
|
|
|
|
|
- TextureHandle createTextureCube(uint16_t _size, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags, const Memory* _mem)
|
|
|
+ TextureHandle createTextureCube(uint16_t _size, bool _hasMips, uint16_t _numLayers, TextureFormat::Enum _format, uint32_t _flags, const Memory* _mem)
|
|
|
{
|
|
|
BGFX_CHECK_MAIN_THREAD();
|
|
|
BX_CHECK(0 != (g_caps.formats[_format] & (BGFX_CAPS_FORMAT_TEXTURE_CUBE|BGFX_CAPS_FORMAT_TEXTURE_CUBE_EMULATED|BGFX_CAPS_FORMAT_TEXTURE_CUBE_SRGB) )
|
|
|
@@ -3068,13 +3051,13 @@ error:
|
|
|
, getName(_format)
|
|
|
);
|
|
|
|
|
|
- _numMips = calcNumMips(_numMips, _size, _size);
|
|
|
+ const uint8_t numMips = calcNumMips(_hasMips, _size, _size);
|
|
|
|
|
|
if (BX_ENABLED(BGFX_CONFIG_DEBUG)
|
|
|
&& NULL != _mem)
|
|
|
{
|
|
|
TextureInfo ti;
|
|
|
- calcTextureSize(ti, _size, _size, 1, true, _numMips, _format);
|
|
|
+ calcTextureSize(ti, _size, _size, 1, true, _hasMips, _numLayers, _format);
|
|
|
BX_CHECK(ti.storageSize == _mem->size
|
|
|
, "createTextureCube: Texture storage size doesn't match passed memory size (storage size: %d, memory size: %d)"
|
|
|
, ti.storageSize
|
|
|
@@ -3094,7 +3077,7 @@ error:
|
|
|
tc.m_height = _size;
|
|
|
tc.m_sides = 6;
|
|
|
tc.m_depth = 0;
|
|
|
- tc.m_numMips = _numMips;
|
|
|
+ tc.m_numMips = numMips;
|
|
|
tc.m_format = _format;
|
|
|
tc.m_cubeMap = true;
|
|
|
tc.m_mem = _mem;
|
|
|
@@ -3177,7 +3160,7 @@ error:
|
|
|
FrameBufferHandle createFrameBuffer(uint16_t _width, uint16_t _height, TextureFormat::Enum _format, uint32_t _textureFlags)
|
|
|
{
|
|
|
_textureFlags |= _textureFlags&BGFX_TEXTURE_RT_MSAA_MASK ? 0 : BGFX_TEXTURE_RT;
|
|
|
- TextureHandle th = createTexture2D(_width, _height, 1, _format, _textureFlags);
|
|
|
+ TextureHandle th = createTexture2D(_width, _height, false, 1, _format, _textureFlags);
|
|
|
return createFrameBuffer(1, &th, true);
|
|
|
}
|
|
|
|
|
|
@@ -3185,7 +3168,7 @@ error:
|
|
|
{
|
|
|
BX_CHECK(_ratio < BackbufferRatio::Count, "Invalid back buffer ratio.");
|
|
|
_textureFlags |= _textureFlags&BGFX_TEXTURE_RT_MSAA_MASK ? 0 : BGFX_TEXTURE_RT;
|
|
|
- TextureHandle th = createTexture2D(_ratio, 1, _format, _textureFlags);
|
|
|
+ TextureHandle th = createTexture2D(_ratio, false, 1, _format, _textureFlags);
|
|
|
return createFrameBuffer(1, &th, true);
|
|
|
}
|
|
|
|
|
|
@@ -4156,10 +4139,10 @@ BGFX_C_API void bgfx_destroy_program(bgfx_program_handle_t _handle)
|
|
|
bgfx::destroyProgram(handle.cpp);
|
|
|
}
|
|
|
|
|
|
-BGFX_C_API void bgfx_calc_texture_size(bgfx_texture_info_t* _info, uint16_t _width, uint16_t _height, uint16_t _depth, bool _cubeMap, uint8_t _numMips, bgfx_texture_format_t _format)
|
|
|
+BGFX_C_API void bgfx_calc_texture_size(bgfx_texture_info_t* _info, uint16_t _width, uint16_t _height, uint16_t _depth, bool _cubeMap, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format)
|
|
|
{
|
|
|
bgfx::TextureInfo& info = *(bgfx::TextureInfo*)_info;
|
|
|
- bgfx::calcTextureSize(info, _width, _height, _depth, _cubeMap, _numMips, bgfx::TextureFormat::Enum(_format) );
|
|
|
+ bgfx::calcTextureSize(info, _width, _height, _depth, _cubeMap, _hasMips, _numLayers, bgfx::TextureFormat::Enum(_format) );
|
|
|
}
|
|
|
|
|
|
BGFX_C_API bgfx_texture_handle_t bgfx_create_texture(const bgfx_memory_t* _mem, uint32_t _flags, uint8_t _skip, bgfx_texture_info_t* _info)
|
|
|
@@ -4170,31 +4153,31 @@ BGFX_C_API bgfx_texture_handle_t bgfx_create_texture(const bgfx_memory_t* _mem,
|
|
|
return handle.c;
|
|
|
}
|
|
|
|
|
|
-BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_2d(uint16_t _width, uint16_t _height, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem)
|
|
|
+BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_2d(uint16_t _width, uint16_t _height, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem)
|
|
|
{
|
|
|
union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle;
|
|
|
- handle.cpp = bgfx::createTexture2D(_width, _height, _numMips, bgfx::TextureFormat::Enum(_format), _flags, (const bgfx::Memory*)_mem);
|
|
|
+ handle.cpp = bgfx::createTexture2D(_width, _height, _hasMips, _numLayers, bgfx::TextureFormat::Enum(_format), _flags, (const bgfx::Memory*)_mem);
|
|
|
return handle.c;
|
|
|
}
|
|
|
|
|
|
-BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_2d_scaled(bgfx_backbuffer_ratio_t _ratio, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags)
|
|
|
+BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_2d_scaled(bgfx_backbuffer_ratio_t _ratio, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format, uint32_t _flags)
|
|
|
{
|
|
|
union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle;
|
|
|
- handle.cpp = bgfx::createTexture2D(bgfx::BackbufferRatio::Enum(_ratio), _numMips, bgfx::TextureFormat::Enum(_format), _flags);
|
|
|
+ handle.cpp = bgfx::createTexture2D(bgfx::BackbufferRatio::Enum(_ratio), _hasMips, _numLayers, bgfx::TextureFormat::Enum(_format), _flags);
|
|
|
return handle.c;
|
|
|
}
|
|
|
|
|
|
-BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_3d(uint16_t _width, uint16_t _height, uint16_t _depth, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem)
|
|
|
+BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_3d(uint16_t _width, uint16_t _height, uint16_t _depth, bool _hasMips, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem)
|
|
|
{
|
|
|
union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle;
|
|
|
- handle.cpp = bgfx::createTexture3D(_width, _height, _depth, _numMips, bgfx::TextureFormat::Enum(_format), _flags, (const bgfx::Memory*)_mem);
|
|
|
+ handle.cpp = bgfx::createTexture3D(_width, _height, _depth, _hasMips, bgfx::TextureFormat::Enum(_format), _flags, (const bgfx::Memory*)_mem);
|
|
|
return handle.c;
|
|
|
}
|
|
|
|
|
|
-BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_cube(uint16_t _size, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem)
|
|
|
+BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_cube(uint16_t _size, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format, uint32_t _flags, const bgfx_memory_t* _mem)
|
|
|
{
|
|
|
union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle;
|
|
|
- handle.cpp = bgfx::createTextureCube(_size, _numMips, bgfx::TextureFormat::Enum(_format), _flags, (const bgfx::Memory*)_mem);
|
|
|
+ handle.cpp = bgfx::createTextureCube(_size, _hasMips, _numLayers, bgfx::TextureFormat::Enum(_format), _flags, (const bgfx::Memory*)_mem);
|
|
|
return handle.c;
|
|
|
}
|
|
|
|