1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-21 21:09:40 +00:00

BruteForce fixes (still incomplete)

This commit is contained in:
Mads Buvik Sandvei 2020-12-20 20:32:32 +01:00
parent 823bda139a
commit 1c94d5af27
5 changed files with 22 additions and 137 deletions

View file

@ -50,25 +50,8 @@ namespace MWVR
}
VRSession::VRSession()
: mXrSyncPhase{FramePhase::Cull}
{
mHandDirectedMovement = Settings::Manager::getBool("hand directed movement", "VR");
auto syncPhase = Settings::Manager::getString("openxr sync phase", "VR Debug");
syncPhase = Misc::StringUtils::lowerCase(syncPhase);
if (syncPhase == "update")
mXrSyncPhase = FramePhase::Update;
else if (syncPhase == "cull")
mXrSyncPhase = FramePhase::Cull;
else if (syncPhase == "draw")
mXrSyncPhase = FramePhase::Draw;
else if (syncPhase == "swap")
mXrSyncPhase = FramePhase::Swap;
else
{
Log(Debug::Verbose) << "Invalid openxr sync phase " << syncPhase << ", defaulting to cull";
return;
}
Log(Debug::Verbose) << "Using openxr sync phase " << syncPhase;
}
VRSession::~VRSession()
@ -154,9 +137,7 @@ namespace MWVR
{
auto* xr = Environment::get().getManager();
beginPhase(FramePhase::Swap);
auto* frameMeta = getFrame(FramePhase::Swap).get();
auto* frameMeta = getFrame(FramePhase::Draw).get();
if (frameMeta->mShouldSyncFrameLoop)
{
@ -185,7 +166,7 @@ namespace MWVR
{
std::unique_lock<std::mutex> lock(mMutex);
mLastRenderedFrame = frameMeta->mFrameNo;
getFrame(FramePhase::Swap) = nullptr;
getFrame(FramePhase::Draw) = nullptr;
}
mCondition.notify_all();
@ -193,8 +174,8 @@ namespace MWVR
void VRSession::beginPhase(FramePhase phase)
{
{
// TODO: Use a queue system
std::unique_lock<std::mutex> lock(mMutex);
while (getFrame(phase))
{
@ -212,24 +193,13 @@ namespace MWVR
else
{
std::unique_lock<std::mutex> lock(mMutex);
FramePhase previousPhase = static_cast<FramePhase>((int)phase - 1);
if (!getFrame(previousPhase))
throw std::logic_error("beginPhase called without a frame");
frame = std::move(getFrame(previousPhase));
frame = std::move(getFrame(FramePhase::Update));
}
mCondition.notify_all();
if (phase == mXrSyncPhase && frame->mShouldSyncFrameLoop)
if (phase == FramePhase::Draw && frame->mShouldSyncFrameLoop)
{
// We may reach this point before xrEndFrame of the previous frame
// Must wait or openxr will interpret another call to xrBeginFrame() as skipping a frame
std::unique_lock<std::mutex> lock(mMutex);
while (mLastRenderedFrame != frame->mFrameNo - 1)
{
mCondition.wait(lock);
}
Environment::get().getManager()->beginFrame();
}

View file

@ -36,9 +36,7 @@ namespace MWVR
enum class FramePhase
{
Update = 0, //!< The frame currently in update traversals
Cull, //!< The frame currently in cull
Draw, //!< The frame currently in draw
Swap, //!< The frame being swapped
NumPhases
};
@ -83,7 +81,6 @@ namespace MWVR
private:
std::mutex mMutex{};
std::condition_variable mCondition{};
FramePhase mXrSyncPhase{ FramePhase::Cull };
bool mHandDirectedMovement{ false };
long long mFrames{ 0 };

View file

@ -94,15 +94,6 @@ namespace MWVR
return VRViewer::MirrorTextureEye::Both;
}
class CullCallback : public osg::NodeCallback
{
void operator()(osg::Node* node, osg::NodeVisitor* nv)
{
Environment::get().getSession()->beginPhase(VRSession::FramePhase::Cull);
traverse(node, nv);
}
};
void VRViewer::configureXR(osg::GraphicsContext* context)
{
std::unique_lock<std::mutex> lock(mMutex);
@ -188,7 +179,6 @@ namespace MWVR
Misc::StereoView::instance().setInitialDrawCallback(new InitialDrawCallback(this));
Misc::StereoView::instance().setPredrawCallback(mPreDraw);
Misc::StereoView::instance().setPostdrawCallback(mPostDraw);
Misc::StereoView::instance().setCullCallback(new CullCallback);
//auto cullMask = Misc::StereoView::instance().getCullMask();
auto cullMask = ~(MWRender::VisMask::Mask_UpdateVisitor | MWRender::VisMask::Mask_SimpleWater);
cullMask &= ~MWRender::VisMask::Mask_GUI;
@ -300,8 +290,7 @@ namespace MWVR
VRViewer::SwapBuffersCallback::swapBuffersImplementation(
osg::GraphicsContext* gc)
{
auto* session = Environment::get().getSession();
session->swapBuffers(gc, *mViewer);
mViewer->swapBuffersCallback(gc);
}
void
@ -319,6 +308,9 @@ namespace MWVR
void VRViewer::initialDrawCallback(osg::RenderInfo& info)
{
if (mRenderingReady)
return;
Environment::get().getSession()->beginPhase(VRSession::FramePhase::Draw);
if (Environment::get().getSession()->getFrame(VRSession::FramePhase::Draw)->mShouldRender)
mSwapchain->beginFrame(info.getState()->getGraphicsContext());
@ -331,6 +323,8 @@ namespace MWVR
// Disable normal OSG FBO camera setup
renderer->setCameraRequiresSetUp(false);
}
mRenderingReady = true;
}
void VRViewer::preDrawCallback(osg::RenderInfo& info)
@ -353,8 +347,11 @@ namespace MWVR
}
}
VRViewer::InitialDrawCallback::~InitialDrawCallback()
void VRViewer::swapBuffersCallback(osg::GraphicsContext* gc)
{
auto* session = Environment::get().getSession();
session->swapBuffers(gc, *this);
mRenderingReady = false;
}
void VRViewer::updateView(Misc::View& left, Misc::View& right)
@ -365,56 +362,9 @@ namespace MWVR
if (frame->mShouldRender)
{
//left.fov.angleLeft = frame->mPredictedPoses.view->fov.angleLeft;
//left.fov.angleLeft = frame->mPredictedPoses.view->fov.angleDown;
//left.fov.angleLeft = frame->mPredictedPoses.view->fov.angleRight;
//left.fov.angleLeft = frame->mPredictedPoses.view->fov.angleUp;
//frame->mPredictedPoses.eye;
left = frame->mPredictedPoses.view[static_cast<int>(Side::LEFT_SIDE)];
right = frame->mPredictedPoses.view[static_cast<int>(Side::RIGHT_SIDE)];
}
// auto* camera = slave._camera.get();
//
// // Update current cached cull mask of camera if it is active
// auto mask = camera->getCullMask();
// if (mask == 0)
// camera->setCullMask(mCullMask);
// else
// mCullMask = mask;
//
// // If the session is not active, we do not want to waste resources rendering frames.
// if (Environment::get().getSession()->getFrame(VRSession::FramePhase::Update)->mShouldRender)
// {
// Side side = Side::RIGHT_SIDE;
// if (mName == "LeftEye")
// {
//
// Environment::get().getViewer()->vrShadow().updateShadowConfig(view);
// side = Side::LEFT_SIDE;
// }
//
// auto* session = Environment::get().getSession();
// auto viewMatrix = view.getCamera()->getViewMatrix();
//
// // If the camera does not have a view, use the VR stage directly
// bool useStage = !(viewMatrix.getTrans().length() > 0.01);
//
// // If the view matrix is still the identity matrix, conventions have to be swapped around.
// bool swapConventions = viewMatrix.isIdentity();
//
// viewMatrix = viewMatrix * session->viewMatrix(VRSession::FramePhase::Update, side, !useStage, !swapConventions);
//
// camera->setViewMatrix(viewMatrix);
//
// auto projectionMatrix = session->projectionMatrix(VRSession::FramePhase::Update, side);
// camera->setProjectionMatrix(projectionMatrix);
// }
// else
// {
// camera->setCullMask(0);
// }
// slave.updateSlaveImplementation(view);
}
void VRViewer::UpdateViewCallback::updateView(Misc::View& left, Misc::View& right)

View file

@ -83,8 +83,6 @@ namespace MWVR
: mViewer(viewer)
{}
~InitialDrawCallback();
void operator()(osg::RenderInfo& info) const override { mViewer->initialDrawCallback(info); };
private:
@ -107,6 +105,7 @@ namespace MWVR
~VRViewer(void);
void traversals();
void swapBuffersCallback(osg::GraphicsContext* gc);
void initialDrawCallback(osg::RenderInfo& info);
void preDrawCallback(osg::RenderInfo& info);
void postDrawCallback(osg::RenderInfo& info);
@ -130,6 +129,7 @@ namespace MWVR
osg::ref_ptr<osgViewer::Viewer> mViewer = nullptr;
osg::ref_ptr<PredrawCallback> mPreDraw{ nullptr };
osg::ref_ptr<PostdrawCallback> mPostDraw{ nullptr };
bool mRenderingReady{ false };
std::unique_ptr<VRFramebuffer> mMsaaResolveMirrorTexture;
std::unique_ptr<VRFramebuffer> mMirrorTexture;

View file

@ -688,55 +688,24 @@ namespace Misc
void StereoView::setInitialDrawCallback(osg::ref_ptr<osg::Camera::DrawCallback> cb)
{
mInitialDrawCallback = cb;
switch (mTechnique)
{
case Technique::GeometryShader_IndexedViewports:
mMainCamera->setInitialDrawCallback(cb); break;
case Technique::BruteForce:
mRightCamera->setInitialDrawCallback(cb); break;
default: break;
}
mMainCamera->setInitialDrawCallback(cb);
}
void StereoView::setPredrawCallback(osg::ref_ptr<osg::Camera::DrawCallback> cb)
{
mPreDrawCallback = cb;
switch (mTechnique)
{
case Technique::GeometryShader_IndexedViewports:
mMainCamera->setPreDrawCallback(cb); break;
case Technique::BruteForce:
mLeftCamera->setPreDrawCallback(cb);
mRightCamera->setPreDrawCallback(cb); break;
default: break;
}
mMainCamera->setPreDrawCallback(cb);
}
void StereoView::setPostdrawCallback(osg::ref_ptr<osg::Camera::DrawCallback> cb)
{
mPostDrawCallback = cb;
switch (mTechnique)
{
case Technique::GeometryShader_IndexedViewports:
mMainCamera->setPostDrawCallback(cb); break;
case Technique::BruteForce:
mLeftCamera->setPostDrawCallback(cb);
mRightCamera->setPostDrawCallback(cb); break;
default: break;
}
mMainCamera->setPostDrawCallback(cb);
}
void StereoView::setCullCallback(osg::ref_ptr<osg::NodeCallback> cb)
{
mCullCallback = cb;
switch (mTechnique)
{
case Technique::GeometryShader_IndexedViewports:
mMainCamera->setCullCallback(cb); break;
case Technique::BruteForce:
mRightCamera->setCullCallback(cb); break;
default: break;
}
mMainCamera->setCullCallback(cb);
}
void StereoView::setCullMask(osg::Node::NodeMask cullMask)
@ -750,8 +719,7 @@ namespace Misc
}
else
{
mLeftCamera->setCullMask(cullMask);
mRightCamera->setCullMask(cullMask);
mMainCamera->setCullMask(cullMask);
}
}
osg::Node::NodeMask StereoView::getCullMask()