Unite all viewer traversals.

pull/615/head
madsbuvi 4 years ago
parent e59fcf7613
commit 018e790ec0

@ -1023,12 +1023,7 @@ void OMW::Engine::go()
} }
else else
{ {
mViewer->eventTraversal(); mEnvironment.getWindowManager()->viewerTraversals(true);
mViewer->updateTraversal();
mEnvironment.getWorld()->updateWindowManager();
mViewer->renderingTraversals();
bool guiActive = mEnvironment.getWindowManager()->isGuiMode(); bool guiActive = mEnvironment.getWindowManager()->isGuiMode();
if (!guiActive) if (!guiActive)

@ -350,6 +350,8 @@ namespace MWBase
virtual void watchActor(const MWWorld::Ptr& ptr) = 0; virtual void watchActor(const MWWorld::Ptr& ptr) = 0;
virtual MWWorld::Ptr getWatchedActor() const = 0; virtual MWWorld::Ptr getWatchedActor() const = 0;
virtual void viewerTraversals(bool updateWindowManager) = 0;
}; };
} }

@ -407,9 +407,7 @@ namespace MWGui
// at the time this function is called we are in the middle of a frame, // at the time this function is called we are in the middle of a frame,
// so out of order calls are necessary to get a correct frameNumber for the next frame. // so out of order calls are necessary to get a correct frameNumber for the next frame.
// refer to the advance() and frame() order in Engine::go() // refer to the advance() and frame() order in Engine::go()
mViewer->eventTraversal(); MWBase::Environment::get().getWindowManager()->viewerTraversals(false);
mViewer->updateTraversal();
mViewer->renderingTraversals();
mViewer->advance(mViewer->getFrameStamp()->getSimulationTime()); mViewer->advance(mViewer->getFrameStamp()->getSimulationTime());
if (mHasCallback) if (mHasCallback)

