From e8075dc3679c5e601d4aa4e13334c385d529398b Mon Sep 17 00:00:00 2001 From: bkaradzic Date: Sun, 19 Jan 2014 14:58:05 -0800 Subject: [PATCH] Using renderFrame to setup thread creation behavior. --- examples/common/entry/entry_ios.mm | 3 +++ examples/common/entry/entry_nacl.cpp | 2 +- include/bgfxplatform.h | 6 +++--- src/bgfx.cpp | 7 +++++-- src/bgfx_p.h | 2 +- src/glcontext_ppapi.cpp | 12 ++++++++---- src/renderer_gl.cpp | 9 +++++---- 7 files changed, 26 insertions(+), 15 deletions(-) diff --git a/examples/common/entry/entry_ios.mm b/examples/common/entry/entry_ios.mm index 0e28348ae..17181e520 100644 --- a/examples/common/entry/entry_ios.mm +++ b/examples/common/entry/entry_ios.mm @@ -36,6 +36,9 @@ namespace entry m_eventQueue.postSizeEvent(768, 1024); + // Prevent render thread creation. + bgfx::renderFrame(); + m_thread.init(MainThreadEntry::threadFunc, &m_mte); } diff --git a/examples/common/entry/entry_nacl.cpp b/examples/common/entry/entry_nacl.cpp index 73f16fd0b..2898cfc77 100644 --- a/examples/common/entry/entry_nacl.cpp +++ b/examples/common/entry/entry_nacl.cpp @@ -93,7 +93,7 @@ namespace entry m_mte.m_argc = 1; m_mte.m_argv = const_cast(argv); - bgfx::naclSetIntefraces(g_instance, g_instInterface, g_graphicsInterface, NULL); + bgfx::naclSetInterfaces(g_instance, g_instInterface, g_graphicsInterface, NULL); m_thread.init(MainThreadEntry::threadFunc, &m_mte); } diff --git a/include/bgfxplatform.h b/include/bgfxplatform.h index 37cb68b2d..268091cdd 100755 --- a/include/bgfxplatform.h +++ b/include/bgfxplatform.h @@ -27,8 +27,8 @@ namespace bgfx }; /// WARNING: This call should be only used on platforms that don't - /// allow creating separate rendering thread. Proper use requires - /// changes inside lib. + /// allow creating separate rendering thread. If it is called before + /// to bgfx::init, render thread won't be created by bgfx::init call. RenderFrame::Enum renderFrame(); } @@ -69,7 +69,7 @@ namespace bgfx typedef void (*PostSwapBuffersFn)(uint32_t _width, uint32_t _height); /// - void naclSetIntefraces(::PP_Instance, const ::PPB_Instance*, const ::PPB_Graphics3D*, PostSwapBuffersFn); + void naclSetInterfaces(::PP_Instance, const ::PPB_Instance*, const ::PPB_Graphics3D*, PostSwapBuffersFn); } // namespace bgfx diff --git a/src/bgfx.cpp b/src/bgfx.cpp index 92137e7aa..5d88f4f79 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -209,6 +209,7 @@ namespace bgfx static BX_THREAD uint32_t s_threadIndex = 0; static Context* s_ctx = NULL; + static bool s_renderFrame = false; void setGraphicsDebuggerPresent(bool _present) { @@ -733,8 +734,9 @@ namespace bgfx s_ctx = BX_NEW(g_allocator, Context); - // On NaCl and iOS renderer is on the main thread. - s_ctx->init(!BX_PLATFORM_NACL && !BX_PLATFORM_IOS && !BX_PLATFORM_OSX); + // When bgfx::renderFrame is called before init render thread + // should not be created. + s_ctx->init(!s_renderFrame); const uint64_t emulatedCaps = 0 | BGFX_CAPS_TEXTURE_FORMAT_BC1 @@ -819,6 +821,7 @@ namespace bgfx { if (NULL == s_ctx) { + s_renderFrame = true; return RenderFrame::NoContext; } diff --git a/src/bgfx_p.h b/src/bgfx_p.h index 0adb70c45..f71740b67 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -642,8 +642,8 @@ namespace bgfx { union { - bx::float4x4_t f4x4; float val[16]; + bx::float4x4_t f4x4; } un; void setIdentity() diff --git a/src/glcontext_ppapi.cpp b/src/glcontext_ppapi.cpp index 1707e69af..d2b9afddd 100644 --- a/src/glcontext_ppapi.cpp +++ b/src/glcontext_ppapi.cpp @@ -37,7 +37,7 @@ namespace bgfx { } - void setIntefraces(PP_Instance _instance, const PPB_Instance* _instInterface, const PPB_Graphics3D* _graphicsInterface, PostSwapBuffersFn _postSwapBuffers); + void setInterfaces(PP_Instance _instance, const PPB_Instance* _instInterface, const PPB_Graphics3D* _graphicsInterface, PostSwapBuffersFn _postSwapBuffers); void resize(uint32_t _width, uint32_t _height, bool /*_vsync*/) { @@ -96,14 +96,18 @@ namespace bgfx s_ppapi.m_instancedArrays->DrawElementsInstancedANGLE(s_ppapi.m_context, _mode, _count, _type, _indices, _primcount); } - void naclSetIntefraces(PP_Instance _instance, const PPB_Instance* _instInterface, const PPB_Graphics3D* _graphicsInterface, PostSwapBuffersFn _postSwapBuffers) + void naclSetInterfaces(PP_Instance _instance, const PPB_Instance* _instInterface, const PPB_Graphics3D* _graphicsInterface, PostSwapBuffersFn _postSwapBuffers) { - s_ppapi.setIntefraces( _instance, _instInterface, _graphicsInterface, _postSwapBuffers); + s_ppapi.setInterfaces( _instance, _instInterface, _graphicsInterface, _postSwapBuffers); } - void Ppapi::setIntefraces(PP_Instance _instance, const PPB_Instance* _instInterface, const PPB_Graphics3D* _graphicsInterface, PostSwapBuffersFn _postSwapBuffers) + void Ppapi::setInterfaces(PP_Instance _instance, const PPB_Instance* _instInterface, const PPB_Graphics3D* _graphicsInterface, PostSwapBuffersFn _postSwapBuffers) { BX_TRACE("PPAPI Interfaces"); + + // Prevent render thread creation. + renderFrame(); + m_instance = _instance; m_instInterface = _instInterface; m_graphicsInterface = _graphicsInterface; diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index 526f89a0a..42eee57c2 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -243,12 +243,12 @@ namespace bgfx }; static const Matrix4 s_bias = - { + {{{ 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f, 0.5f, 0.5f, 0.5f, 1.0f, - }; + }}}; struct Extension { @@ -2486,7 +2486,7 @@ namespace bgfx GLint glGet(GLenum _pname) { - GLint result; + GLint result = 0; glGetIntegerv(_pname, &result); GLenum err = glGetError(); BX_WARN(0 == err, "glGetIntegerv(0x%04x, ...) failed with GL error: 0x%04x.", _pname, err); @@ -2498,7 +2498,7 @@ namespace bgfx s_renderCtx = BX_NEW(g_allocator, RendererContext); s_renderCtx->init(); - GLint numCmpFormats; + GLint numCmpFormats = 0; GL_CHECK(glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numCmpFormats) ); BX_TRACE("GL_NUM_COMPRESSED_TEXTURE_FORMATS %d", numCmpFormats); @@ -2506,6 +2506,7 @@ namespace bgfx if (0 < numCmpFormats) { + numCmpFormats = numCmpFormats > 256 ? 256 : numCmpFormats; cmpFormat = (GLint*)alloca(sizeof(GLint)*numCmpFormats); GL_CHECK(glGetIntegerv(GL_COMPRESSED_TEXTURE_FORMATS, cmpFormat) );