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:
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()
@ -652,10 +594,7 @@ void OMW::Engine::createWindow()
realizeOperations->add(mSelectColorFormatOperation);
if (Stereo::getStereo())
{
realizeOperations->add(new InitializeStereoOperation());
Stereo::setVertexBufferHint(Settings::Manager::getBool("multiview", "Stereo"));
}
realizeOperations->add(new Stereo::InitializeStereoOperation());
mViewer->realize();
mGlMaxTextureImageUnits = identifyOp->getMaxTextureImageUnits();

@ -396,4 +396,61 @@ namespace Stereo
left = mLeft;
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();
//! Constructor
//!
//!
//! @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.
@ -82,7 +82,7 @@ namespace Stereo
//! Called during update traversal
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.
void initializeStereo(osg::GraphicsContext* gc, bool enableMultiview);
@ -152,6 +152,15 @@ namespace Stereo
osg::ref_ptr<Identifier> mIdentifierLeft = 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

Loading…
Cancel
Save