@ -124,6 +124,8 @@
#include "../mwvr/vrenvironment.hpp" #include "../mwvr/vrenvironment.hpp"
#include "../mwvr/vrgui.hpp" #include "../mwvr/vrgui.hpp"
#include "../mwvr/vrvirtualkeyboard.hpp" #include "../mwvr/vrvirtualkeyboard.hpp"
#include "../mwvr/vrviewer.hpp"
#include "../mwvr/vrsession.hpp"
#endif #endif
namespace MWGui namespace MWGui
@ -770,11 +772,7 @@ namespace MWGui
if (!mWindowVisible) if (!mWindowVisible)
std::this_thread::sleep_for(std::chrono::milliseconds(5)); std::this_thread::sleep_for(std::chrono::milliseconds(5));
else else
{ viewerTraversals(false);
mViewer->eventTraversal();
mViewer->updateTraversal();
mViewer->renderingTraversals();
}
// at the time this function is called we are in the middle of a frame, // at the time this function is called we are in the middle of a frame,
// so out of order calls are necessary to get a correct frameNumber for the next frame. // so out of order calls are necessary to get a correct frameNumber for the next frame.
// refer to the advance() and frame() order in Engine::go() // refer to the advance() and frame() order in Engine::go()
@ -1829,9 +1827,7 @@ namespace MWGui
if (mVideoWidget->isPaused()) if (mVideoWidget->isPaused())
mVideoWidget->resume(); mVideoWidget->resume();
mViewer->eventTraversal(); viewerTraversals(false);
mViewer->updateTraversal();
mViewer->renderingTraversals();
} }
// at the time this function is called we are in the middle of a frame, // at the time this function is called we are in the middle of a frame,
// so out of order calls are necessary to get a correct frameNumber for the next frame. // so out of order calls are necessary to get a correct frameNumber for the next frame.
@ -2248,6 +2244,25 @@ namespace MWGui
return MyGUI::InputManager::getInstance().injectKeyRelease(key); return MyGUI::InputManager::getInstance().injectKeyRelease(key);
} }
void WindowManager::viewerTraversals(bool updateWindowManager)
{
#ifdef USE_OPENXR
if (MWBase::Environment::get().getVrMode())
MWVR::Environment::get().getSession()->beginFrame();
#endif
mViewer->eventTraversal();
mViewer->updateTraversal();
if (updateWindowManager)
MWBase::Environment::get().getWorld()->updateWindowManager();
mViewer->renderingTraversals();
#ifdef USE_OPENXR
if (MWBase::Environment::get().getVrMode())
MWVR::Environment::get().getSession()->endFrame();
#endif
}
void WindowManager::GuiModeState::update(bool visible) void WindowManager::GuiModeState::update(bool visible)
{ {
for (unsigned int i=0; i<mWindows.size(); ++i) for (unsigned int i=0; i<mWindows.size(); ++i)

@ -389,6 +389,7 @@ namespace MWGui
bool injectKeyPress(MyGUI::KeyCode key, unsigned int text, bool repeat=false) override; bool injectKeyPress(MyGUI::KeyCode key, unsigned int text, bool repeat=false) override;
bool injectKeyRelease(MyGUI::KeyCode key) override; bool injectKeyRelease(MyGUI::KeyCode key) override;
void viewerTraversals(bool updateWindowManager) override;
private: private:
unsigned int mOldUpdateMask; unsigned int mOldCullMask; unsigned int mOldUpdateMask; unsigned int mOldCullMask;

@ -927,9 +927,7 @@ namespace MWRender
MWBase::Environment::get().getWindowManager()->getLoadingScreen()->loadingOn(false); MWBase::Environment::get().getWindowManager()->getLoadingScreen()->loadingOn(false);
mViewer->eventTraversal(); MWBase::Environment::get().getWindowManager()->viewerTraversals(false);
mViewer->updateTraversal();
mViewer->renderingTraversals();
callback->waitTillDone(); callback->waitTillDone();
MWBase::Environment::get().getWindowManager()->getLoadingScreen()->loadingOff(); MWBase::Environment::get().getWindowManager()->getLoadingScreen()->loadingOff();
@ -969,9 +967,6 @@ namespace MWRender
void RenderingManager::screenshotFramebuffer(osg::Image* image, int w, int h) void RenderingManager::screenshotFramebuffer(osg::Image* image, int w, int h)
{ {
osg::Camera* camera = mViewer->getCamera(); osg::Camera* camera = mViewer->getCamera();
#ifdef USE_OPENXR
MWVR::Environment::get().getSession()->beginPhase(MWVR::VRSession::FramePhase::Update);
#endif
osg::ref_ptr<osg::Drawable> tempDrw = new osg::Drawable; osg::ref_ptr<osg::Drawable> tempDrw = new osg::Drawable;
tempDrw->setDrawCallback(new ReadImageFromFramebufferCallback(image, w, h)); tempDrw->setDrawCallback(new ReadImageFromFramebufferCallback(image, w, h));
tempDrw->setCullingActive(false); tempDrw->setCullingActive(false);
@ -980,9 +975,7 @@ namespace MWRender
osg::ref_ptr<NotifyDrawCompletedCallback> callback (new NotifyDrawCompletedCallback(mViewer->getFrameStamp()->getFrameNumber())); osg::ref_ptr<NotifyDrawCompletedCallback> callback (new NotifyDrawCompletedCallback(mViewer->getFrameStamp()->getFrameNumber()));
auto* oldCb = camera->getFinalDrawCallback(); auto* oldCb = camera->getFinalDrawCallback();
camera->setFinalDrawCallback(callback); camera->setFinalDrawCallback(callback);
mViewer->eventTraversal(); MWBase::Environment::get().getWindowManager()->viewerTraversals(false);
mViewer->updateTraversal();
mViewer->renderingTraversals();
callback->waitTillDone(); callback->waitTillDone();
// now that we've "used up" the current frame, get a fresh frame number for the next frame() following after the screenshot is completed // now that we've "used up" the current frame, get a fresh frame number for the next frame() following after the screenshot is completed
mViewer->advance(mViewer->getFrameStamp()->getSimulationTime()); mViewer->advance(mViewer->getFrameStamp()->getSimulationTime());

@ -394,12 +394,13 @@ namespace MWVR
updateActivationIndication(); updateActivationIndication();
MWInput::InputManager::update(dt, disableControls, disableEvents); MWInput::InputManager::update(dt, disableControls, disableEvents);
// This is the first update that needs openxr tracking, so i begin the next frame here. // This is the first update that needs openxr tracking, so i begin the next frame here.
auto* session = Environment::get().getSession(); auto* session = Environment::get().getSession();
if (!session) if (!session)
return; return;
session->beginPhase(VRSession::FramePhase::Update); session->beginFrame();
// The rest of this code assumes the game is running // The rest of this code assumes the game is running
if (MWBase::Environment::get().getStateManager()->getState() == MWBase::StateManager::State_NoGame) if (MWBase::Environment::get().getStateManager()->getState() == MWBase::StateManager::State_NoGame)

@ -78,6 +78,26 @@ namespace MWVR
} }
} }
void VRSession::beginFrame()
{
// Viewer traversals are sometimes entered without first updating the input manager.
if (getFrame(FramePhase::Update) == nullptr)
{
beginPhase(FramePhase::Update);
}
}
void VRSession::endFrame()
{
// Make sure we don't continue until the render thread has moved the frame to its next phase.
std::unique_lock<std::mutex> lock(mMutex);
while (getFrame(FramePhase::Update))
{
mCondition.wait(lock);
}
}
osg::Matrix VRSession::viewMatrix(osg::Vec3 position, osg::Quat orientation) osg::Matrix VRSession::viewMatrix(osg::Vec3 position, osg::Quat orientation)
{ {
position = position * Constants::UnitsPerMeter; position = position * Constants::UnitsPerMeter;
@ -179,7 +199,7 @@ namespace MWVR
std::unique_lock<std::mutex> lock(mMutex); std::unique_lock<std::mutex> lock(mMutex);
while (getFrame(phase)) while (getFrame(phase))
{ {
//Log(Debug::Verbose) << "Warning: beginPhase called with a frame already in the target phase"; Log(Debug::Verbose) << "Warning: beginPhase called with a frame already in the target phase";
mCondition.wait(lock); mCondition.wait(lock);
} }
} }

