mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-29 05:15:34 +00:00
Avoid using camera settings from stereo manager
This commit is contained in:
parent
f724b05c57
commit
561a6bf854
3 changed files with 23 additions and 11 deletions
|
@ -313,6 +313,8 @@ bool OMW::Engine::frame(float frametime)
|
||||||
mLuaManager->reportStats(frameNumber, *stats);
|
mLuaManager->reportStats(frameNumber, *stats);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mStereoManager->updateSettings(Settings::camera().mNearClip, Settings::camera().mViewingDistance);
|
||||||
|
|
||||||
mViewer->eventTraversal();
|
mViewer->eventTraversal();
|
||||||
mViewer->updateTraversal();
|
mViewer->updateTraversal();
|
||||||
|
|
||||||
|
@ -634,7 +636,8 @@ void OMW::Engine::prepareEngine()
|
||||||
|
|
||||||
bool stereoEnabled
|
bool stereoEnabled
|
||||||
= Settings::Manager::getBool("stereo enabled", "Stereo") || osg::DisplaySettings::instance().get()->getStereo();
|
= 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);
|
osg::ref_ptr<osg::Group> rootNode(new osg::Group);
|
||||||
mViewer->setSceneData(rootNode);
|
mViewer->setSceneData(rootNode);
|
||||||
|
|
|
@ -114,13 +114,15 @@ namespace Stereo
|
||||||
return *sInstance;
|
return *sInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
Manager::Manager(osgViewer::Viewer* viewer, bool enableStereo)
|
Manager::Manager(osgViewer::Viewer* viewer, bool enableStereo, double near, double far)
|
||||||
: mViewer(viewer)
|
: mViewer(viewer)
|
||||||
, mMainCamera(mViewer->getCamera())
|
, mMainCamera(mViewer->getCamera())
|
||||||
, mUpdateCallback(new StereoUpdateCallback(this))
|
, mUpdateCallback(new StereoUpdateCallback(this))
|
||||||
, mMasterProjectionMatrix(osg::Matrixd::identity())
|
, mMasterProjectionMatrix(osg::Matrixd::identity())
|
||||||
, mEyeResolutionOverriden(false)
|
, mEyeResolutionOverriden(false)
|
||||||
, mEyeResolutionOverride(0, 0)
|
, mEyeResolutionOverride(0, 0)
|
||||||
|
, mNear(near)
|
||||||
|
, mFar(far)
|
||||||
, mFrustumManager(nullptr)
|
, mFrustumManager(nullptr)
|
||||||
, mUpdateViewCallback(nullptr)
|
, mUpdateViewCallback(nullptr)
|
||||||
{
|
{
|
||||||
|
@ -289,20 +291,17 @@ namespace Stereo
|
||||||
|
|
||||||
void Manager::update()
|
void Manager::update()
|
||||||
{
|
{
|
||||||
const double near_ = Settings::camera().mNearClip;
|
|
||||||
const double far_ = Settings::camera().mViewingDistance;
|
|
||||||
|
|
||||||
if (mUpdateViewCallback)
|
if (mUpdateViewCallback)
|
||||||
{
|
{
|
||||||
mUpdateViewCallback->updateView(mView[0], mView[1]);
|
mUpdateViewCallback->updateView(mView[0], mView[1]);
|
||||||
mViewOffsetMatrix[0] = mView[0].viewMatrix(true);
|
mViewOffsetMatrix[0] = mView[0].viewMatrix(true);
|
||||||
mViewOffsetMatrix[1] = mView[1].viewMatrix(true);
|
mViewOffsetMatrix[1] = mView[1].viewMatrix(true);
|
||||||
mProjectionMatrix[0] = mView[0].perspectiveMatrix(near_, far_, false);
|
mProjectionMatrix[0] = mView[0].perspectiveMatrix(mNear, mFar, false);
|
||||||
mProjectionMatrix[1] = mView[1].perspectiveMatrix(near_, far_, false);
|
mProjectionMatrix[1] = mView[1].perspectiveMatrix(mNear, mFar, false);
|
||||||
if (SceneUtil::AutoDepth::isReversed())
|
if (SceneUtil::AutoDepth::isReversed())
|
||||||
{
|
{
|
||||||
mProjectionMatrixReverseZ[0] = mView[0].perspectiveMatrix(near_, far_, true);
|
mProjectionMatrixReverseZ[0] = mView[0].perspectiveMatrix(mNear, mFar, true);
|
||||||
mProjectionMatrixReverseZ[1] = mView[1].perspectiveMatrix(near_, far_, true);
|
mProjectionMatrixReverseZ[1] = mView[1].perspectiveMatrix(mNear, mFar, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
View masterView;
|
View masterView;
|
||||||
|
@ -310,7 +309,7 @@ namespace Stereo
|
||||||
masterView.fov.angleUp = std::max(mView[0].fov.angleUp, mView[1].fov.angleUp);
|
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.angleLeft = std::min(mView[0].fov.angleLeft, mView[1].fov.angleLeft);
|
||||||
masterView.fov.angleRight = std::max(mView[0].fov.angleRight, mView[1].fov.angleRight);
|
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);
|
mMainCamera->setProjectionMatrix(projectionMatrix);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -76,12 +76,20 @@ namespace Stereo
|
||||||
//! @Param viewer the osg viewer whose stereo should be managed.
|
//! @Param viewer the osg viewer whose stereo should be managed.
|
||||||
//! @Param enableStereo whether or not stereo should be enabled.
|
//! @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.
|
//! @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();
|
~Manager();
|
||||||
|
|
||||||
//! Called during update traversal
|
//! Called during update traversal
|
||||||
void update();
|
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,
|
//! 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.
|
//! and the GL_OVR_Multiview extension is supported, Stereo::getMultiview() will return true after this call.
|
||||||
void initializeStereo(osg::GraphicsContext* gc, bool enableMultiview);
|
void initializeStereo(osg::GraphicsContext* gc, bool enableMultiview);
|
||||||
|
@ -138,6 +146,8 @@ namespace Stereo
|
||||||
std::shared_ptr<MultiviewFramebuffer> mMultiviewFramebuffer;
|
std::shared_ptr<MultiviewFramebuffer> mMultiviewFramebuffer;
|
||||||
bool mEyeResolutionOverriden;
|
bool mEyeResolutionOverriden;
|
||||||
osg::Vec2i mEyeResolutionOverride;
|
osg::Vec2i mEyeResolutionOverride;
|
||||||
|
double mNear;
|
||||||
|
double mFar;
|
||||||
|
|
||||||
std::array<View, 2> mView;
|
std::array<View, 2> mView;
|
||||||
std::array<osg::Matrixd, 2> mViewOffsetMatrix;
|
std::array<osg::Matrixd, 2> mViewOffsetMatrix;
|
||||||
|
|
Loading…
Reference in a new issue