From fea964a6f3c1facb51ef4985e3891ac2e5f816d6 Mon Sep 17 00:00:00 2001 From: Mads Buvik Sandvei Date: Mon, 27 Jan 2020 18:34:48 +0100 Subject: [PATCH] Tightened prediction point --- apps/openmw/mwvr/openxrmanagerimpl.cpp | 26 +++++++++++++++----------- apps/openmw/mwvr/openxrview.cpp | 4 ++++ apps/openmw/mwvr/openxrviewer.cpp | 1 - 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/apps/openmw/mwvr/openxrmanagerimpl.cpp b/apps/openmw/mwvr/openxrmanagerimpl.cpp index fb0c07952..c41b6e6b7 100644 --- a/apps/openmw/mwvr/openxrmanagerimpl.cpp +++ b/apps/openmw/mwvr/openxrmanagerimpl.cpp @@ -262,7 +262,7 @@ namespace MWVR // In some implementations xrWaitFrame might not return immediately when it should. // So i let it wait in a separate thread. xrBeginFrame() should wait on xrWaitFrame() // and xrWaitFrame() doesn't happen again until xrEndFrame() so synchronization is not necessary. - std::thread([this]() { + //std::thread([this]() { static std::mutex waitFrameMutex; std::unique_lock lock(waitFrameMutex); @@ -277,7 +277,7 @@ namespace MWVR mTimeKeeper.progressToNextFrame(frameState); - }).detach(); + //}).detach(); } @@ -425,7 +425,7 @@ namespace MWVR beginInfo.primaryViewConfigurationType = mViewConfigType; CHECK_XRCMD(xrBeginSession(mSession, &beginInfo)); mSessionRunning = true; - waitFrame(); + //waitFrame(); break; } case XR_SESSION_STATE_STOPPING: @@ -480,16 +480,20 @@ namespace MWVR { std::unique_lock lock(mMutex); - auto prediction = mPredictedFrameTime; - auto predictedPeriod = mPredictedPeriod; + //auto prediction = mPredictedFrameTime; + //auto predictedPeriod = mPredictedPeriod; - auto futureFrames = frameIndex - OpenXRFrameIndexer::instance().renderIndex(); + //auto futureFrames = frameIndex - OpenXRFrameIndexer::instance().renderIndex(); - prediction += ( 0 + futureFrames) * predictedPeriod; + //prediction += ( 0 + futureFrames) * predictedPeriod; - Log(Debug::Verbose) << "Predicted: displayTime[" << futureFrames << "]=" << prediction; + //Log(Debug::Verbose) << "Predicted: displayTime[" << futureFrames << "]=" << prediction; - return prediction; + //return prediction; + + //return mFrameState.predictedDisplayTime; + + return mPredictedFrameTime; } void OpenXRTimeKeeper::progressToNextFrame(XrFrameState frameState) @@ -515,8 +519,8 @@ namespace MWVR { // predictedDisplayTime refers to the midpoint of the display period // The upjustment must therefore only be half the magnitude - // mPredictedFrameTime += (realPeriod - mFrameState.predictedDisplayPeriod); - // mPredictedPeriod = realPeriod; + mPredictedFrameTime += (realPeriod - mFrameState.predictedDisplayPeriod) / 2; + mPredictedPeriod = realPeriod; } diff --git a/apps/openmw/mwvr/openxrview.cpp b/apps/openmw/mwvr/openxrview.cpp index 274fe9784..165937274 100644 --- a/apps/openmw/mwvr/openxrview.cpp +++ b/apps/openmw/mwvr/openxrview.cpp @@ -74,6 +74,10 @@ namespace MWVR { void OpenXRView::prerenderCallback(osg::RenderInfo& renderInfo) { + + if(mName == "LeftEye") + mXR->waitFrame(); + Log(Debug::Verbose) << mName << ": prerenderCallback"; if (mSwapchain) { diff --git a/apps/openmw/mwvr/openxrviewer.cpp b/apps/openmw/mwvr/openxrviewer.cpp index d77596e7e..1cfaaf70e 100644 --- a/apps/openmw/mwvr/openxrviewer.cpp +++ b/apps/openmw/mwvr/openxrviewer.cpp @@ -185,7 +185,6 @@ namespace MWVR mViews[OpenXRWorldView::RIGHT_VIEW]->swapchain().endFrame(gc); mXRMenu->swapchain().endFrame(gc); mXR->endFrame(); - mXR->waitFrame(); //gl->glBindFramebuffer(GL_DRAW_FRAMEBUFFER_EXT, 0); //mMirrorTextureSwapchain->renderBuffer()->blit(gc, 0, 0, mMirrorTextureSwapchain->width(), mMirrorTextureSwapchain->height());