@ -78,6 +78,9 @@ namespace MWVR
void processChangedSettings(const std::set< std::pair<std::string, std::string> >& changed); void processChangedSettings(const std::set< std::pair<std::string, std::string> >& changed);
void beginFrame();
void endFrame();
private: private:
std::mutex mMutex{}; std::mutex mMutex{};
std::condition_variable mCondition{}; std::condition_variable mCondition{};

@ -57,12 +57,6 @@ namespace MWVR
{ {
} }
void VRViewer::traversals()
{
mViewer->updateTraversal();
mViewer->renderingTraversals();
}
int parseResolution(std::string conf, int recommended, int max) int parseResolution(std::string conf, int recommended, int max)
{ {
if (Misc::StringUtils::isNumber(conf)) if (Misc::StringUtils::isNumber(conf))

@ -104,7 +104,6 @@ namespace MWVR
~VRViewer(void); ~VRViewer(void);
void traversals();
void swapBuffersCallback(osg::GraphicsContext* gc); void swapBuffersCallback(osg::GraphicsContext* gc);
void initialDrawCallback(osg::RenderInfo& info); void initialDrawCallback(osg::RenderInfo& info);
void preDrawCallback(osg::RenderInfo& info); void preDrawCallback(osg::RenderInfo& info);

Loading…
Cancel
Save