1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-16 06:59:55 +00:00

Avoid using camera settings from stereo manager

This commit is contained in:
elsid 2023-10-27 23:26:50 +02:00
parent f724b05c57
commit 561a6bf854
No known key found for this signature in database
GPG key ID: 4DE04C198CBA7625
3 changed files with 23 additions and 11 deletions

View file

@ -313,6 +313,8 @@ bool OMW::Engine::frame(float frametime)
mLuaManager->reportStats(frameNumber, *stats);
}
mStereoManager->updateSettings(Settings::camera().mNearClip, Settings::camera().mViewingDistance);
mViewer->eventTraversal();
mViewer->updateTraversal();
@ -634,7 +636,8 @@ void OMW::Engine::prepareEngine()
bool stereoEnabled
= Settings::Manager::getBool("stereo enabled", "Stereo") || osg::DisplaySettings::instance().get()->getStereo();
mStereoManager = std::make_unique<Stereo::Manager>(mViewer, stereoEnabled);
mStereoManager = std::make_unique<Stereo::Manager>(
mViewer, stereoEnabled, Settings::camera().mNearClip, Settings::camera().mViewingDistance);
osg::ref_ptr<osg::Group> rootNode(new osg::Group);
mViewer->setSceneData(rootNode);

View file

@ -114,13 +114,15 @@ namespace Stereo
return *sInstance;
}
Manager::Manager(osgViewer::Viewer* viewer, bool enableStereo)
Manager::Manager(osgViewer::Viewer* viewer, bool enableStereo, double near, double far)
: mViewer(viewer)
, mMainCamera(mViewer->getCamera())
, mUpdateCallback(new StereoUpdateCallback(this))
, mMasterProjectionMatrix(osg::Matrixd::identity())
, mEyeResolutionOverriden(false)
, mEyeResolutionOverride(0, 0)
, mNear(near)
, mFar(far)
, mFrustumManager(nullptr)
, mUpdateViewCallback(nullptr)
{
@ -289,20 +291,17 @@ namespace Stereo
void Manager::update()
{
const double near_ = Settings::camera().mNearClip;
const double far_ = Settings::camera().mViewingDistance;
if (mUpdateViewCallback)
{
mUpdateViewCallback->updateView(mView[0], mView[1]);
mViewOffsetMatrix[0] = mView[0].viewMatrix(true);
mViewOffsetMatrix[1] = mView[1].viewMatrix(true);
mProjectionMatrix[0] = mView[0].perspectiveMatrix(near_, far_, false);
mProjectionMatrix[1] = mView[1].perspectiveMatrix(near_, far_, false);
mProjectionMatrix[0] = mView[0].perspectiveMatrix(mNear, mFar, false);
mProjectionMatrix[1] = mView[1].perspectiveMatrix(mNear, mFar, false);
if (SceneUtil::AutoDepth::isReversed())
{
mProjectionMatrixReverseZ[0] = mView[0].perspectiveMatrix(near_, far_, true);
mProjectionMatrixReverseZ[1] = mView[1].perspectiveMatrix(near_, far_, true);
mProjectionMatrixReverseZ[0] = mView[0].perspectiveMatrix(mNear, mFar, true);
mProjectionMatrixReverseZ[1] = mView[1].perspectiveMatrix(mNear, mFar, true);
}
View masterView;
@ -310,7 +309,7 @@ namespace Stereo
masterView.fov.angleUp = std::max(mView[0].fov.angleUp, mView[1].fov.angleUp);
masterView.fov.angleLeft = std::min(mView[0].fov.angleLeft, mView[1].fov.angleLeft);
masterView.fov.angleRight = std::max(mView[0].fov.angleRight, mView[1].fov.angleRight);
auto projectionMatrix = masterView.perspectiveMatrix(near_, far_, false);
auto projectionMatrix = masterView.perspectiveMatrix(mNear, mFar, false);
mMainCamera->setProjectionMatrix(projectionMatrix);
}
else

View file

@ -76,12 +76,20 @@ namespace Stereo
//! @Param viewer the osg viewer whose stereo should be managed.
//! @Param enableStereo whether or not stereo should be enabled.
//! @Param enableMultiview whether or not to make use of the GL_OVR_Multiview extension, if supported.
Manager(osgViewer::Viewer* viewer, bool enableStereo);
//! @Param near defines distance to near camera clipping plane from view point.
//! @Param far defines distance to far camera clipping plane from view point.
explicit Manager(osgViewer::Viewer* viewer, bool enableStereo, double near, double far);
~Manager();
//! Called during update traversal
void update();
void updateSettings(double near, double far)
{
mNear = near;
mFar = far;
}
//! Initializes all details of stereo if applicable. If the constructor was called with enableMultiview=true,
//! and the GL_OVR_Multiview extension is supported, Stereo::getMultiview() will return true after this call.
void initializeStereo(osg::GraphicsContext* gc, bool enableMultiview);
@ -138,6 +146,8 @@ namespace Stereo
std::shared_ptr<MultiviewFramebuffer> mMultiviewFramebuffer;
bool mEyeResolutionOverriden;
osg::Vec2i mEyeResolutionOverride;
double mNear;
double mFar;
std::array<View, 2> mView;
std::array<osg::Matrixd, 2> mViewOffsetMatrix;