Move InitializeStereoOperation to components/stereo

revert-6246b479
Mads Buvik Sandvei 2 years ago committed by unknown
parent fe066069d7
commit 7d69bea7dc

@ -144,64 +144,6 @@ namespace
private: private:
int mMaxTextureImageUnits = 0; int mMaxTextureImageUnits = 0;
}; };
class InitializeStereoOperation final : public osg::GraphicsOperation
{
public:
InitializeStereoOperation()
: GraphicsOperation("InitializeStereoOperation", false)
{
}
void operator()(osg::GraphicsContext* graphicsContext) override
{
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 (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"));
}
};
} }
void OMW::Engine::executeLocalScripts() void OMW::Engine::executeLocalScripts()
@ -652,10 +594,7 @@ void OMW::Engine::createWindow()
realizeOperations->add(mSelectColorFormatOperation); realizeOperations->add(mSelectColorFormatOperation);
if (Stereo::getStereo()) if (Stereo::getStereo())
{ realizeOperations->add(new Stereo::InitializeStereoOperation());
realizeOperations->add(new InitializeStereoOperation());
Stereo::setVertexBufferHint(Settings::Manager::getBool("multiview", "Stereo"));
}
mViewer->realize(); mViewer->realize();
mGlMaxTextureImageUnits = identifyOp->getMaxTextureImageUnits(); mGlMaxTextureImageUnits = identifyOp->getMaxTextureImageUnits();

@ -396,4 +396,61 @@ namespace Stereo
left = mLeft; left = mLeft;
right = mRight; right = mRight;
} }
InitializeStereoOperation::InitializeStereoOperation()
: GraphicsOperation("InitializeStereoOperation", false)
{
// 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"));
}
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 (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"));
}
} }

@ -72,7 +72,7 @@ namespace Stereo
static Manager& instance(); static Manager& instance();
//! Constructor //! Constructor
//! //!
//! @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.
@ -82,7 +82,7 @@ namespace Stereo
//! Called during update traversal //! Called during update traversal
void update(); void update();
//! 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);
@ -152,6 +152,15 @@ namespace Stereo
osg::ref_ptr<Identifier> mIdentifierLeft = new Identifier(); osg::ref_ptr<Identifier> mIdentifierLeft = new Identifier();
osg::ref_ptr<Identifier> mIdentifierRight = new Identifier(); osg::ref_ptr<Identifier> mIdentifierRight = new Identifier();
}; };
//! Performs stereo-specific initialization operations.
class InitializeStereoOperation final : public osg::GraphicsOperation
{
public:
InitializeStereoOperation();
void operator()(osg::GraphicsContext* graphicsContext) override;
};
} }
#endif #endif

Loading…
Cancel
Save