diff --git a/examples/common/entry/entry_osx.mm b/examples/common/entry/entry_osx.mm index 86fba91f..61575e23 100644 --- a/examples/common/entry/entry_osx.mm +++ b/examples/common/entry/entry_osx.mm @@ -13,6 +13,7 @@ #include #include +#include #define DEFAULT_WIDTH 1280 #define DEFAULT_HEIGHT 720 @@ -225,7 +226,8 @@ namespace entry NSString* appName = [[NSProcessInfo processInfo] processName]; [window setTitle:appName]; [window cascadeTopLeftFromPoint:NSMakePoint(20,20)]; - [window makeKeyAndOrderFront:nil]; + [window makeKeyAndOrderFront:window]; + [window setContentView:nil]; [[Window sharedDelegate] windowCreated:window]; bgfx::osxSetNSWindow(window); @@ -239,11 +241,18 @@ namespace entry while (!(m_exit = [dg applicationHasTerminated]) ) { - DispatchEvent(WaitEvent() ); + //DispatchEvent(WaitEvent() ); + if (bgfx::RenderFrame::Exiting == bgfx::renderFrame() ) + { + break; + } while (DispatchEvent(PeekEvent() ) ); } + + m_eventQueue.postExitEvent(); + while (bgfx::RenderFrame::NoContext != bgfx::renderFrame() ); thread.shutdown(); return 0; diff --git a/include/bgfxplatform.h b/include/bgfxplatform.h index 43506171..37cb68b2 100755 --- a/include/bgfxplatform.h +++ b/include/bgfxplatform.h @@ -12,6 +12,26 @@ #include +namespace bgfx +{ + struct RenderFrame + { + enum Enum + { + NoContext, + Render, + Exiting, + + Count + }; + }; + + /// WARNING: This call should be only used on platforms that don't + /// allow creating separate rendering thread. Proper use requires + /// changes inside lib. + RenderFrame::Enum renderFrame(); +} + #if BX_PLATFORM_ANDROID # include diff --git a/src/bgfx.cpp b/src/bgfx.cpp index a0cccb8d..170cb4e6 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -197,11 +197,6 @@ namespace bgfx static BX_THREAD uint32_t s_threadIndex = 0; static Context* s_ctx = NULL; - bool hasContext() - { - return NULL != s_ctx; - } - void setGraphicsDebuggerPresent(bool _present) { BX_TRACE("Graphics debugger is %spresent.", _present ? "" : "not "); @@ -710,7 +705,7 @@ 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); + s_ctx->init(!BX_PLATFORM_NACL && !BX_PLATFORM_IOS && !BX_PLATFORM_OSX); BX_TRACE("Init complete."); } @@ -720,9 +715,10 @@ namespace bgfx BX_TRACE("Shutdown..."); BGFX_CHECK_MAIN_THREAD(); - s_ctx->shutdown(); + Context* ctx = s_ctx; // it's going to be NULLd inside shutdown. + ctx->shutdown(); - BX_DELETE(g_allocator, s_ctx); + BX_DELETE(g_allocator, ctx); if (NULL != s_callbackStub) { @@ -758,10 +754,20 @@ namespace bgfx return s_ctx->frame(); } - bool renderFrame() + RenderFrame::Enum renderFrame() { + if (NULL == s_ctx) + { + return RenderFrame::NoContext; + } + BGFX_CHECK_RENDER_THREAD(); - return s_ctx->renderFrame(); + if (s_ctx->renderFrame() ) + { + return RenderFrame::Exiting; + } + + return RenderFrame::Render; } const uint32_t g_uniformTypeSize[UniformType::Count+1] = @@ -891,6 +897,7 @@ namespace bgfx } #endif // BGFX_CONFIG_MULTITHREADED + s_ctx = NULL; // Can't be used by renderFrame at this point. renderSemWait(); m_submit->destroy(); diff --git a/src/bgfx_p.h b/src/bgfx_p.h index 4d5e7c9f..184e6985 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -73,6 +73,7 @@ namespace bgfx #include #include +#include "bgfxplatform.h" #include "image.h" #define BGFX_CHUNK_MAGIC_FSH BX_MAKEFOURCC('F', 'S', 'H', 0x1) @@ -233,7 +234,6 @@ namespace bgfx bool isGraphicsDebuggerPresent(); void release(const Memory* _mem); const char* getAttribName(Attrib::Enum _attr); - bool renderFrame(); inline uint32_t gcd(uint32_t _a, uint32_t _b) { diff --git a/src/glcontext_ppapi.cpp b/src/glcontext_ppapi.cpp index fcecce54..19c9f38a 100644 --- a/src/glcontext_ppapi.cpp +++ b/src/glcontext_ppapi.cpp @@ -15,8 +15,6 @@ namespace bgfx # include "glimports.h" # undef GL_IMPORT - extern bool hasContext(); - void naclSwapCompleteCb(void* /*_data*/, int32_t /*_result*/); PP_CompletionCallback naclSwapComplete = @@ -80,10 +78,7 @@ namespace bgfx s_ppapi.swap(); } - if (hasContext() ) - { - renderFrame(); - } + renderFrame(); } static void GL_APIENTRY naclVertexAttribDivisor(GLuint _index, GLuint _divisor)