diff options
Diffstat (limited to 'intern')
-rw-r--r-- | intern/ghost/GHOST_C-api.h | 3 | ||||
-rw-r--r-- | intern/ghost/GHOST_IXrContext.h | 3 | ||||
-rw-r--r-- | intern/ghost/intern/GHOST_C-api.cpp | 11 | ||||
-rw-r--r-- | intern/ghost/intern/GHOST_XrContext.cpp | 9 | ||||
-rw-r--r-- | intern/ghost/intern/GHOST_XrContext.h | 3 | ||||
-rw-r--r-- | intern/ghost/intern/GHOST_XrSession.cpp | 14 | ||||
-rw-r--r-- | intern/ghost/intern/GHOST_XrSession.h | 2 |
7 files changed, 31 insertions, 14 deletions
diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h index 84bad87e654..557503783e5 100644 --- a/intern/ghost/GHOST_C-api.h +++ b/intern/ghost/GHOST_C-api.h @@ -998,10 +998,11 @@ void GHOST_XrGraphicsContextBindFuncs(GHOST_XrContextHandle xr_context, void GHOST_XrDrawViewFunc(GHOST_XrContextHandle xr_context, GHOST_XrDrawViewFn draw_view_fn); /* sessions */ -int GHOST_XrSessionIsRunning(const GHOST_XrContextHandle xr_context); void GHOST_XrSessionStart(GHOST_XrContextHandle xr_context, const GHOST_XrSessionBeginInfo *begin_info); void GHOST_XrSessionEnd(GHOST_XrContextHandle xr_context); +int GHOST_XrHasSession(const GHOST_XrContextHandle xr_contexthandle); +int GHOST_XrSessionShouldRunDrawLoop(const GHOST_XrContextHandle xr_context); void GHOST_XrSessionDrawViews(GHOST_XrContextHandle xr_context, void *customdata); /* events */ diff --git a/intern/ghost/GHOST_IXrContext.h b/intern/ghost/GHOST_IXrContext.h index 362bc923ee8..968c98ad42e 100644 --- a/intern/ghost/GHOST_IXrContext.h +++ b/intern/ghost/GHOST_IXrContext.h @@ -29,7 +29,8 @@ class GHOST_IXrContext { virtual void startSession(const GHOST_XrSessionBeginInfo *begin_info) = 0; virtual void endSession() = 0; - virtual bool isSessionRunning() const = 0; + virtual bool hasSession() const = 0; + virtual bool shouldRunSessionDrawLoop() const = 0; virtual void drawSessionViews(void *draw_customdata) = 0; virtual void dispatchErrorMessage(const class GHOST_XrException *) const = 0; diff --git a/intern/ghost/intern/GHOST_C-api.cpp b/intern/ghost/intern/GHOST_C-api.cpp index caa88f46ff9..98579985693 100644 --- a/intern/ghost/intern/GHOST_C-api.cpp +++ b/intern/ghost/intern/GHOST_C-api.cpp @@ -937,10 +937,17 @@ void GHOST_XrSessionEnd(GHOST_XrContextHandle xr_contexthandle) GHOST_XR_CAPI_CALL(xr_context->endSession(), xr_context); } -int GHOST_XrSessionIsRunning(const GHOST_XrContextHandle xr_contexthandle) +int GHOST_XrHasSession(const GHOST_XrContextHandle xr_contexthandle) { const GHOST_IXrContext *xr_context = (GHOST_IXrContext *)xr_contexthandle; - GHOST_XR_CAPI_CALL_RET(xr_context->isSessionRunning(), xr_context); + GHOST_XR_CAPI_CALL_RET(xr_context->hasSession(), xr_context); + return 0; // Only reached if exception is thrown. +} + +int GHOST_XrSessionShouldRunDrawLoop(const GHOST_XrContextHandle xr_contexthandle) +{ + const GHOST_IXrContext *xr_context = (GHOST_IXrContext *)xr_contexthandle; + GHOST_XR_CAPI_CALL_RET(xr_context->shouldRunSessionDrawLoop(), xr_context); return 0; // Only reached if exception is thrown. } diff --git a/intern/ghost/intern/GHOST_XrContext.cpp b/intern/ghost/intern/GHOST_XrContext.cpp index 07ed037fb5b..541e23312ea 100644 --- a/intern/ghost/intern/GHOST_XrContext.cpp +++ b/intern/ghost/intern/GHOST_XrContext.cpp @@ -456,9 +456,14 @@ void GHOST_XrContext::endSession() m_session = nullptr; } -bool GHOST_XrContext::isSessionRunning() const +bool GHOST_XrContext::hasSession() const { - return m_session && m_session->isRunning(); + return m_session != nullptr; +} + +bool GHOST_XrContext::shouldRunSessionDrawLoop() const +{ + return m_session && m_session->shouldRunDrawLoop(); } void GHOST_XrContext::drawSessionViews(void *draw_customdata) diff --git a/intern/ghost/intern/GHOST_XrContext.h b/intern/ghost/intern/GHOST_XrContext.h index 6f5c6ab425c..c260e95eb08 100644 --- a/intern/ghost/intern/GHOST_XrContext.h +++ b/intern/ghost/intern/GHOST_XrContext.h @@ -61,7 +61,8 @@ class GHOST_XrContext : public GHOST_IXrContext { void startSession(const GHOST_XrSessionBeginInfo *begin_info) override; void endSession() override; - bool isSessionRunning() const override; + bool hasSession() const override; + bool shouldRunSessionDrawLoop() const override; void drawSessionViews(void *draw_customdata) override; static void setErrorHandler(GHOST_XrErrorHandlerFn handler_fn, void *customdata); diff --git a/intern/ghost/intern/GHOST_XrSession.cpp b/intern/ghost/intern/GHOST_XrSession.cpp index f2f01a9b354..f2f94d8f47d 100644 --- a/intern/ghost/intern/GHOST_XrSession.cpp +++ b/intern/ghost/intern/GHOST_XrSession.cpp @@ -193,16 +193,13 @@ void GHOST_XrSession::end() GHOST_XrSession::eLifeExpectancy GHOST_XrSession::handleStateChangeEvent( const XrEventDataSessionStateChanged *lifecycle) { - m_oxr->session_state = lifecycle->state; - /* Runtime may send events for apparently destroyed session. Our handle should be NULL then. */ assert((m_oxr->session == XR_NULL_HANDLE) || (m_oxr->session == lifecycle->session)); switch (lifecycle->state) { case XR_SESSION_STATE_READY: { - XrSessionBeginInfo begin_info{}; + XrSessionBeginInfo begin_info{XR_TYPE_SESSION_BEGIN_INFO}; - begin_info.type = XR_TYPE_SESSION_BEGIN_INFO; begin_info.primaryViewConfigurationType = m_oxr->view_type; CHECK_XR(xrBeginSession(m_oxr->session, &begin_info), "Failed to cleanly begin the VR session."); @@ -218,6 +215,10 @@ GHOST_XrSession::eLifeExpectancy GHOST_XrSession::handleStateChangeEvent( break; } + /* GHOST session state is managed through this. Set last so on parallel execution of GHOST_Xr + * calls, state changes only take effect once previous operations in this functions are done. */ + m_oxr->session_state = lifecycle->state; + return SESSION_KEEP_ALIVE; } /** \} */ /* State Management */ @@ -320,7 +321,6 @@ void GHOST_XrSession::beginFrameDrawing() XrFrameBeginInfo begin_info{XR_TYPE_FRAME_BEGIN_INFO}; XrFrameState frame_state{XR_TYPE_FRAME_STATE}; - // TODO Blocking call. Does this intefer with other drawing? CHECK_XR(xrWaitFrame(m_oxr->session, &wait_info, &frame_state), "Failed to synchronize frame rates between Blender and the device."); @@ -381,6 +381,8 @@ void GHOST_XrSession::draw(void *draw_customdata) XrCompositionLayerProjection proj_layer; std::vector<XrCompositionLayerBaseHeader *> layers; + assert(shouldRunDrawLoop()); + beginFrameDrawing(); if (m_draw_info->frame_state.shouldRender) { @@ -513,7 +515,7 @@ XrCompositionLayerProjection GHOST_XrSession::drawLayer( * * \{ */ -bool GHOST_XrSession::isRunning() const +bool GHOST_XrSession::shouldRunDrawLoop() const { if (m_oxr->session == XR_NULL_HANDLE) { return false; diff --git a/intern/ghost/intern/GHOST_XrSession.h b/intern/ghost/intern/GHOST_XrSession.h index 7b75bdbae56..56bba7130b0 100644 --- a/intern/ghost/intern/GHOST_XrSession.h +++ b/intern/ghost/intern/GHOST_XrSession.h @@ -39,7 +39,7 @@ class GHOST_XrSession { eLifeExpectancy handleStateChangeEvent(const struct XrEventDataSessionStateChanged *lifecycle); - bool isRunning() const; + bool shouldRunDrawLoop() const; void unbindGraphicsContext(); /* public so context can ensure it's unbound as needed. */ |