summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bgfx/src/bgfx.cpp
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/bgfx/src/bgfx.cpp')
-rw-r--r--3rdparty/bgfx/src/bgfx.cpp102
1 files changed, 70 insertions, 32 deletions
diff --git a/3rdparty/bgfx/src/bgfx.cpp b/3rdparty/bgfx/src/bgfx.cpp
index 3a353942cc5..677d7e26a25 100644
--- a/3rdparty/bgfx/src/bgfx.cpp
+++ b/3rdparty/bgfx/src/bgfx.cpp
@@ -485,12 +485,12 @@ namespace bgfx
memcpy(vertex, vert, sizeof(vert) );
vertex += 4;
- indices[0] = startVertex+0;
- indices[1] = startVertex+1;
- indices[2] = startVertex+2;
- indices[3] = startVertex+2;
- indices[4] = startVertex+3;
- indices[5] = startVertex+0;
+ indices[0] = uint16_t(startVertex+0);
+ indices[1] = uint16_t(startVertex+1);
+ indices[2] = uint16_t(startVertex+2);
+ indices[3] = uint16_t(startVertex+2);
+ indices[4] = uint16_t(startVertex+3);
+ indices[5] = uint16_t(startVertex+0);
startVertex += 4;
indices += 6;
@@ -819,6 +819,10 @@ namespace bgfx
BGFX_CHECK_RENDER_THREAD();
if (s_ctx->renderFrame() )
{
+ Context* ctx = s_ctx;
+ ctx->gameSemWait();
+ s_ctx = NULL;
+ ctx->renderSemPost();
return RenderFrame::Exiting;
}
@@ -969,7 +973,7 @@ namespace bgfx
for (uint32_t ii = 0; ii < BX_COUNTOF(m_viewRemap); ++ii)
{
- m_viewRemap[ii] = ii;
+ m_viewRemap[ii] = uint8_t(ii);
}
memset(m_fb, 0xff, sizeof(m_fb) );
@@ -1054,15 +1058,18 @@ namespace bgfx
m_declRef.shutdown(m_vertexDeclHandle);
#if BGFX_CONFIG_MULTITHREADED
+ // Render thread shutdown sequence.
+ renderSemWait(); // Wait for previous frame.
+ gameSemPost(); // OK to set context to NULL.
+ // s_ctx is NULL here.
+ renderSemWait(); // In RenderFrame::Exiting state.
+
if (m_thread.isRunning() )
{
m_thread.shutdown();
}
#endif // BGFX_CONFIG_MULTITHREADED
- s_ctx = NULL; // Can't be used by renderFrame at this point.
- renderSemWait();
-
m_submit->destroy();
m_render->destroy();
@@ -1204,7 +1211,10 @@ namespace bgfx
freeAllHandles(m_submit);
m_submit->resetFreeHandles();
- m_submit->m_textVideoMem->resize(m_render->m_textVideoMem->m_small, m_resolution.m_width, m_resolution.m_height);
+ m_submit->m_textVideoMem->resize(m_render->m_textVideoMem->m_small
+ , m_resolution.m_width
+ , m_resolution.m_height
+ );
}
bool Context::renderFrame()
@@ -2099,18 +2109,41 @@ again:
return mem;
}
- const Memory* makeRef(const void* _data, uint32_t _size)
+ struct MemoryRef
{
- Memory* mem = (Memory*)BX_ALLOC(g_allocator, sizeof(Memory) );
- mem->size = _size;
- mem->data = (uint8_t*)_data;
- return mem;
+ Memory mem;
+ ReleaseFn releaseFn;
+ void* userData;
+ };
+
+ const Memory* makeRef(const void* _data, uint32_t _size, ReleaseFn _releaseFn, void* _userData)
+ {
+ MemoryRef* memRef = (MemoryRef*)BX_ALLOC(g_allocator, sizeof(MemoryRef) );
+ memRef->mem.size = _size;
+ memRef->mem.data = (uint8_t*)_data;
+ memRef->releaseFn = _releaseFn;
+ memRef->userData = _userData;
+ return &memRef->mem;
+ }
+
+ bool isMemoryRef(const Memory* _mem)
+ {
+ return _mem->data != (uint8_t*)_mem + sizeof(Memory);
}
void release(const Memory* _mem)
{
BX_CHECK(NULL != _mem, "_mem can't be NULL");
- BX_FREE(g_allocator, const_cast<Memory*>(_mem) );
+ Memory* mem = const_cast<Memory*>(_mem);
+ if (isMemoryRef(mem) )
+ {
+ MemoryRef* memRef = reinterpret_cast<MemoryRef*>(mem);
+ if (NULL != memRef->releaseFn)
+ {
+ memRef->releaseFn(mem->data, memRef->userData);
+ }
+ }
+ BX_FREE(g_allocator, mem);
}
void setDebug(uint32_t _debug)
@@ -2350,15 +2383,15 @@ again:
{
const ImageBlockInfo& blockInfo = getBlockInfo(_format);
const uint8_t bpp = blockInfo.bitsPerPixel;
- const uint32_t blockWidth = blockInfo.blockWidth;
- const uint32_t blockHeight = blockInfo.blockHeight;
- const uint32_t minBlockX = blockInfo.minBlockX;
- const uint32_t minBlockY = blockInfo.minBlockY;
+ const uint16_t blockWidth = blockInfo.blockWidth;
+ const uint16_t blockHeight = blockInfo.blockHeight;
+ const uint16_t minBlockX = blockInfo.minBlockX;
+ const uint16_t minBlockY = blockInfo.minBlockY;
- _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);
- _numMips = bx::uint32_max(1, _numMips);
+ _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;
@@ -2400,7 +2433,7 @@ again:
{
BGFX_CHECK_MAIN_THREAD();
- _numMips = bx::uint32_max(1, _numMips);
+ _numMips = uint8_t(bx::uint32_max(1, _numMips) );
if (BX_ENABLED(BGFX_CONFIG_DEBUG)
&& NULL != _mem)
@@ -2441,7 +2474,7 @@ again:
BGFX_CHECK_MAIN_THREAD();
BX_CHECK(0 != (g_caps.supported & BGFX_CAPS_TEXTURE_3D), "Texture3D is not supported! Use bgfx::getCaps to check backend renderer capabilities.");
- _numMips = bx::uint32_max(1, _numMips);
+ _numMips = uint8_t(bx::uint32_max(1, _numMips) );
if (BX_ENABLED(BGFX_CONFIG_DEBUG)
&& NULL != _mem)
@@ -2481,7 +2514,7 @@ again:
{
BGFX_CHECK_MAIN_THREAD();
- _numMips = bx::uint32_max(1, _numMips);
+ _numMips = uint8_t(bx::uint32_max(1, _numMips) );
if (BX_ENABLED(BGFX_CONFIG_DEBUG)
&& NULL != _mem)
@@ -2621,10 +2654,10 @@ again:
{
BGFX_CHECK_MAIN_THREAD();
- const uint8_t rr = _rgba>>24;
- const uint8_t gg = _rgba>>16;
- const uint8_t bb = _rgba>> 8;
- const uint8_t aa = _rgba>> 0;
+ const uint8_t rr = uint8_t(_rgba>>24);
+ const uint8_t gg = uint8_t(_rgba>>16);
+ const uint8_t bb = uint8_t(_rgba>> 8);
+ const uint8_t aa = uint8_t(_rgba>> 0);
float rgba[4] =
{
@@ -3073,6 +3106,11 @@ BGFX_C_API const bgfx_memory_t* bgfx_make_ref(const void* _data, uint32_t _size)
return (const bgfx_memory_t*)bgfx::makeRef(_data, _size);
}
+BGFX_C_API const bgfx_memory_t* bgfx_make_ref_release(const void* _data, uint32_t _size, bgfx_release_fn_t _releaseFn, void* _userData)
+{
+ return (const bgfx_memory_t*)bgfx::makeRef(_data, _size, _releaseFn, _userData);
+}
+
BGFX_C_API void bgfx_set_debug(uint32_t _debug)
{
bgfx::setDebug(_debug);