diff --git a/include/bgfx/c99/platform.h b/include/bgfx/c99/platform.h index 217371bc5..8e44aeea6 100644 --- a/include/bgfx/c99/platform.h +++ b/include/bgfx/c99/platform.h @@ -19,6 +19,7 @@ typedef enum bgfx_render_frame { BGFX_RENDER_FRAME_NO_CONTEXT, BGFX_RENDER_FRAME_RENDER, + BGFX_RENDER_FRAME_TIMEOUT, BGFX_RENDER_FRAME_EXITING, BGFX_RENDER_FRAME_COUNT diff --git a/include/bgfx/defines.h b/include/bgfx/defines.h index c83385692..2776d5a97 100644 --- a/include/bgfx/defines.h +++ b/include/bgfx/defines.h @@ -6,7 +6,7 @@ #ifndef BGFX_DEFINES_H_HEADER_GUARD #define BGFX_DEFINES_H_HEADER_GUARD -#define BGFX_API_VERSION UINT32_C(35) +#define BGFX_API_VERSION UINT32_C(36) /// #define BGFX_STATE_RGB_WRITE UINT64_C(0x0000000000000001) //!< Enable RGB write. diff --git a/include/bgfx/platform.h b/include/bgfx/platform.h index fa539c114..1c9b3c754 100644 --- a/include/bgfx/platform.h +++ b/include/bgfx/platform.h @@ -25,6 +25,7 @@ namespace bgfx { NoContext, Render, + Timeout, Exiting, Count diff --git a/src/bgfx.cpp b/src/bgfx.cpp index b1469777e..cbcc7660a 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -1032,16 +1032,16 @@ namespace bgfx } BGFX_CHECK_RENDER_THREAD(); - if (s_ctx->renderFrame() ) + RenderFrame::Enum result = s_ctx->renderFrame(BGFX_CONFIG_API_SEMAPHORE_TIMEOUT); + if (RenderFrame::Exiting == result) { Context* ctx = s_ctx; ctx->apiSemWait(); s_ctx = NULL; ctx->renderSemPost(); - return RenderFrame::Exiting; } - return RenderFrame::Render; + return result; } BX_CHECK(false, "This call only makes sense if used with multi-threaded renderer."); @@ -1646,7 +1646,7 @@ namespace bgfx return m_uniformRef[_handle.idx].m_name.getPtr(); } - bool Context::renderFrame() + RenderFrame::Enum Context::renderFrame(int32_t _msecs) { BGFX_PROFILER_SCOPE(bgfx, render_frame, 0xff2040ff); @@ -1658,7 +1658,7 @@ namespace bgfx m_flipped = true; } - if (apiSemWait(BGFX_CONFIG_API_SEMAPHORE_TIMEOUT) ) + if (apiSemWait(_msecs) ) { rendererExecCommands(m_render->m_cmdPre); if (m_rendererInitialized) @@ -1678,8 +1678,15 @@ namespace bgfx m_flipped = true; } } + else + { + return RenderFrame::Timeout; + } - return m_exit; + return m_exit + ? RenderFrame::Exiting + : RenderFrame::Render + ; } void rendererUpdateUniforms(RendererContextI* _renderCtx, UniformBuffer* _uniformBuffer, uint32_t _begin, uint32_t _end) diff --git a/src/bgfx_p.h b/src/bgfx_p.h index 0248023c6..aca9a3a84 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -4041,7 +4041,7 @@ namespace bgfx const char* getName(UniformHandle _handle) const; // render thread - bool renderFrame(); + RenderFrame::Enum renderFrame(int32_t _msecs = -1); void flushTextureUpdateBatch(CommandBuffer& _cmdbuf); void rendererExecCommands(CommandBuffer& _cmdbuf);