@ -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 ( ) )
{
@ -402,39 +382,16 @@ 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 ;