mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-28 18:45:54 -05:00
Fixed init/shutdown code, so it can be called multiple time from the same app.
This commit is contained in:
parent
a165353896
commit
ed0055caad
2 changed files with 36 additions and 1 deletions
15
src/bgfx.cpp
15
src/bgfx.cpp
|
@ -681,8 +681,15 @@ namespace bgfx
|
||||||
|
|
||||||
void Context::init(bool _createRenderThread)
|
void Context::init(bool _createRenderThread)
|
||||||
{
|
{
|
||||||
|
BX_CHECK(!m_rendererInitialized, "Already initialized?");
|
||||||
BX_TRACE("init");
|
BX_TRACE("init");
|
||||||
|
|
||||||
|
m_exit = false;
|
||||||
|
m_frames = 0;
|
||||||
|
m_render = &m_frame[0];
|
||||||
|
m_submit = &m_frame[1];
|
||||||
|
m_debug = BGFX_DEBUG_NONE;
|
||||||
|
|
||||||
m_submit->create();
|
m_submit->create();
|
||||||
m_render->create();
|
m_render->create();
|
||||||
|
|
||||||
|
@ -707,7 +714,9 @@ namespace bgfx
|
||||||
m_rect[ii].m_height = 1;
|
m_rect[ii].m_height = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
gameSemPost();
|
m_declRef.init();
|
||||||
|
|
||||||
|
frameNoRenderWait();
|
||||||
|
|
||||||
getCommandBuffer(CommandBuffer::RendererInit);
|
getCommandBuffer(CommandBuffer::RendererInit);
|
||||||
|
|
||||||
|
@ -742,6 +751,8 @@ namespace bgfx
|
||||||
getCommandBuffer(CommandBuffer::RendererShutdownEnd);
|
getCommandBuffer(CommandBuffer::RendererShutdownEnd);
|
||||||
frame();
|
frame();
|
||||||
|
|
||||||
|
m_declRef.shutdown(m_vertexDeclHandle);
|
||||||
|
|
||||||
#if BGFX_CONFIG_MULTITHREADED
|
#if BGFX_CONFIG_MULTITHREADED
|
||||||
if (m_thread.isRunning() )
|
if (m_thread.isRunning() )
|
||||||
{
|
{
|
||||||
|
@ -749,6 +760,8 @@ namespace bgfx
|
||||||
}
|
}
|
||||||
#endif // BGFX_CONFIG_MULTITHREADED
|
#endif // BGFX_CONFIG_MULTITHREADED
|
||||||
|
|
||||||
|
renderSemWait();
|
||||||
|
|
||||||
m_submit->destroy();
|
m_submit->destroy();
|
||||||
m_render->destroy();
|
m_render->destroy();
|
||||||
|
|
||||||
|
|
22
src/bgfx_p.h
22
src/bgfx_p.h
|
@ -945,6 +945,7 @@ namespace bgfx
|
||||||
{
|
{
|
||||||
m_constantBuffer = ConstantBuffer::create(BGFX_CONFIG_MAX_CONSTANT_BUFFER_SIZE);
|
m_constantBuffer = ConstantBuffer::create(BGFX_CONFIG_MAX_CONSTANT_BUFFER_SIZE);
|
||||||
reset();
|
reset();
|
||||||
|
finish();
|
||||||
m_textVideoMem = new TextVideoMem;
|
m_textVideoMem = new TextVideoMem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1309,11 +1310,25 @@ namespace bgfx
|
||||||
struct VertexDeclRef
|
struct VertexDeclRef
|
||||||
{
|
{
|
||||||
VertexDeclRef()
|
VertexDeclRef()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void init()
|
||||||
{
|
{
|
||||||
memset(m_vertexDeclRef, 0, sizeof(m_vertexDeclRef) );
|
memset(m_vertexDeclRef, 0, sizeof(m_vertexDeclRef) );
|
||||||
memset(m_vertexBufferRef, 0xff, sizeof(m_vertexBufferRef) );
|
memset(m_vertexBufferRef, 0xff, sizeof(m_vertexBufferRef) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void shutdown(HandleAlloc& _handleAlloc)
|
||||||
|
{
|
||||||
|
for (VertexDeclMap::iterator it = m_vertexDeclMap.begin(), itEnd = m_vertexDeclMap.end(); it != itEnd; ++it)
|
||||||
|
{
|
||||||
|
_handleAlloc.free(it->second.idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_vertexDeclMap.clear();
|
||||||
|
}
|
||||||
|
|
||||||
VertexDeclHandle find(uint32_t _hash)
|
VertexDeclHandle find(uint32_t _hash)
|
||||||
{
|
{
|
||||||
VertexDeclMap::const_iterator it = m_vertexDeclMap.find(_hash);
|
VertexDeclMap::const_iterator it = m_vertexDeclMap.find(_hash);
|
||||||
|
@ -1502,7 +1517,11 @@ namespace bgfx
|
||||||
{
|
{
|
||||||
// wait for render thread to finish
|
// wait for render thread to finish
|
||||||
renderSemWait();
|
renderSemWait();
|
||||||
|
frameNoRenderWait();
|
||||||
|
}
|
||||||
|
|
||||||
|
void frameNoRenderWait()
|
||||||
|
{
|
||||||
swap();
|
swap();
|
||||||
|
|
||||||
// release render thread
|
// release render thread
|
||||||
|
@ -2523,6 +2542,7 @@ namespace bgfx
|
||||||
{
|
{
|
||||||
case CommandBuffer::RendererInit:
|
case CommandBuffer::RendererInit:
|
||||||
{
|
{
|
||||||
|
BX_CHECK(!m_rendererInitialized, "This shouldn't happen! Bad synchronization?");
|
||||||
rendererInit();
|
rendererInit();
|
||||||
m_rendererInitialized = true;
|
m_rendererInitialized = true;
|
||||||
}
|
}
|
||||||
|
@ -2530,12 +2550,14 @@ namespace bgfx
|
||||||
|
|
||||||
case CommandBuffer::RendererShutdownBegin:
|
case CommandBuffer::RendererShutdownBegin:
|
||||||
{
|
{
|
||||||
|
BX_CHECK(m_rendererInitialized, "This shouldn't happen! Bad synchronization?");
|
||||||
m_rendererInitialized = false;
|
m_rendererInitialized = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CommandBuffer::RendererShutdownEnd:
|
case CommandBuffer::RendererShutdownEnd:
|
||||||
{
|
{
|
||||||
|
BX_CHECK(!m_rendererInitialized && !m_exit, "This shouldn't happen! Bad synchronization?");
|
||||||
rendererShutdown();
|
rendererShutdown();
|
||||||
m_exit = true;
|
m_exit = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue