Merge branch 'settings_values_stereo' into 'master'

Use settings values for Stereo settings (#6876)

See merge request OpenMW/openmw!3530
macos_ci_fix
Alexei Kotov 1 year ago
commit c49c401441

@ -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();
@ -593,7 +595,63 @@ void OMW::Engine::createWindow()
realizeOperations->add(mSelectColorFormatOperation);
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();
mGlMaxTextureImageUnits = identifyOp->getMaxTextureImageUnits();
@ -632,9 +690,9 @@ void OMW::Engine::prepareEngine()
mStateManager = std::make_unique<MWState::StateManager>(mCfgMgr.getUserDataPath() / "saves", mContentFiles);
mEnvironment.setStateManager(*mStateManager);
bool stereoEnabled
= Settings::Manager::getBool("stereo enabled", "Stereo") || osg::DisplaySettings::instance().get()->getStereo();
mStereoManager = std::make_unique<Stereo::Manager>(mViewer, stereoEnabled);
const bool stereoEnabled = Settings::stereo().mStereoEnabled || osg::DisplaySettings::instance().get()->getStereo();
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);

@ -31,14 +31,14 @@ namespace Settings
makeClampSanitizerDouble(-1, 1) };
SettingValue<double> mLeftEyeOrientationW{ mIndex, "Stereo View", "left eye orientation w",
makeClampSanitizerDouble(-1, 1) };
SettingValue<double> mLeftEyeFovLeft{ mIndex, "Stereo View", "left eye fov left",
makeClampSanitizerDouble(-osg::PI, osg::PI) };
SettingValue<double> mLeftEyeFovRight{ mIndex, "Stereo View", "left eye fov right",
makeClampSanitizerDouble(-osg::PI, osg::PI) };
SettingValue<double> mLeftEyeFovUp{ mIndex, "Stereo View", "left eye fov up",
makeClampSanitizerDouble(-osg::PI, osg::PI) };
SettingValue<double> mLeftEyeFovDown{ mIndex, "Stereo View", "left eye fov down",
makeClampSanitizerDouble(-osg::PI, osg::PI) };
SettingValue<float> mLeftEyeFovLeft{ mIndex, "Stereo View", "left eye fov left",
makeClampSanitizerFloat(-osg::PIf, osg::PIf) };
SettingValue<float> mLeftEyeFovRight{ mIndex, "Stereo View", "left eye fov right",
makeClampSanitizerFloat(-osg::PIf, osg::PIf) };
SettingValue<float> mLeftEyeFovUp{ mIndex, "Stereo View", "left eye fov up",
makeClampSanitizerFloat(-osg::PIf, osg::PIf) };
SettingValue<float> mLeftEyeFovDown{ mIndex, "Stereo View", "left eye fov down",
makeClampSanitizerFloat(-osg::PIf, osg::PIf) };
SettingValue<double> mRightEyeOffsetX{ mIndex, "Stereo View", "right eye offset x" };
SettingValue<double> mRightEyeOffsetY{ mIndex, "Stereo View", "right eye offset y" };
SettingValue<double> mRightEyeOffsetZ{ mIndex, "Stereo View", "right eye offset z" };
@ -50,14 +50,14 @@ namespace Settings
makeClampSanitizerDouble(-1, 1) };
SettingValue<double> mRightEyeOrientationW{ mIndex, "Stereo View", "right eye orientation w",
makeClampSanitizerDouble(-1, 1) };
SettingValue<double> mRightEyeFovLeft{ mIndex, "Stereo View", "right eye fov left",
makeClampSanitizerDouble(-osg::PI, osg::PI) };
SettingValue<double> mRightEyeFovRight{ mIndex, "Stereo View", "right eye fov right",
makeClampSanitizerDouble(-osg::PI, osg::PI) };
SettingValue<double> mRightEyeFovUp{ mIndex, "Stereo View", "right eye fov up",
makeClampSanitizerDouble(-osg::PI, osg::PI) };
SettingValue<double> mRightEyeFovDown{ mIndex, "Stereo View", "right eye fov down",
makeClampSanitizerDouble(-osg::PI, osg::PI) };
SettingValue<float> mRightEyeFovLeft{ mIndex, "Stereo View", "right eye fov left",
makeClampSanitizerFloat(-osg::PIf, osg::PIf) };
SettingValue<float> mRightEyeFovRight{ mIndex, "Stereo View", "right eye fov right",
makeClampSanitizerFloat(-osg::PIf, osg::PIf) };
SettingValue<float> mRightEyeFovUp{ mIndex, "Stereo View", "right eye fov up",
makeClampSanitizerFloat(-osg::PIf, osg::PIf) };
SettingValue<float> mRightEyeFovDown{ mIndex, "Stereo View", "right eye fov down",
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)
, mShadowTechnique(nullptr)
, mShadowFrustumCallback(nullptr)
@ -95,7 +95,7 @@ namespace Stereo
mMultiviewFrustumCallback = std::make_unique<MultiviewFrustumCallback>(this, camera);
}
if (Settings::Manager::getBool("shared shadow maps", "Stereo"))
if (sharedShadowMaps)
{
mShadowFrustumCallback = new ShadowFrustumCallback(this);
auto* renderer = static_cast<osgViewer::Renderer*>(mCamera->getRenderer());

@ -45,7 +45,7 @@ namespace Stereo
class StereoFrustumManager
{
public:
StereoFrustumManager(osg::Camera* camera);
StereoFrustumManager(bool sharedShadowMaps, osg::Camera* camera);
~StereoFrustumManager();
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)
{
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)
{
// 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);
//! 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
osg::ref_ptr<osg::Texture2D> createTextureView_Texture2DFromTexture2DArray(

@ -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)
{
@ -132,13 +134,13 @@ namespace Stereo
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();
configureExtensions(ci, enableMultiview);
mMainCamera->addUpdateCallback(mUpdateCallback);
mFrustumManager = std::make_unique<StereoFrustumManager>(mViewer->getCamera());
mFrustumManager = std::make_unique<StereoFrustumManager>(sharedShadowMaps, mViewer->getCamera());
if (getMultiview())
setupOVRMultiView2Technique();
@ -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
@ -394,60 +393,30 @@ namespace Stereo
right = mRight;
}
InitializeStereoOperation::InitializeStereoOperation()
InitializeStereoOperation::InitializeStereoOperation(const Settings& settings)
: 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
// hint has to be set before realize is called on the osg viewer, and so has to
// be done here instead.
Stereo::setVertexBufferHint(Settings::Manager::getBool("multiview", "Stereo"));
Stereo::setVertexBufferHint(settings.mMultiview, settings.mAllowDisplayListsForMultiview);
}
void InitializeStereoOperation::operator()(osg::GraphicsContext* graphicsContext)
{
auto& sm = Stereo::Manager::instance();
if (Settings::Manager::getBool("use custom view", "Stereo"))
{
Stereo::View left;
Stereo::View right;
left.pose.position.x() = Settings::Manager::getDouble("left eye offset x", "Stereo View");
left.pose.position.y() = Settings::Manager::getDouble("left eye offset y", "Stereo View");
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");
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 (mCustomView.has_value())
sm.setUpdateViewCallback(
std::make_shared<Stereo::Manager::CustomViewCallback>(mCustomView->mLeft, mCustomView->mRight));
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);
}
if (mEyeResolution.has_value())
sm.overrideEyeResolution(*mEyeResolution);
sm.initializeStereo(graphicsContext, Settings::Manager::getBool("multiview", "Stereo"));
sm.initializeStereo(graphicsContext, mMultiview, mSharedShadowMaps);
}
}

@ -76,15 +76,23 @@ 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);
void initializeStereo(osg::GraphicsContext* gc, bool enableMultiview, bool sharedShadowMaps);
//! Callback that updates stereo configuration during the update pass
void setUpdateViewCallback(std::shared_ptr<UpdateViewCallback> cb);
@ -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;
@ -153,13 +163,34 @@ namespace Stereo
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.
class InitializeStereoOperation final : public osg::GraphicsOperation
{
public:
InitializeStereoOperation();
explicit InitializeStereoOperation(const Settings& settings);
void operator()(osg::GraphicsContext* graphicsContext) override;
private:
bool mMultiview;
bool mSharedShadowMaps;
std::optional<CustomView> mCustomView;
std::optional<osg::Vec2i> mEyeResolution;
};
}

Loading…
Cancel
Save