mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 12:53:53 +00:00
Merge branch 'settings_values_stereo' into 'master'
Use settings values for Stereo settings (#6876) See merge request OpenMW/openmw!3530
This commit is contained in:
commit
c49c401441
8 changed files with 140 additions and 82 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();
|
||||||
|
|
||||||
|
@ -593,7 +595,63 @@ void OMW::Engine::createWindow()
|
||||||
realizeOperations->add(mSelectColorFormatOperation);
|
realizeOperations->add(mSelectColorFormatOperation);
|
||||||
|
|
||||||
if (Stereo::getStereo())
|
if (Stereo::getStereo())
|
||||||
realizeOperations->add(new Stereo::InitializeStereoOperation());
|
{
|
||||||
|
Stereo::Settings settings;
|
||||||
|
|
||||||
|
settings.mMultiview = Settings::stereo().mMultiview;
|
||||||
|
settings.mAllowDisplayListsForMultiview = Settings::stereo().mAllowDisplayListsForMultiview;
|
||||||
|
settings.mSharedShadowMaps = Settings::stereo().mSharedShadowMaps;
|
||||||
|
|
||||||
|
if (Settings::stereo().mUseCustomView)
|
||||||
|
{
|
||||||
|
const osg::Vec3 leftEyeOffset(Settings::stereoView().mLeftEyeOffsetX,
|
||||||
|
Settings::stereoView().mLeftEyeOffsetY, Settings::stereoView().mLeftEyeOffsetZ);
|
||||||
|
|
||||||
|
const osg::Quat leftEyeOrientation(Settings::stereoView().mLeftEyeOrientationX,
|
||||||
|
Settings::stereoView().mLeftEyeOrientationY, Settings::stereoView().mLeftEyeOrientationZ,
|
||||||
|
Settings::stereoView().mLeftEyeOrientationW);
|
||||||
|
|
||||||
|
const osg::Vec3 rightEyeOffset(Settings::stereoView().mRightEyeOffsetX,
|
||||||
|
Settings::stereoView().mRightEyeOffsetY, Settings::stereoView().mRightEyeOffsetZ);
|
||||||
|
|
||||||
|
const osg::Quat rightEyeOrientation(Settings::stereoView().mRightEyeOrientationX,
|
||||||
|
Settings::stereoView().mRightEyeOrientationY, Settings::stereoView().mRightEyeOrientationZ,
|
||||||
|
Settings::stereoView().mRightEyeOrientationW);
|
||||||
|
|
||||||
|
settings.mCustomView = Stereo::CustomView{
|
||||||
|
.mLeft = Stereo::View{
|
||||||
|
.pose = Stereo::Pose{
|
||||||
|
.position = leftEyeOffset,
|
||||||
|
.orientation = leftEyeOrientation,
|
||||||
|
},
|
||||||
|
.fov = Stereo::FieldOfView{
|
||||||
|
.angleLeft = Settings::stereoView().mLeftEyeFovLeft,
|
||||||
|
.angleRight = Settings::stereoView().mLeftEyeFovRight,
|
||||||
|
.angleUp = Settings::stereoView().mLeftEyeFovUp,
|
||||||
|
.angleDown = Settings::stereoView().mLeftEyeFovDown,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
.mRight = Stereo::View{
|
||||||
|
.pose = Stereo::Pose{
|
||||||
|
.position = rightEyeOffset,
|
||||||
|
.orientation = rightEyeOrientation,
|
||||||
|
},
|
||||||
|
.fov = Stereo::FieldOfView{
|
||||||
|
.angleLeft = Settings::stereoView().mRightEyeFovLeft,
|
||||||
|
.angleRight = Settings::stereoView().mRightEyeFovRight,
|
||||||
|
.angleUp = Settings::stereoView().mRightEyeFovUp,
|
||||||
|
.angleDown = Settings::stereoView().mRightEyeFovDown,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Settings::stereo().mUseCustomEyeResolution)
|
||||||
|
settings.mEyeResolution
|
||||||
|
= osg::Vec2i(Settings::stereoView().mEyeResolutionX, Settings::stereoView().mEyeResolutionY);
|
||||||
|
|
||||||
|
realizeOperations->add(new Stereo::InitializeStereoOperation(settings));
|
||||||
|
}
|
||||||
|
|
||||||
mViewer->realize();
|
mViewer->realize();
|
||||||
mGlMaxTextureImageUnits = identifyOp->getMaxTextureImageUnits();
|
mGlMaxTextureImageUnits = identifyOp->getMaxTextureImageUnits();
|
||||||
|
@ -632,9 +690,9 @@ void OMW::Engine::prepareEngine()
|
||||||
mStateManager = std::make_unique<MWState::StateManager>(mCfgMgr.getUserDataPath() / "saves", mContentFiles);
|
mStateManager = std::make_unique<MWState::StateManager>(mCfgMgr.getUserDataPath() / "saves", mContentFiles);
|
||||||
mEnvironment.setStateManager(*mStateManager);
|
mEnvironment.setStateManager(*mStateManager);
|
||||||
|
|
||||||
bool stereoEnabled
|
const bool stereoEnabled = Settings::stereo().mStereoEnabled || osg::DisplaySettings::instance().get()->getStereo();
|
||||||
= Settings::Manager::getBool("stereo enabled", "Stereo") || osg::DisplaySettings::instance().get()->getStereo();
|
mStereoManager = std::make_unique<Stereo::Manager>(
|
||||||
mStereoManager = std::make_unique<Stereo::Manager>(mViewer, stereoEnabled);
|
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);
|
||||||
|
|
|
@ -31,14 +31,14 @@ namespace Settings
|
||||||
makeClampSanitizerDouble(-1, 1) };
|
makeClampSanitizerDouble(-1, 1) };
|
||||||
SettingValue<double> mLeftEyeOrientationW{ mIndex, "Stereo View", "left eye orientation w",
|
SettingValue<double> mLeftEyeOrientationW{ mIndex, "Stereo View", "left eye orientation w",
|
||||||
makeClampSanitizerDouble(-1, 1) };
|
makeClampSanitizerDouble(-1, 1) };
|
||||||
SettingValue<double> mLeftEyeFovLeft{ mIndex, "Stereo View", "left eye fov left",
|
SettingValue<float> mLeftEyeFovLeft{ mIndex, "Stereo View", "left eye fov left",
|
||||||
makeClampSanitizerDouble(-osg::PI, osg::PI) };
|
makeClampSanitizerFloat(-osg::PIf, osg::PIf) };
|
||||||
SettingValue<double> mLeftEyeFovRight{ mIndex, "Stereo View", "left eye fov right",
|
SettingValue<float> mLeftEyeFovRight{ mIndex, "Stereo View", "left eye fov right",
|
||||||
makeClampSanitizerDouble(-osg::PI, osg::PI) };
|
makeClampSanitizerFloat(-osg::PIf, osg::PIf) };
|
||||||
SettingValue<double> mLeftEyeFovUp{ mIndex, "Stereo View", "left eye fov up",
|
SettingValue<float> mLeftEyeFovUp{ mIndex, "Stereo View", "left eye fov up",
|
||||||
makeClampSanitizerDouble(-osg::PI, osg::PI) };
|
makeClampSanitizerFloat(-osg::PIf, osg::PIf) };
|
||||||
SettingValue<double> mLeftEyeFovDown{ mIndex, "Stereo View", "left eye fov down",
|
SettingValue<float> mLeftEyeFovDown{ mIndex, "Stereo View", "left eye fov down",
|
||||||
makeClampSanitizerDouble(-osg::PI, osg::PI) };
|
makeClampSanitizerFloat(-osg::PIf, osg::PIf) };
|
||||||
SettingValue<double> mRightEyeOffsetX{ mIndex, "Stereo View", "right eye offset x" };
|
SettingValue<double> mRightEyeOffsetX{ mIndex, "Stereo View", "right eye offset x" };
|
||||||
SettingValue<double> mRightEyeOffsetY{ mIndex, "Stereo View", "right eye offset y" };
|
SettingValue<double> mRightEyeOffsetY{ mIndex, "Stereo View", "right eye offset y" };
|
||||||
SettingValue<double> mRightEyeOffsetZ{ mIndex, "Stereo View", "right eye offset z" };
|
SettingValue<double> mRightEyeOffsetZ{ mIndex, "Stereo View", "right eye offset z" };
|
||||||
|
@ -50,14 +50,14 @@ namespace Settings
|
||||||
makeClampSanitizerDouble(-1, 1) };
|
makeClampSanitizerDouble(-1, 1) };
|
||||||
SettingValue<double> mRightEyeOrientationW{ mIndex, "Stereo View", "right eye orientation w",
|
SettingValue<double> mRightEyeOrientationW{ mIndex, "Stereo View", "right eye orientation w",
|
||||||
makeClampSanitizerDouble(-1, 1) };
|
makeClampSanitizerDouble(-1, 1) };
|
||||||
SettingValue<double> mRightEyeFovLeft{ mIndex, "Stereo View", "right eye fov left",
|
SettingValue<float> mRightEyeFovLeft{ mIndex, "Stereo View", "right eye fov left",
|
||||||
makeClampSanitizerDouble(-osg::PI, osg::PI) };
|
makeClampSanitizerFloat(-osg::PIf, osg::PIf) };
|
||||||
SettingValue<double> mRightEyeFovRight{ mIndex, "Stereo View", "right eye fov right",
|
SettingValue<float> mRightEyeFovRight{ mIndex, "Stereo View", "right eye fov right",
|
||||||
makeClampSanitizerDouble(-osg::PI, osg::PI) };
|
makeClampSanitizerFloat(-osg::PIf, osg::PIf) };
|
||||||
SettingValue<double> mRightEyeFovUp{ mIndex, "Stereo View", "right eye fov up",
|
SettingValue<float> mRightEyeFovUp{ mIndex, "Stereo View", "right eye fov up",
|
||||||
makeClampSanitizerDouble(-osg::PI, osg::PI) };
|
makeClampSanitizerFloat(-osg::PIf, osg::PIf) };
|
||||||
SettingValue<double> mRightEyeFovDown{ mIndex, "Stereo View", "right eye fov down",
|
SettingValue<float> mRightEyeFovDown{ mIndex, "Stereo View", "right eye fov down",
|
||||||
makeClampSanitizerDouble(-osg::PI, osg::PI) };
|
makeClampSanitizerFloat(-osg::PIf, osg::PIf) };
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,7 @@ namespace Stereo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StereoFrustumManager::StereoFrustumManager(osg::Camera* camera)
|
StereoFrustumManager::StereoFrustumManager(bool sharedShadowMaps, osg::Camera* camera)
|
||||||
: mCamera(camera)
|
: mCamera(camera)
|
||||||
, mShadowTechnique(nullptr)
|
, mShadowTechnique(nullptr)
|
||||||
, mShadowFrustumCallback(nullptr)
|
, mShadowFrustumCallback(nullptr)
|
||||||
|
@ -95,7 +95,7 @@ namespace Stereo
|
||||||
mMultiviewFrustumCallback = std::make_unique<MultiviewFrustumCallback>(this, camera);
|
mMultiviewFrustumCallback = std::make_unique<MultiviewFrustumCallback>(this, camera);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Settings::Manager::getBool("shared shadow maps", "Stereo"))
|
if (sharedShadowMaps)
|
||||||
{
|
{
|
||||||
mShadowFrustumCallback = new ShadowFrustumCallback(this);
|
mShadowFrustumCallback = new ShadowFrustumCallback(this);
|
||||||
auto* renderer = static_cast<osgViewer::Renderer*>(mCamera->getRenderer());
|
auto* renderer = static_cast<osgViewer::Renderer*>(mCamera->getRenderer());
|
||||||
|
|
|
@ -45,7 +45,7 @@ namespace Stereo
|
||||||
class StereoFrustumManager
|
class StereoFrustumManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
StereoFrustumManager(osg::Camera* camera);
|
StereoFrustumManager(bool sharedShadowMaps, osg::Camera* camera);
|
||||||
~StereoFrustumManager();
|
~StereoFrustumManager();
|
||||||
|
|
||||||
void update(std::array<osg::Matrix, 2> projections);
|
void update(std::array<osg::Matrix, 2> projections);
|
||||||
|
|
|
@ -124,12 +124,12 @@ namespace Stereo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setVertexBufferHint(bool enableMultiview)
|
void setVertexBufferHint(bool enableMultiview, bool allowDisplayListsForMultiview)
|
||||||
{
|
{
|
||||||
if (getStereo() && enableMultiview)
|
if (getStereo() && enableMultiview)
|
||||||
{
|
{
|
||||||
auto* ds = osg::DisplaySettings::instance().get();
|
auto* ds = osg::DisplaySettings::instance().get();
|
||||||
if (!Settings::Manager::getBool("allow display lists for multiview", "Stereo")
|
if (!allowDisplayListsForMultiview
|
||||||
&& ds->getVertexBufferHint() == osg::DisplaySettings::VertexBufferHint::NO_PREFERENCE)
|
&& ds->getVertexBufferHint() == osg::DisplaySettings::VertexBufferHint::NO_PREFERENCE)
|
||||||
{
|
{
|
||||||
// Note that this only works if this code is executed before realize() is called on the viewer.
|
// Note that this only works if this code is executed before realize() is called on the viewer.
|
||||||
|
|
|
@ -37,7 +37,7 @@ namespace Stereo
|
||||||
void configureExtensions(unsigned int contextID, bool enableMultiview);
|
void configureExtensions(unsigned int contextID, bool enableMultiview);
|
||||||
|
|
||||||
//! Sets the appropriate vertex buffer hint on OSG's display settings if needed
|
//! Sets the appropriate vertex buffer hint on OSG's display settings if needed
|
||||||
void setVertexBufferHint(bool enableMultiview);
|
void setVertexBufferHint(bool enableMultiview, bool allowDisplayListsForMultiview);
|
||||||
|
|
||||||
//! Creates a Texture2D as a texture view into a Texture2DArray
|
//! Creates a Texture2D as a texture view into a Texture2DArray
|
||||||
osg::ref_ptr<osg::Texture2D> createTextureView_Texture2DFromTexture2DArray(
|
osg::ref_ptr<osg::Texture2D> createTextureView_Texture2DFromTexture2DArray(
|
||||||
|
|
|
@ -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)
|
||||||
{
|
{
|
||||||
|
@ -132,13 +134,13 @@ namespace Stereo
|
||||||
|
|
||||||
Manager::~Manager() {}
|
Manager::~Manager() {}
|
||||||
|
|
||||||
void Manager::initializeStereo(osg::GraphicsContext* gc, bool enableMultiview)
|
void Manager::initializeStereo(osg::GraphicsContext* gc, bool enableMultiview, bool sharedShadowMaps)
|
||||||
{
|
{
|
||||||
auto ci = gc->getState()->getContextID();
|
auto ci = gc->getState()->getContextID();
|
||||||
configureExtensions(ci, enableMultiview);
|
configureExtensions(ci, enableMultiview);
|
||||||
|
|
||||||
mMainCamera->addUpdateCallback(mUpdateCallback);
|
mMainCamera->addUpdateCallback(mUpdateCallback);
|
||||||
mFrustumManager = std::make_unique<StereoFrustumManager>(mViewer->getCamera());
|
mFrustumManager = std::make_unique<StereoFrustumManager>(sharedShadowMaps, mViewer->getCamera());
|
||||||
|
|
||||||
if (getMultiview())
|
if (getMultiview())
|
||||||
setupOVRMultiView2Technique();
|
setupOVRMultiView2Technique();
|
||||||
|
@ -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
|
||||||
|
@ -394,60 +393,30 @@ namespace Stereo
|
||||||
right = mRight;
|
right = mRight;
|
||||||
}
|
}
|
||||||
|
|
||||||
InitializeStereoOperation::InitializeStereoOperation()
|
InitializeStereoOperation::InitializeStereoOperation(const Settings& settings)
|
||||||
: GraphicsOperation("InitializeStereoOperation", false)
|
: GraphicsOperation("InitializeStereoOperation", false)
|
||||||
|
, mMultiview(settings.mMultiview)
|
||||||
|
, mSharedShadowMaps(settings.mSharedShadowMaps)
|
||||||
|
, mCustomView(settings.mCustomView)
|
||||||
|
, mEyeResolution(settings.mEyeResolution)
|
||||||
{
|
{
|
||||||
// Ideally, this would have belonged to the operator(). But the vertex buffer
|
// Ideally, this would have belonged to the operator(). But the vertex buffer
|
||||||
// hint has to be set before realize is called on the osg viewer, and so has to
|
// hint has to be set before realize is called on the osg viewer, and so has to
|
||||||
// be done here instead.
|
// be done here instead.
|
||||||
Stereo::setVertexBufferHint(Settings::Manager::getBool("multiview", "Stereo"));
|
Stereo::setVertexBufferHint(settings.mMultiview, settings.mAllowDisplayListsForMultiview);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitializeStereoOperation::operator()(osg::GraphicsContext* graphicsContext)
|
void InitializeStereoOperation::operator()(osg::GraphicsContext* graphicsContext)
|
||||||
{
|
{
|
||||||
auto& sm = Stereo::Manager::instance();
|
auto& sm = Stereo::Manager::instance();
|
||||||
|
|
||||||
if (Settings::Manager::getBool("use custom view", "Stereo"))
|
if (mCustomView.has_value())
|
||||||
{
|
sm.setUpdateViewCallback(
|
||||||
Stereo::View left;
|
std::make_shared<Stereo::Manager::CustomViewCallback>(mCustomView->mLeft, mCustomView->mRight));
|
||||||
Stereo::View right;
|
|
||||||
|
|
||||||
left.pose.position.x() = Settings::Manager::getDouble("left eye offset x", "Stereo View");
|
if (mEyeResolution.has_value())
|
||||||
left.pose.position.y() = Settings::Manager::getDouble("left eye offset y", "Stereo View");
|
sm.overrideEyeResolution(*mEyeResolution);
|
||||||
left.pose.position.z() = Settings::Manager::getDouble("left eye offset z", "Stereo View");
|
|
||||||
left.pose.orientation.x() = Settings::Manager::getDouble("left eye orientation x", "Stereo View");
|
|
||||||
left.pose.orientation.y() = Settings::Manager::getDouble("left eye orientation y", "Stereo View");
|
|
||||||
left.pose.orientation.z() = Settings::Manager::getDouble("left eye orientation z", "Stereo View");
|
|
||||||
left.pose.orientation.w() = Settings::Manager::getDouble("left eye orientation w", "Stereo View");
|
|
||||||
left.fov.angleLeft = Settings::Manager::getDouble("left eye fov left", "Stereo View");
|
|
||||||
left.fov.angleRight = Settings::Manager::getDouble("left eye fov right", "Stereo View");
|
|
||||||
left.fov.angleUp = Settings::Manager::getDouble("left eye fov up", "Stereo View");
|
|
||||||
left.fov.angleDown = Settings::Manager::getDouble("left eye fov down", "Stereo View");
|
|
||||||
|
|
||||||
right.pose.position.x() = Settings::Manager::getDouble("right eye offset x", "Stereo View");
|
sm.initializeStereo(graphicsContext, mMultiview, mSharedShadowMaps);
|
||||||
right.pose.position.y() = Settings::Manager::getDouble("right eye offset y", "Stereo View");
|
|
||||||
right.pose.position.z() = Settings::Manager::getDouble("right eye offset z", "Stereo View");
|
|
||||||
right.pose.orientation.x() = Settings::Manager::getDouble("right eye orientation x", "Stereo View");
|
|
||||||
right.pose.orientation.y() = Settings::Manager::getDouble("right eye orientation y", "Stereo View");
|
|
||||||
right.pose.orientation.z() = Settings::Manager::getDouble("right eye orientation z", "Stereo View");
|
|
||||||
right.pose.orientation.w() = Settings::Manager::getDouble("right eye orientation w", "Stereo View");
|
|
||||||
right.fov.angleLeft = Settings::Manager::getDouble("right eye fov left", "Stereo View");
|
|
||||||
right.fov.angleRight = Settings::Manager::getDouble("right eye fov right", "Stereo View");
|
|
||||||
right.fov.angleUp = Settings::Manager::getDouble("right eye fov up", "Stereo View");
|
|
||||||
right.fov.angleDown = Settings::Manager::getDouble("right eye fov down", "Stereo View");
|
|
||||||
|
|
||||||
auto customViewCallback = std::make_shared<Stereo::Manager::CustomViewCallback>(left, right);
|
|
||||||
sm.setUpdateViewCallback(customViewCallback);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Settings::Manager::getBool("use custom eye resolution", "Stereo"))
|
|
||||||
{
|
|
||||||
osg::Vec2i eyeResolution = osg::Vec2i();
|
|
||||||
eyeResolution.x() = Settings::Manager::getInt("eye resolution x", "Stereo View");
|
|
||||||
eyeResolution.y() = Settings::Manager::getInt("eye resolution y", "Stereo View");
|
|
||||||
sm.overrideEyeResolution(eyeResolution);
|
|
||||||
}
|
|
||||||
|
|
||||||
sm.initializeStereo(graphicsContext, Settings::Manager::getBool("multiview", "Stereo"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,15 +76,23 @@ 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, bool sharedShadowMaps);
|
||||||
|
|
||||||
//! Callback that updates stereo configuration during the update pass
|
//! Callback that updates stereo configuration during the update pass
|
||||||
void setUpdateViewCallback(std::shared_ptr<UpdateViewCallback> cb);
|
void setUpdateViewCallback(std::shared_ptr<UpdateViewCallback> cb);
|
||||||
|
@ -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;
|
||||||
|
@ -153,13 +163,34 @@ namespace Stereo
|
||||||
osg::ref_ptr<Identifier> mIdentifierRight = new Identifier();
|
osg::ref_ptr<Identifier> mIdentifierRight = new Identifier();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct CustomView
|
||||||
|
{
|
||||||
|
Stereo::View mLeft;
|
||||||
|
Stereo::View mRight;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Settings
|
||||||
|
{
|
||||||
|
bool mMultiview;
|
||||||
|
bool mAllowDisplayListsForMultiview;
|
||||||
|
bool mSharedShadowMaps;
|
||||||
|
std::optional<CustomView> mCustomView;
|
||||||
|
std::optional<osg::Vec2i> mEyeResolution;
|
||||||
|
};
|
||||||
|
|
||||||
//! Performs stereo-specific initialization operations.
|
//! Performs stereo-specific initialization operations.
|
||||||
class InitializeStereoOperation final : public osg::GraphicsOperation
|
class InitializeStereoOperation final : public osg::GraphicsOperation
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
InitializeStereoOperation();
|
explicit InitializeStereoOperation(const Settings& settings);
|
||||||
|
|
||||||
void operator()(osg::GraphicsContext* graphicsContext) override;
|
void operator()(osg::GraphicsContext* graphicsContext) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool mMultiview;
|
||||||
|
bool mSharedShadowMaps;
|
||||||
|
std::optional<CustomView> mCustomView;
|
||||||
|
std::optional<osg::Vec2i> mEyeResolution;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue