|
|
|
@ -105,6 +105,8 @@ namespace Stereo
|
|
|
|
|
Manager* mManager;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static bool sStereoEnabled = false;
|
|
|
|
|
|
|
|
|
|
static Manager* sInstance = nullptr;
|
|
|
|
|
|
|
|
|
|
Manager& Manager::instance()
|
|
|
|
@ -112,19 +114,7 @@ namespace Stereo
|
|
|
|
|
return *sInstance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct CustomViewCallback : public Manager::UpdateViewCallback
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
CustomViewCallback();
|
|
|
|
|
|
|
|
|
|
void updateView(View& left, View& right) override;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
View mLeft;
|
|
|
|
|
View mRight;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Manager::Manager(osgViewer::Viewer* viewer)
|
|
|
|
|
Manager::Manager(osgViewer::Viewer* viewer, bool enableStereo)
|
|
|
|
|
: mViewer(viewer)
|
|
|
|
|
, mMainCamera(mViewer->getCamera())
|
|
|
|
|
, mUpdateCallback(new StereoUpdateCallback(this))
|
|
|
|
@ -137,29 +127,19 @@ namespace Stereo
|
|
|
|
|
if (sInstance)
|
|
|
|
|
throw std::logic_error("Double instance of Stereo::Manager");
|
|
|
|
|
sInstance = this;
|
|
|
|
|
|
|
|
|
|
if (Settings::Manager::getBool("use custom view", "Stereo"))
|
|
|
|
|
mUpdateViewCallback = std::make_shared<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");
|
|
|
|
|
overrideEyeResolution(eyeResolution);
|
|
|
|
|
}
|
|
|
|
|
sStereoEnabled = enableStereo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Manager::~Manager() {}
|
|
|
|
|
|
|
|
|
|
void Manager::initializeStereo(osg::GraphicsContext* gc)
|
|
|
|
|
void Manager::initializeStereo(osg::GraphicsContext* gc, bool enableMultiview)
|
|
|
|
|
{
|
|
|
|
|
auto ci = gc->getState()->getContextID();
|
|
|
|
|
configureExtensions(ci, enableMultiview);
|
|
|
|
|
|
|
|
|
|
mMainCamera->addUpdateCallback(mUpdateCallback);
|
|
|
|
|
mFrustumManager = std::make_unique<StereoFrustumManager>(mViewer->getCamera());
|
|
|
|
|
|
|
|
|
|
auto ci = gc->getState()->getContextID();
|
|
|
|
|
configureExtensions(ci);
|
|
|
|
|
|
|
|
|
|
if (getMultiview())
|
|
|
|
|
setupOVRMultiView2Technique();
|
|
|
|
|
else
|
|
|
|
@ -168,7 +148,7 @@ namespace Stereo
|
|
|
|
|
updateStereoFramebuffer();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Manager::shaderStereoDefines(Shader::ShaderManager::DefineMap& defines) const
|
|
|
|
|
void shaderStereoDefines(Shader::ShaderManager::DefineMap& defines)
|
|
|
|
|
{
|
|
|
|
|
if (getMultiview())
|
|
|
|
|
{
|
|
|
|
@ -399,41 +379,75 @@ namespace Stereo
|
|
|
|
|
|
|
|
|
|
bool getStereo()
|
|
|
|
|
{
|
|
|
|
|
static bool stereo = Settings::Manager::getBool("stereo enabled", "Stereo")
|
|
|
|
|
|| osg::DisplaySettings::instance().get()->getStereo();
|
|
|
|
|
return stereo;
|
|
|
|
|
return sStereoEnabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CustomViewCallback::CustomViewCallback()
|
|
|
|
|
Manager::CustomViewCallback::CustomViewCallback(View left, View right)
|
|
|
|
|
: mLeft(left)
|
|
|
|
|
, mRight(right)
|
|
|
|
|
{
|
|
|
|
|
mLeft.pose.position.x() = Settings::Manager::getDouble("left eye offset x", "Stereo View");
|
|
|
|
|
mLeft.pose.position.y() = Settings::Manager::getDouble("left eye offset y", "Stereo View");
|
|
|
|
|
mLeft.pose.position.z() = Settings::Manager::getDouble("left eye offset z", "Stereo View");
|
|
|
|
|
mLeft.pose.orientation.x() = Settings::Manager::getDouble("left eye orientation x", "Stereo View");
|
|
|
|
|
mLeft.pose.orientation.y() = Settings::Manager::getDouble("left eye orientation y", "Stereo View");
|
|
|
|
|
mLeft.pose.orientation.z() = Settings::Manager::getDouble("left eye orientation z", "Stereo View");
|
|
|
|
|
mLeft.pose.orientation.w() = Settings::Manager::getDouble("left eye orientation w", "Stereo View");
|
|
|
|
|
mLeft.fov.angleLeft = Settings::Manager::getDouble("left eye fov left", "Stereo View");
|
|
|
|
|
mLeft.fov.angleRight = Settings::Manager::getDouble("left eye fov right", "Stereo View");
|
|
|
|
|
mLeft.fov.angleUp = Settings::Manager::getDouble("left eye fov up", "Stereo View");
|
|
|
|
|
mLeft.fov.angleDown = Settings::Manager::getDouble("left eye fov down", "Stereo View");
|
|
|
|
|
|
|
|
|
|
mRight.pose.position.x() = Settings::Manager::getDouble("right eye offset x", "Stereo View");
|
|
|
|
|
mRight.pose.position.y() = Settings::Manager::getDouble("right eye offset y", "Stereo View");
|
|
|
|
|
mRight.pose.position.z() = Settings::Manager::getDouble("right eye offset z", "Stereo View");
|
|
|
|
|
mRight.pose.orientation.x() = Settings::Manager::getDouble("right eye orientation x", "Stereo View");
|
|
|
|
|
mRight.pose.orientation.y() = Settings::Manager::getDouble("right eye orientation y", "Stereo View");
|
|
|
|
|
mRight.pose.orientation.z() = Settings::Manager::getDouble("right eye orientation z", "Stereo View");
|
|
|
|
|
mRight.pose.orientation.w() = Settings::Manager::getDouble("right eye orientation w", "Stereo View");
|
|
|
|
|
mRight.fov.angleLeft = Settings::Manager::getDouble("right eye fov left", "Stereo View");
|
|
|
|
|
mRight.fov.angleRight = Settings::Manager::getDouble("right eye fov right", "Stereo View");
|
|
|
|
|
mRight.fov.angleUp = Settings::Manager::getDouble("right eye fov up", "Stereo View");
|
|
|
|
|
mRight.fov.angleDown = Settings::Manager::getDouble("right eye fov down", "Stereo View");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CustomViewCallback::updateView(View& left, View& right)
|
|
|
|
|
void Manager::CustomViewCallback::updateView(View& left, View& right)
|
|
|
|
|
{
|
|
|
|
|
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"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|