@ -105,6 +105,8 @@ namespace Stereo
Manager * mManager ;
Manager * mManager ;
} ;
} ;
static bool sStereoEnabled = false ;
static Manager * sInstance = nullptr ;
static Manager * sInstance = nullptr ;
Manager & Manager : : instance ( )
Manager & Manager : : instance ( )
@ -112,19 +114,7 @@ namespace Stereo
return * sInstance ;
return * sInstance ;
}
}
struct CustomViewCallback : public Manager : : UpdateViewCallback
Manager : : Manager ( osgViewer : : Viewer * viewer , bool enableStereo )
{
public :
CustomViewCallback ( ) ;
void updateView ( View & left , View & right ) override ;
private :
View mLeft ;
View mRight ;
} ;
Manager : : Manager ( osgViewer : : Viewer * viewer )
: mViewer ( viewer )
: mViewer ( viewer )
, mMainCamera ( mViewer - > getCamera ( ) )
, mMainCamera ( mViewer - > getCamera ( ) )
, mUpdateCallback ( new StereoUpdateCallback ( this ) )
, mUpdateCallback ( new StereoUpdateCallback ( this ) )
@ -137,29 +127,19 @@ namespace Stereo
if ( sInstance )
if ( sInstance )
throw std : : logic_error ( " Double instance of Stereo::Manager " ) ;
throw std : : logic_error ( " Double instance of Stereo::Manager " ) ;
sInstance = this ;
sInstance = this ;
sStereoEnabled = enableStereo ;
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 ) ;
}
}
}
Manager : : ~ Manager ( ) { }
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 ) ;
mMainCamera - > addUpdateCallback ( mUpdateCallback ) ;
mFrustumManager = std : : make_unique < StereoFrustumManager > ( mViewer - > getCamera ( ) ) ;
mFrustumManager = std : : make_unique < StereoFrustumManager > ( mViewer - > getCamera ( ) ) ;
auto ci = gc - > getState ( ) - > getContextID ( ) ;
configureExtensions ( ci ) ;
if ( getMultiview ( ) )
if ( getMultiview ( ) )
setupOVRMultiView2Technique ( ) ;
setupOVRMultiView2Technique ( ) ;
else
else
@ -168,7 +148,7 @@ namespace Stereo
updateStereoFramebuffer ( ) ;
updateStereoFramebuffer ( ) ;
}
}
void Manager: : shaderStereoDefines( Shader : : ShaderManager : : DefineMap & defines ) const
void shaderStereoDefines( Shader : : ShaderManager : : DefineMap & defines )
{
{
if ( getMultiview ( ) )
if ( getMultiview ( ) )
{
{
@ -402,39 +382,16 @@ namespace Stereo
bool getStereo ( )
bool getStereo ( )
{
{
static bool stereo = Settings : : Manager : : getBool ( " stereo enabled " , " Stereo " )
return sStereoEnabled ;
| | osg : : DisplaySettings : : instance ( ) . get ( ) - > getStereo ( ) ;
}
return stereo ;
}
Manager : : CustomViewCallback : : CustomViewCallback ( View left , View right )
: mLeft ( left )
CustomViewCallback : : CustomViewCallback ( )
, 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 " ) ;
void Manager : : CustomViewCallback : : updateView ( View & left , View & right )
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 )
{
{
left = mLeft ;
left = mLeft ;
right = mRight ;
right = mRight ;