From 3b6c2b636acc2bdb397b2cd26f54d7d659fa69da Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 16 May 2013 10:11:06 +0000 Subject: [PATCH] Renamed osgViewer::Config osgViewer::ViewConfig and moved it's declaration into include/osgViewer. --- examples/osgkeystone/osgkeystone.cpp | 6 +- include/osgViewer/Config | 276 -- include/osgViewer/View | 45 +- include/osgViewer/config/AcrossAllScreens | 6 +- .../config/PanoramicSphericalDisplay | 6 +- include/osgViewer/config/SingleScreen | 6 +- include/osgViewer/config/SingleWindow | 6 +- include/osgViewer/config/SphericalDisplay | 6 +- include/osgViewer/config/WoWVxDisplay | 10 +- src/osgViewer/CMakeLists.txt | 2 - src/osgViewer/Config.cpp | 2413 ----------------- src/osgViewer/View.cpp | 1178 +------- src/osgViewer/Viewer.cpp | 6 +- .../serializers/osgViewer/Config.cpp | 10 +- .../osgViewer/PanoramicSphericalDisplay.cpp | 2 +- .../serializers/osgViewer/SingleScreen.cpp | 2 +- .../serializers/osgViewer/SingleWindow.cpp | 2 +- .../osgViewer/SphericalDisplay.cpp | 2 +- .../serializers/osgViewer/WoWVxDisplay.cpp | 21 +- 19 files changed, 113 insertions(+), 3892 deletions(-) delete mode 100644 include/osgViewer/Config delete mode 100644 src/osgViewer/Config.cpp diff --git a/examples/osgkeystone/osgkeystone.cpp b/examples/osgkeystone/osgkeystone.cpp index 2b2af3fdd..ccb2f5d5a 100644 --- a/examples/osgkeystone/osgkeystone.cpp +++ b/examples/osgkeystone/osgkeystone.cpp @@ -39,11 +39,11 @@ int main( int argc, char **argv ) osg::ArgumentParser arguments(&argc,argv); - osg::ref_ptr config; + osg::ref_ptr config; std::string configFile; if (arguments.read("-c",configFile)) { - config = osgDB::readFile(configFile); + config = osgDB::readFile(configFile); } if (!config) { @@ -74,7 +74,7 @@ int main( int argc, char **argv ) if (config.valid()) { - config->configure(viewer); + viewer.apply(config.get()); osgDB::writeObjectFile(*config,"myconfig.osgx"); } diff --git a/include/osgViewer/Config b/include/osgViewer/Config deleted file mode 100644 index ef2c54f06..000000000 --- a/include/osgViewer/Config +++ /dev/null @@ -1,276 +0,0 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield - * - * This library is open source and may be redistributed and/or modified under - * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or - * (at your option) any later version. The full license is in LICENSE file - * included with this distribution, and on the openscenegraph.org website. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * OpenSceneGraph Public License for more details. -*/ - -#ifndef OSGVIEWER_CONFIG -#define OSGVIEWER_CONFIG 1 - -#include -#include -#include - -#include - -namespace osgViewer { - -// forward declare -class View; - -/** Config base class for encapsulating view configuration.*/ -class OSGVIEWER_EXPORT Config : public osg::Object -{ - public: - - Config() {} - - Config(const Config& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : osg::Object(rhs,copyop) {} - - META_Object(osgViewer,Config); - - /** configure method that is overridden by Config subclasses.*/ - virtual void configure(osgViewer::View& /*view*/) const {} - - virtual osg::DisplaySettings* getActiveDisplaySetting(osgViewer::View& view) const; -}; -#if 0 - -class OSGVIEWER_EXPORT ViewAcrossAllScreens : public Config -{ - public: - - ViewAcrossAllScreens() {} - ViewAcrossAllScreens(const ViewAcrossAllScreens& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY): Config(rhs,copyop) {} - - META_Object(osgViewer,ViewAcrossAllScreens); - - virtual void configure(osgViewer::View& view) const; -}; - -/** single camera on a single window.*/ -class OSGVIEWER_EXPORT ViewInWindow : public Config -{ - public: - - ViewInWindow():_x(0),_y(0),_width(-1),_height(-1),_screenNum(0) {} - ViewInWindow(int x, int y, int width, int height, unsigned int screenNum=0):_x(x),_y(y),_width(width),_height(height),_screenNum(screenNum) {} - ViewInWindow(const ViewInWindow& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):Config(rhs,copyop), _x(rhs._x),_y(rhs._y),_width(rhs._width),_height(rhs._height),_screenNum(rhs._screenNum) {} - - META_Object(osgViewer,ViewInWindow); - - virtual void configure(osgViewer::View& view) const; - - void setX(int x) { _x = x; } - int getX() const { return _x; } - - void setY(int y) { _y = y; } - int getY() const { return _y; } - - void setWidth(int w) { _width = w; } - int getWidth() const { return _width; } - - void setHeight(int h) { _height = h; } - int getHeight() const { return _height; } - - void setScreenNum(unsigned int sn) { _screenNum = sn; } - unsigned int getScreenNum() const { return _screenNum; } - - protected: - - int _x, _y, _width, _height; - unsigned int _screenNum; -}; - - -/** single camera associated with a single full screen GraphicsWindow.*/ -class OSGVIEWER_EXPORT ViewOnSingleScreen : public Config -{ - public: - - ViewOnSingleScreen(unsigned int screenNum=0) : _screenNum(screenNum) {} - ViewOnSingleScreen(const ViewOnSingleScreen& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : Config(rhs,copyop), _screenNum(rhs._screenNum) {} - - META_Object(osgViewer,ViewOnSingleScreen); - - virtual void configure(osgViewer::View& view) const; - - void setScreenNum(unsigned int sn) { _screenNum = sn; } - unsigned int getScreenNum() const { return _screenNum; } - - protected: - - unsigned int _screenNum; -}; - - -/** spherical display using 6 slave cameras rendering the 6 sides of a cube map, and 7th camera doing distortion correction to present on a spherical display.*/ -class OSGVIEWER_EXPORT ViewFor3DSphericalDisplay : public Config -{ - public: - - ViewFor3DSphericalDisplay(double radius=1.0, double collar=0.45, unsigned int screenNum=0, osg::Image* intensityMap=0, const osg::Matrixd& projectorMatrix = osg::Matrixd()): - _radius(radius), - _collar(collar), - _screenNum(screenNum), - _intensityMap(intensityMap), - _projectorMatrix(projectorMatrix) {} - - ViewFor3DSphericalDisplay(const ViewFor3DSphericalDisplay& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY): - Config(rhs,copyop), - _radius(rhs._radius), - _collar(rhs._collar), - _screenNum(rhs._screenNum), - _intensityMap(rhs._intensityMap), - _projectorMatrix(rhs._projectorMatrix) {} - - META_Object(osgViewer,ViewFor3DSphericalDisplay); - - virtual void configure(osgViewer::View& view) const; - - void setRadius(double r) { _radius = r; } - double getRadius() const { return _radius; } - - void setCollar(double r) { _collar = r; } - double getCollar() const { return _collar; } - - void setScreenNum(unsigned int n) { _screenNum = n; } - unsigned int getScreenNum() const { return _screenNum; } - - void setIntensityMap(osg::Image* im) { _intensityMap = im; } - const osg::Image* getIntensityMap() const { return _intensityMap.get(); } - - void setProjectionMatrix(const osg::Matrixd& m) { _projectorMatrix = m; } - const osg::Matrixd& getProjectionMatrix() const { return _projectorMatrix; } - - protected: - - osg::Geometry* create3DSphericalDisplayDistortionMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector, double sphere_radius, double collar_radius,osg::Image* intensityMap, const osg::Matrix& projectorMatrix) const; - - double _radius; - double _collar; - unsigned int _screenNum; - osg::ref_ptr _intensityMap; - osg::Matrixd _projectorMatrix; -}; - -/** spherical display by rendering main scene to a panoramic 2:1 texture and then doing distortion correction to present onto a spherical display.*/ -class OSGVIEWER_EXPORT ViewForPanoramicSphericalDisplay : public Config -{ - public: - - ViewForPanoramicSphericalDisplay(double radius=1.0, double collar=0.45, unsigned int screenNum=0, osg::Image* intensityMap=0, const osg::Matrixd& projectorMatrix = osg::Matrixd()); - ViewForPanoramicSphericalDisplay(const ViewForPanoramicSphericalDisplay& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); - - META_Object(osgViewer,ViewOnSingleScreen); - - virtual void configure(osgViewer::View& view) const; - - void setRadius(double r) { _radius = r; } - double getRadius() const { return _radius; } - - void setCollar(double r) { _collar = r; } - double getCollar() const { return _collar; } - - void setScreenNum(unsigned int n) { _screenNum = n; } - unsigned int getScreenNum() const { return _screenNum; } - - void setIntensityMap(osg::Image* im) { _intensityMap = im; } - const osg::Image* getIntensityMap() const { return _intensityMap; } - - void setProjectionMatrix(const osg::Matrixd& m) { _projectorMatrix = m; } - const osg::Matrixd& getProjectionMatrix() const { return _projectorMatrix; } - - protected: - - double _radius; - double _collar; - unsigned int _screenNum; - osg::ref_ref _intensityMap; - osg::Matrixd _projectorMatrix; -}; - -/** autostereoscopic Philips WoWvx display.*/ -class OSGVIEWER_EXPORT ViewForWoWVxDisplay : public Config -{ - public: - - ViewForWoWVxDisplay(); - ViewForWoWVxDisplay(unsigned int screenNum, unsigned char wow_content, unsigned char wow_factor, unsigned char wow_offset, float wow_disparity_Zd, float wow_disparity_vz, float wow_disparity_M, float wow_disparity_C); - ViewForWoWVxDisplay(const ViewForWoWVxDisplay& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); - - META_Object(osgViewer,ViewForWoWVxDisplay); - - virtual void configure(osgViewer::View& view) const; - - void setScreenNum(unsigned int n) { _screenNum = n; } - unsigned int getScreenNum() const { return _screenNum; } - - void set(unsigned char c) { _wow_content = c; } - double get() const { return _wow_content; } - - void set(unsigned char c) { _wow_factor = c; } - double get() const { return _wow_factor; } - - void set(unsigned char c) { _wow_offset = c; } - double get() const { return _wow_offset; } - - void setWowDisparityZD(float c) { _wow_disparity_Zd = c; } - float getWowDisparityZD() const { return _wow_disparity_Zd; } - - void setWowDisparityVZ(float c) { _wow_disparity_vz = c; } - float getWowDisparityVZ() const { return _wow_disparity_vz; } - - void setWowDisparityM(float c) { _wow_disparity_M = c; } - float getWowDisparityM() const { return _wow_disparity_M; } - - void setWowDisparityC(float c) { _wow_disparity_C = c; } - float getWowDisparityC() const { return _wow_disparity_C; } - - protected: - - unsigned int _screenNum; - unsigned char _wow_content; - unsigned char _wow_factor; - unsigned char _wow_offset; - float _wow_disparity_Zd; - float _wow_disparity_vz; - float _wow_disparity_M; - float _wow_disparity_C; -}; - -/** Configure view with DepthPartition.*/ -class OSGVIEWER_EXPORT DepthPartition : public Config -{ - public: - - DepthPartition(DepthPartitionSettings* dsp=0); - - DepthPartition(const ViewForWoWVxDisplay& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); - - META_Object(osgViewer,DepthPartition); - - void setDepthPartionSettings(DepthPartitionSettings* dsp) const { _dps = dps; } - const DepthPartitionSettings* getDepthPartionSettings() const { return _dps; } - - /** for setting up depth partitioning on the specified camera.*/ - bool setUpDepthPartitionForCamera(osg::Camera* cameraToPartition, DepthPartitionSettings* dps=0); - - virtual void configure(osgViewer::View& view) const; - - protected: -}; - -#endif - -} - - -#endif diff --git a/include/osgViewer/View b/include/osgViewer/View index bd2aa0802..1ab324b9c 100644 --- a/include/osgViewer/View +++ b/include/osgViewer/View @@ -33,6 +33,25 @@ namespace osgViewer { +/** Base class for View configurations for setting up Camera and Windowing.*/ +class OSGVIEWER_EXPORT ViewConfig : public osg::Object +{ + public: + + ViewConfig() {} + + ViewConfig(const ViewConfig& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : osg::Object(rhs,copyop) {} + + META_Object(osgViewer,ViewConfig); + + /** configure method that is overridden by Config subclasses.*/ + virtual void configure(osgViewer::View& /*view*/) const {} + + /** convinience method for getting the relavent display settings to use.*/ + virtual osg::DisplaySettings* getActiveDisplaySetting(osgViewer::View& view) const; +}; + + struct OSGVIEWER_EXPORT DepthPartitionSettings : public osg::Referenced { enum DepthMode @@ -197,26 +216,33 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter /** Get the FusionDistanceValue. Note, only used for USE_FUSION_DISTANCE_VALUE & PROPORTIONAL_TO_SCREEN_DISTANCE modes.*/ float getFusionDistanceValue() const { return _fusionDistanceValue; } - - /** Convenience method for creating slave Cameras and associated GraphicsWindows across all screens.*/ + + /** Apply a viewer configuration to set up Cameras and Windowing. */ + void apply(ViewConfig* config); + + ViewConfig* getLastAppliedViewConfig() { return _lastAppliedViewConfig.get(); } + const ViewConfig* getLastAppliedViewConfig() const { return _lastAppliedViewConfig.get(); } + + + /** deprecated, use view.apply(new osgViewer::AcrossAllWindows()). */ void setUpViewAcrossAllScreens(); - /** Convenience method for a single camera on a single window.*/ + /** depreacted, use view.apply(new osgViewer::SingleWindow(x,y,width,screenNum)). */ void setUpViewInWindow(int x, int y, int width, int height, unsigned int screenNum=0); - /** Convenience method for a single camera associated with a single full screen GraphicsWindow.*/ + /** deprecated, use view.apply(new osgViewer::SingleScreen(screenNum)). */ void setUpViewOnSingleScreen(unsigned int screenNum=0); - - /** Convenience method for spherical display using 6 slave cameras rendering the 6 sides of a cube map, and 7th camera doing distortion correction to present on a spherical display.*/ + /** deprecated, use view.apply(new osgViewer::SphericalDisplay(radius, collar, screenNum, intensityMap, projectorMatrix)). */ void setUpViewFor3DSphericalDisplay(double radius=1.0, double collar=0.45, unsigned int screenNum=0, osg::Image* intensityMap=0, const osg::Matrixd& projectorMatrix = osg::Matrixd()); - /** Convenience method for spherical display by rendering main scene to a panoramic 2:1 texture and then doing distortion correction to present onto a spherical display.*/ + /** depreacted, use view.apply(new osgViewer::PanoramicSphericalDisplay(radius, collar, screenNum, intensityMap, projectorMatrix)). */ void setUpViewForPanoramicSphericalDisplay(double radius=1.0, double collar=0.45, unsigned int screenNum=0, osg::Image* intensityMap=0, const osg::Matrixd& projectorMatrix = osg::Matrixd()); - /** Convenience method for autostereoscopic Philips WoWvx display.*/ + /** deprecated. use view.apply(new osgViewer::WoWVxDisplay(type (20 to 42), screenNum). */ void setUpViewForWoWVxDisplay(unsigned int screenNum, unsigned char wow_content, unsigned char wow_factor, unsigned char wow_offset, float wow_disparity_Zd, float wow_disparity_vz, float wow_disparity_M, float wow_disparity_C); + /** Convenience method for setting up depth partitioning on the specified camera.*/ bool setUpDepthPartitionForCamera(osg::Camera* cameraToPartition, DepthPartitionSettings* dps=0); @@ -307,6 +333,9 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter osg::ref_ptr _displaySettings; osgUtil::SceneView::FusionDistanceMode _fusionDistanceMode; float _fusionDistanceValue; + + osg::ref_ptr _lastAppliedViewConfig; + }; } diff --git a/include/osgViewer/config/AcrossAllScreens b/include/osgViewer/config/AcrossAllScreens index 01fb29b03..b07907cae 100644 --- a/include/osgViewer/config/AcrossAllScreens +++ b/include/osgViewer/config/AcrossAllScreens @@ -14,16 +14,16 @@ #ifndef OSGVIEWER_AcrossAllScreens #define OSGVIEWER_AcrossAllScreens 1 -#include +#include namespace osgViewer { -class OSGVIEWER_EXPORT AcrossAllScreens : public Config +class OSGVIEWER_EXPORT AcrossAllScreens : public ViewConfig { public: AcrossAllScreens() {} - AcrossAllScreens(const AcrossAllScreens& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY): Config(rhs,copyop) {} + AcrossAllScreens(const AcrossAllScreens& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY): ViewConfig(rhs,copyop) {} META_Object(osgViewer, AcrossAllScreens); diff --git a/include/osgViewer/config/PanoramicSphericalDisplay b/include/osgViewer/config/PanoramicSphericalDisplay index 571ed6481..3a05b82b1 100644 --- a/include/osgViewer/config/PanoramicSphericalDisplay +++ b/include/osgViewer/config/PanoramicSphericalDisplay @@ -14,12 +14,12 @@ #ifndef OSGVIEWER_PanoramicSphericalDisplay #define OSGVIEWER_PanoramicSphericalDisplay 1 -#include +#include namespace osgViewer { /** spherical display by rendering main scene to a panoramic 2:1 texture and then doing distortion correction to present onto a spherical display.*/ -class OSGVIEWER_EXPORT PanoramicSphericalDisplay : public Config +class OSGVIEWER_EXPORT PanoramicSphericalDisplay : public ViewConfig { public: @@ -31,7 +31,7 @@ class OSGVIEWER_EXPORT PanoramicSphericalDisplay : public Config _projectorMatrix(projectorMatrix) {} PanoramicSphericalDisplay(const PanoramicSphericalDisplay& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY): - Config(rhs, copyop), + ViewConfig(rhs, copyop), _radius(rhs._radius), _collar(rhs._collar), _screenNum(rhs._screenNum), diff --git a/include/osgViewer/config/SingleScreen b/include/osgViewer/config/SingleScreen index e404ae919..15cf21f36 100644 --- a/include/osgViewer/config/SingleScreen +++ b/include/osgViewer/config/SingleScreen @@ -14,17 +14,17 @@ #ifndef OSGVIEWER_SingleScreen #define OSGVIEWER_SingleScreen 1 -#include +#include namespace osgViewer { /** single camera associated with a single full screen GraphicsWindow.*/ -class OSGVIEWER_EXPORT SingleScreen : public Config +class OSGVIEWER_EXPORT SingleScreen : public ViewConfig { public: SingleScreen(unsigned int screenNum=0) : _screenNum(screenNum) {} - SingleScreen(const SingleScreen& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : Config(rhs,copyop), _screenNum(rhs._screenNum) {} + SingleScreen(const SingleScreen& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : ViewConfig(rhs,copyop), _screenNum(rhs._screenNum) {} META_Object(osgViewer, SingleScreen); diff --git a/include/osgViewer/config/SingleWindow b/include/osgViewer/config/SingleWindow index 28a333d5e..51a3fe0e2 100644 --- a/include/osgViewer/config/SingleWindow +++ b/include/osgViewer/config/SingleWindow @@ -14,18 +14,18 @@ #ifndef OSGVIEWER_SingleWindow #define OSGVIEWER_SingleWindow 1 -#include +#include namespace osgViewer { /** single camera on a single window.*/ -class OSGVIEWER_EXPORT SingleWindow : public Config +class OSGVIEWER_EXPORT SingleWindow : public ViewConfig { public: SingleWindow():_x(0),_y(0),_width(-1),_height(-1),_screenNum(0) {} SingleWindow(int x, int y, int width, int height, unsigned int screenNum=0):_x(x),_y(y),_width(width),_height(height),_screenNum(screenNum) {} - SingleWindow(const SingleWindow& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):Config(rhs,copyop), _x(rhs._x),_y(rhs._y),_width(rhs._width),_height(rhs._height),_screenNum(rhs._screenNum) {} + SingleWindow(const SingleWindow& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):ViewConfig(rhs,copyop), _x(rhs._x),_y(rhs._y),_width(rhs._width),_height(rhs._height),_screenNum(rhs._screenNum) {} META_Object(osgViewer,SingleWindow); diff --git a/include/osgViewer/config/SphericalDisplay b/include/osgViewer/config/SphericalDisplay index b4c2fc002..d756f67e8 100644 --- a/include/osgViewer/config/SphericalDisplay +++ b/include/osgViewer/config/SphericalDisplay @@ -14,12 +14,12 @@ #ifndef OSGVIEWER_SphericalDisplay #define OSGVIEWER_SphericalDisplay 1 -#include +#include namespace osgViewer { /** spherical display using 6 slave cameras rendering the 6 sides of a cube map, and 7th camera doing distortion correction to present on a spherical display.*/ -class OSGVIEWER_EXPORT SphericalDisplay : public Config +class OSGVIEWER_EXPORT SphericalDisplay : public ViewConfig { public: @@ -31,7 +31,7 @@ class OSGVIEWER_EXPORT SphericalDisplay : public Config _projectorMatrix(projectorMatrix) {} SphericalDisplay(const SphericalDisplay& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY): - Config(rhs,copyop), + ViewConfig(rhs,copyop), _radius(rhs._radius), _collar(rhs._collar), _screenNum(rhs._screenNum), diff --git a/include/osgViewer/config/WoWVxDisplay b/include/osgViewer/config/WoWVxDisplay index 517039256..a0764d9a1 100644 --- a/include/osgViewer/config/WoWVxDisplay +++ b/include/osgViewer/config/WoWVxDisplay @@ -11,15 +11,15 @@ * OpenSceneGraph Public License for more details. */ -#ifndef OSGVIEWER_PanoramicSphericalDisplay -#define OSGVIEWER_PanoramicSphericalDisplay 1 +#ifndef OSGVIEWER_WoWVxDisplay +#define OSGVIEWER_WoWVxDisplay 1 -#include +#include namespace osgViewer { /** autostereoscopic Philips WoWvx display.*/ -class OSGVIEWER_EXPORT WoWVxDisplay : public Config +class OSGVIEWER_EXPORT WoWVxDisplay : public ViewConfig { public: @@ -45,7 +45,7 @@ class OSGVIEWER_EXPORT WoWVxDisplay : public Config _wow_disparity_C(wow_disparity_C) {} WoWVxDisplay(const WoWVxDisplay& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY): - Config(rhs, copyop), + ViewConfig(rhs, copyop), _screenNum(rhs._screenNum), _wow_content(rhs._wow_content), _wow_factor(rhs._wow_factor), diff --git a/src/osgViewer/CMakeLists.txt b/src/osgViewer/CMakeLists.txt index 9b7acb628..c1bcac983 100644 --- a/src/osgViewer/CMakeLists.txt +++ b/src/osgViewer/CMakeLists.txt @@ -10,7 +10,6 @@ SET(LIB_NAME osgViewer) SET(HEADER_PATH ${OpenSceneGraph_SOURCE_DIR}/include/${LIB_NAME}) SET(TARGET_H ${HEADER_PATH}/CompositeViewer - ${HEADER_PATH}/Config ${HEADER_PATH}/Export ${HEADER_PATH}/GraphicsWindow ${HEADER_PATH}/Keystone @@ -28,7 +27,6 @@ FILE(GLOB LIB_COMMON_FILES config/*.cpp) SET(LIB_COMMON_FILES ${LIB_COMMON_FILES} CompositeViewer.cpp - Config.cpp GraphicsWindow.cpp HelpHandler.cpp Keystone.cpp diff --git a/src/osgViewer/Config.cpp b/src/osgViewer/Config.cpp deleted file mode 100644 index cf2e7ff1e..000000000 --- a/src/osgViewer/Config.cpp +++ /dev/null @@ -1,2413 +0,0 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield - * - * This library is open source and may be redistributed and/or modified under - * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or - * (at your option) any later version. The full license is in LICENSE file - * included with this distribution, and on the openscenegraph.org website. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * OpenSceneGraph Public License for more details. -*/ - -#include -#include - -#include - - -using namespace osgViewer; - -osg::DisplaySettings* Config::getActiveDisplaySetting(osgViewer::View& view) const -{ - return view.getDisplaySettings() ? view.getDisplaySettings() : osg::DisplaySettings::instance().get(); -} - -#if 0 - -void ViewAcrossAllScreens::configure(osgViewer::View& view) const -{ - osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); - if (!wsi) - { - OSG_NOTICE<<"View::setUpViewAcrossAllScreens() : Error, no WindowSystemInterface available, cannot create windows."<getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar); - - osg::GraphicsContext::ScreenIdentifier si; - si.readDISPLAY(); - - // displayNum has not been set so reset it to 0. - if (si.displayNum<0) si.displayNum = 0; - - unsigned int numScreens = wsi->getNumScreens(si); - if (numScreens==1) - { - if (si.screenNum<0) si.screenNum = 0; - - unsigned int width, height; - wsi->getScreenResolution(si, width, height); - - osg::ref_ptr traits = new osg::GraphicsContext::Traits(ds); - traits->hostName = si.hostName; - traits->displayNum = si.displayNum; - traits->screenNum = si.screenNum; - traits->x = 0; - traits->y = 0; - traits->width = width; - traits->height = height; - traits->windowDecoration = false; - traits->doubleBuffer = true; - traits->sharedContext = 0; - - osg::ref_ptr gc = osg::GraphicsContext::createGraphicsContext(traits.get()); - - view.getCamera()->setGraphicsContext(gc.get()); - - osgViewer::GraphicsWindow* gw = dynamic_cast(gc.get()); - if (gw) - { - OSG_INFO<<" GraphicsWindow has been created successfully."<getEventQueue()->getCurrentEventState()->setWindowRectangle(0, 0, width, height ); - } - else - { - OSG_NOTICE<<" GraphicsWindow has not been created successfully."<width) / double(traits->height); - double aspectRatioChange = newAspectRatio / aspectRatio; - if (aspectRatioChange != 1.0) - { - view.getCamera()->getProjectionMatrix() *= osg::Matrix::scale(1.0/aspectRatioChange,1.0,1.0); - } - - view.getCamera()->setViewport(new osg::Viewport(0, 0, traits->width, traits->height)); - - GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; - - view.getCamera()->setDrawBuffer(buffer); - view.getCamera()->setReadBuffer(buffer); - - } - else - { - - double translate_x = 0.0; - - for(unsigned int i=0; igetScreenResolution(si, width, height); - translate_x += double(width) / (double(height) * aspectRatio); - } - - bool stereoSplitScreens = numScreens==2 && - ds->getStereoMode()==osg::DisplaySettings::HORIZONTAL_SPLIT && - ds->getStereo(); - - for(unsigned int i=0; igetScreenResolution(si, width, height); - - osg::ref_ptr traits = new osg::GraphicsContext::Traits(ds); - traits->hostName = si.hostName; - traits->displayNum = si.displayNum; - traits->screenNum = si.screenNum; - traits->screenNum = i; - traits->x = 0; - traits->y = 0; - traits->width = width; - traits->height = height; - traits->windowDecoration = false; - traits->doubleBuffer = true; - traits->sharedContext = 0; - - osg::ref_ptr gc = osg::GraphicsContext::createGraphicsContext(traits.get()); - - osg::ref_ptr camera = new osg::Camera; - camera->setGraphicsContext(gc.get()); - - osgViewer::GraphicsWindow* gw = dynamic_cast(gc.get()); - if (gw) - { - OSG_INFO<<" GraphicsWindow has been created successfully."<getEventQueue()->getCurrentEventState()->setWindowRectangle(traits->x, traits->y, traits->width, traits->height ); - } - else - { - OSG_NOTICE<<" GraphicsWindow has not been created successfully."<setViewport(new osg::Viewport(0, 0, traits->width, traits->height)); - - GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; - camera->setDrawBuffer(buffer); - camera->setReadBuffer(buffer); - - if (stereoSplitScreens) - { - unsigned int leftCameraNum = (ds->getSplitStereoHorizontalEyeMapping()==osg::DisplaySettings::LEFT_EYE_LEFT_VIEWPORT) ? 0 : 1; - - osg::ref_ptr ds_local = new osg::DisplaySettings(*ds); - ds_local->setStereoMode(leftCameraNum==i ? osg::DisplaySettings::LEFT_EYE : osg::DisplaySettings::RIGHT_EYE); - camera->setDisplaySettings(ds_local.get()); - - view.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd() ); - } - else - { - double newAspectRatio = double(traits->width) / double(traits->height); - double aspectRatioChange = newAspectRatio / aspectRatio; - - view.addSlave(camera.get(), osg::Matrixd::translate( translate_x - aspectRatioChange, 0.0, 0.0) * osg::Matrix::scale(1.0/aspectRatioChange,1.0,1.0), osg::Matrixd() ); - translate_x -= aspectRatioChange * 2.0; - } - } - } - - view.assignSceneDataToCameras(); -} - - -void ViewInWindow::configure(osgViewer::View& view) const -{ - osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); - if (!wsi) - { - OSG_NOTICE<<"View::setUpViewAcrossAllScreens() : Error, no WindowSystemInterface available, cannot create windows."< traits = new osg::GraphicsContext::Traits(ds); - - traits->readDISPLAY(); - if (traits->displayNum<0) traits->displayNum = 0; - - traits->screenNum = _screenNum; - traits->x = _x; - traits->y = _y; - traits->width = _width; - traits->height = _height; - traits->windowDecoration = true; - traits->doubleBuffer = true; - traits->sharedContext = 0; - - if (traits->width<=0 || traits->height<=0 ) - { - osg::GraphicsContext::ScreenIdentifier si; - si.readDISPLAY(); - - // displayNum has not been set so reset it to 0. - if (si.displayNum<0) si.displayNum = 0; - - si.screenNum = _screenNum; - - unsigned int width, height; - wsi->getScreenResolution(si, width, height); - if (traits->width<=0) traits->width = width; - if (traits->height<=0) traits->height = height; - } - - osg::ref_ptr gc = osg::GraphicsContext::createGraphicsContext(traits.get()); - - view.getCamera()->setGraphicsContext(gc.get()); - - osgViewer::GraphicsWindow* gw = dynamic_cast(gc.get()); - if (gw) - { - OSG_INFO<<"View::setUpViewOnSingleScreen - GraphicsWindow has been created successfully."<getEventQueue()->getCurrentEventState()->setWindowRectangle(traits->x, traits->y, traits->width, traits->height ); - } - else - { - OSG_NOTICE<<" GraphicsWindow has not been created successfully."<getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar); - - double newAspectRatio = double(traits->width) / double(traits->height); - double aspectRatioChange = newAspectRatio / aspectRatio; - if (aspectRatioChange != 1.0) - { - view.getCamera()->getProjectionMatrix() *= osg::Matrix::scale(1.0/aspectRatioChange,1.0,1.0); - } - - view.getCamera()->setViewport(new osg::Viewport(0, 0, traits->width, traits->height)); - - GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; - - view.getCamera()->setDrawBuffer(buffer); - view.getCamera()->setReadBuffer(buffer); -} - -void ViewOnSingleScreen::configure(osgViewer::View& view) const -{ - osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); - if (!wsi) - { - OSG_NOTICE<<"View::setUpViewOnSingleScreen() : Error, no WindowSystemInterface available, cannot create windows."<getScreenResolution(si, width, height); - - osg::ref_ptr traits = new osg::GraphicsContext::Traits(ds); - traits->hostName = si.hostName; - traits->displayNum = si.displayNum; - traits->screenNum = si.screenNum; - traits->x = 0; - traits->y = 0; - traits->width = width; - traits->height = height; - traits->windowDecoration = false; - traits->doubleBuffer = true; - traits->sharedContext = 0; - - osg::ref_ptr gc = osg::GraphicsContext::createGraphicsContext(traits.get()); - - view.getCamera()->setGraphicsContext(gc.get()); - - osgViewer::GraphicsWindow* gw = dynamic_cast(gc.get()); - if (gw) - { - OSG_INFO<<"View::setUpViewOnSingleScreen - GraphicsWindow has been created successfully."<getEventQueue()->getCurrentEventState()->setWindowRectangle(0, 0, width, height ); - } - else - { - OSG_NOTICE<<" GraphicsWindow has not been created successfully."<getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar); - - double newAspectRatio = double(traits->width) / double(traits->height); - double aspectRatioChange = newAspectRatio / aspectRatio; - if (aspectRatioChange != 1.0) - { - view.getCamera()->getProjectionMatrix() *= osg::Matrix::scale(1.0/aspectRatioChange,1.0,1.0); - } - - view.getCamera()->setViewport(new osg::Viewport(0, 0, traits->width, traits->height)); - - GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; - - view.getCamera()->setDrawBuffer(buffer); - view.getCamera()->setReadBuffer(buffer); -} - -osg::Geometry* ViewFor3DSphericalDisplay::create3DSphericalDisplayDistortionMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector, double sphere_radius, double collar_radius,osg::Image* intensityMap, const osg::Matrix& projectorMatrix) const -{ - osg::Vec3d center(0.0,0.0,0.0); - osg::Vec3d eye(0.0,0.0,0.0); - - double distance = sqrt(sphere_radius*sphere_radius - collar_radius*collar_radius); - - bool centerProjection = false; - - osg::Vec3d projector = eye - osg::Vec3d(0.0,0.0, distance); - - OSG_INFO<<"create3DSphericalDisplayDistortionMesh : Projector position = "<getScreenResolution(si, width, height); - - - osg::ref_ptr traits = new osg::GraphicsContext::Traits; - traits->hostName = si.hostName; - traits->displayNum = si.displayNum; - traits->screenNum = si.screenNum; - traits->x = 0; - traits->y = 0; - traits->width = width; - traits->height = height; - traits->windowDecoration = false; - traits->doubleBuffer = true; - traits->sharedContext = 0; - - - osg::ref_ptr gc = osg::GraphicsContext::createGraphicsContext(traits.get()); - if (!gc) - { - OSG_NOTICE<<"GraphicsWindow has not been created successfully."<setTextureSize(tex_width, tex_height); - texture->setInternalFormat(GL_RGB); - texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); - texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); - texture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE); - texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE); - texture->setWrap(osg::Texture::WRAP_R,osg::Texture::CLAMP_TO_EDGE); - -#if 0 - osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::SEPERATE_WINDOW; - GLenum buffer = GL_FRONT; -#else - osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::FRAME_BUFFER_OBJECT; - GLenum buffer = GL_FRONT; -#endif - - // front face - { - osg::ref_ptr camera = new osg::Camera; - camera->setName("Front face camera"); - camera->setGraphicsContext(gc.get()); - camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height)); - camera->setDrawBuffer(buffer); - camera->setReadBuffer(buffer); - camera->setAllowEventFocus(false); - // tell the camera to use OpenGL frame buffer object where supported. - camera->setRenderTargetImplementation(renderTargetImplementation); - - // attach the texture and use it as the color buffer. - camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::POSITIVE_Y); - - view.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd()); - } - - - // top face - { - osg::ref_ptr camera = new osg::Camera; - camera->setName("Top face camera"); - camera->setGraphicsContext(gc.get()); - camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height)); - camera->setDrawBuffer(buffer); - camera->setReadBuffer(buffer); - camera->setAllowEventFocus(false); - - // tell the camera to use OpenGL frame buffer object where supported. - camera->setRenderTargetImplementation(renderTargetImplementation); - - // attach the texture and use it as the color buffer. - camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::POSITIVE_Z); - - view.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(-90.0f), 1.0,0.0,0.0)); - } - - // left face - { - osg::ref_ptr camera = new osg::Camera; - camera->setName("Left face camera"); - camera->setGraphicsContext(gc.get()); - camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height)); - camera->setDrawBuffer(buffer); - camera->setReadBuffer(buffer); - camera->setAllowEventFocus(false); - - // tell the camera to use OpenGL frame buffer object where supported. - camera->setRenderTargetImplementation(renderTargetImplementation); - - // attach the texture and use it as the color buffer. - camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::NEGATIVE_X); - - view.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(-90.0f), 0.0,1.0,0.0) * osg::Matrixd::rotate(osg::inDegrees(-90.0f), 0.0,0.0,1.0)); - } - - // right face - { - osg::ref_ptr camera = new osg::Camera; - camera->setName("Right face camera"); - camera->setGraphicsContext(gc.get()); - camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height)); - camera->setDrawBuffer(buffer); - camera->setReadBuffer(buffer); - camera->setAllowEventFocus(false); - - // tell the camera to use OpenGL frame buffer object where supported. - camera->setRenderTargetImplementation(renderTargetImplementation); - - // attach the texture and use it as the color buffer. - camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::POSITIVE_X); - - view.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(90.0f), 0.0,1.0,0.0 ) * osg::Matrixd::rotate(osg::inDegrees(90.0f), 0.0,0.0,1.0)); - } - - // bottom face - { - osg::ref_ptr camera = new osg::Camera; - camera->setGraphicsContext(gc.get()); - camera->setName("Bottom face camera"); - camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height)); - camera->setDrawBuffer(buffer); - camera->setReadBuffer(buffer); - camera->setAllowEventFocus(false); - - // tell the camera to use OpenGL frame buffer object where supported. - camera->setRenderTargetImplementation(renderTargetImplementation); - - // attach the texture and use it as the color buffer. - camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::NEGATIVE_Z); - - view.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(90.0f), 1.0,0.0,0.0) * osg::Matrixd::rotate(osg::inDegrees(180.0f), 0.0,0.0,1.0)); - } - - // back face - { - osg::ref_ptr camera = new osg::Camera; - camera->setName("Back face camera"); - camera->setGraphicsContext(gc.get()); - camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height)); - camera->setDrawBuffer(buffer); - camera->setReadBuffer(buffer); - camera->setAllowEventFocus(false); - - // tell the camera to use OpenGL frame buffer object where supported. - camera->setRenderTargetImplementation(renderTargetImplementation); - - // attach the texture and use it as the color buffer. - camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::NEGATIVE_Y); - - view.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(180.0f), 1.0,0.0,0.0)); - } - - view.getCamera()->setProjectionMatrixAsPerspective(90.0f, 1.0, 1, 1000.0); - - // distortion correction set up. - { - osg::Geode* geode = new osg::Geode(); - geode->addDrawable(create3DSphericalDisplayDistortionMesh(osg::Vec3(0.0f,0.0f,0.0f), osg::Vec3(width,0.0f,0.0f), osg::Vec3(0.0f,height,0.0f), _radius, _collar, applyIntensityMapAsColours ? _intensityMap.get() : 0, _projectorMatrix)); - - // new we need to add the texture to the mesh, we do so by creating a - // StateSet to contain the Texture StateAttribute. - osg::StateSet* stateset = geode->getOrCreateStateSet(); - stateset->setTextureAttributeAndModes(0, texture,osg::StateAttribute::ON); - stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); - - if (!applyIntensityMapAsColours && _intensityMap.valid()) - { - stateset->setTextureAttributeAndModes(1, new osg::Texture2D(_intensityMap.get()), osg::StateAttribute::ON); - } - - osg::ref_ptr camera = new osg::Camera; - camera->setGraphicsContext(gc.get()); - camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT ); - camera->setClearColor( osg::Vec4(0.0,0.0,0.0,1.0) ); - camera->setViewport(new osg::Viewport(0, 0, width, height)); - GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; - camera->setDrawBuffer(buffer); - camera->setReadBuffer(buffer); - camera->setReferenceFrame(osg::Camera::ABSOLUTE_RF); - camera->setAllowEventFocus(true); - camera->setInheritanceMask(camera->getInheritanceMask() & ~osg::CullSettings::CLEAR_COLOR & ~osg::CullSettings::COMPUTE_NEAR_FAR_MODE); - //camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR); - - camera->setProjectionMatrixAsOrtho2D(0,width,0,height); - camera->setViewMatrix(osg::Matrix::identity()); - - // add subgraph to render - camera->addChild(geode); - - camera->setName("DistortionCorrectionCamera"); - - view.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd(), false); - } - - view.getCamera()->setNearFarRatio(0.0001f); - - if (view.getLightingMode()==osg::View::HEADLIGHT) - { - // set a local light source for headlight to ensure that lighting is consistent across sides of cube. - view.getLight()->setPosition(osg::Vec4(0.0f,0.0f,0.0f,1.0f)); - } -} - - -static osg::Geometry* createParoramicSphericalDisplayDistortionMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector, double sphere_radius, double collar_radius, osg::Image* intensityMap, const osg::Matrix& projectorMatrix) -{ - osg::Vec3d center(0.0,0.0,0.0); - osg::Vec3d eye(0.0,0.0,0.0); - - double distance = sqrt(sphere_radius*sphere_radius - collar_radius*collar_radius); - bool flip = false; - bool texcoord_flip = false; - - osg::Vec3d projector = eye - osg::Vec3d(0.0,0.0, distance); - - - OSG_INFO<<"createParoramicSphericalDisplayDistortionMesh : Projector position = "<getScreenResolution(si, width, height); - - osg::ref_ptr traits = new osg::GraphicsContext::Traits; - traits->hostName = si.hostName; - traits->displayNum = si.displayNum; - traits->screenNum = si.screenNum; - traits->x = 0; - traits->y = 0; - traits->width = width; - traits->height = height; - traits->windowDecoration = false; - traits->doubleBuffer = true; - traits->sharedContext = 0; - - - bool applyIntensityMapAsColours = true; - - osg::ref_ptr gc = osg::GraphicsContext::createGraphicsContext(traits.get()); - if (!gc) - { - OSG_NOTICE<<"GraphicsWindow has not been created successfully."<setTextureSize(tex_width, tex_height); - texture->setInternalFormat(GL_RGB); - texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); - texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); - texture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE); - texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE); - -#if 0 - osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::SEPERATE_WINDOW; - GLenum buffer = GL_FRONT; -#else - osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::FRAME_BUFFER_OBJECT; - GLenum buffer = GL_FRONT; -#endif - - // front face - { - osg::ref_ptr camera = new osg::Camera; - camera->setName("Front face camera"); - camera->setGraphicsContext(gc.get()); - camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height)); - camera->setDrawBuffer(buffer); - camera->setReadBuffer(buffer); - camera->setAllowEventFocus(false); - // tell the camera to use OpenGL frame buffer object where supported. - camera->setRenderTargetImplementation(renderTargetImplementation); - - // attach the texture and use it as the color buffer. - camera->attach(osg::Camera::COLOR_BUFFER, texture); - - addSlave(camera.get(), osg::Matrixd(), osg::Matrixd()); - } - - // distortion correction set up. - { - osg::Geode* geode = new osg::Geode(); - geode->addDrawable(createParoramicSphericalDisplayDistortionMesh(osg::Vec3(0.0f,0.0f,0.0f), osg::Vec3(width,0.0f,0.0f), osg::Vec3(0.0f,height,0.0f), radius, collar, applyIntensityMapAsColours ? intensityMap : 0, projectorMatrix)); - - // new we need to add the texture to the mesh, we do so by creating a - // StateSet to contain the Texture StateAttribute. - osg::StateSet* stateset = geode->getOrCreateStateSet(); - stateset->setTextureAttributeAndModes(0, texture,osg::StateAttribute::ON); - stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); - - osg::TexMat* texmat = new osg::TexMat; - texmat->setScaleByTextureRectangleSize(true); - stateset->setTextureAttributeAndModes(0, texmat, osg::StateAttribute::ON); - - if (!applyIntensityMapAsColours && intensityMap) - { - stateset->setTextureAttributeAndModes(1, new osg::Texture2D(intensityMap), osg::StateAttribute::ON); - } - - osg::ref_ptr camera = new osg::Camera; - camera->setGraphicsContext(gc.get()); - camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT ); - camera->setClearColor( osg::Vec4(0.0,0.0,0.0,1.0) ); - camera->setViewport(new osg::Viewport(0, 0, width, height)); - GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; - camera->setDrawBuffer(buffer); - camera->setReadBuffer(buffer); - camera->setReferenceFrame(osg::Camera::ABSOLUTE_RF); - camera->setAllowEventFocus(false); - camera->setInheritanceMask(camera->getInheritanceMask() & ~osg::CullSettings::CLEAR_COLOR & ~osg::CullSettings::COMPUTE_NEAR_FAR_MODE); - //camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR); - - camera->setProjectionMatrixAsOrtho2D(0,width,0,height); - camera->setViewMatrix(osg::Matrix::identity()); - - // add subgraph to render - camera->addChild(geode); - - camera->setName("DistortionCorrectionCamera"); - - addSlave(camera.get(), osg::Matrixd(), osg::Matrixd(), false); - } -} - -void View::setUpViewForWoWVxDisplay(unsigned int screenNum, unsigned char wow_content, unsigned char wow_factor, unsigned char wow_offset, float wow_disparity_Zd, float wow_disparity_vz, float wow_disparity_M, float wow_disparity_C) -{ - OSG_INFO<<"View::setUpViewForWoWVxDisplay(...)"<getScreenResolution(si, width, height); - - osg::ref_ptr traits = new osg::GraphicsContext::Traits; - traits->hostName = si.hostName; - traits->displayNum = si.displayNum; - traits->screenNum = si.screenNum; - traits->x = 0; - traits->y = 0; - traits->width = width; - traits->height = height; - traits->windowDecoration = false; - traits->doubleBuffer = true; - traits->sharedContext = 0; - - - osg::ref_ptr gc = osg::GraphicsContext::createGraphicsContext(traits.get()); - if (!gc) - { - OSG_NOTICE<<"GraphicsWindow has not been created successfully."<setTextureSize(tex_width, tex_height); - texture->setInternalFormat(GL_RGB); - texture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR); - texture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR); - - osg::Texture2D* textureD = new osg::Texture2D; - textureD->setTextureSize(tex_width, tex_height); - textureD->setInternalFormat(GL_DEPTH_COMPONENT); - textureD->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR); - textureD->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR); - -#if 0 - osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::SEPERATE_WINDOW; - GLenum buffer = GL_FRONT; -#else - osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::FRAME_BUFFER_OBJECT; - GLenum buffer = GL_FRONT; -#endif - - // front face - { - osg::ref_ptr camera = new osg::Camera; - camera->setName("Front face camera"); - camera->setGraphicsContext(gc.get()); - camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height)); - camera->setDrawBuffer(buffer); - camera->setReadBuffer(buffer); - camera->setAllowEventFocus(false); - // tell the camera to use OpenGL frame buffer object where supported. - camera->setRenderTargetImplementation(renderTargetImplementation); - - // attach the texture and use it as the color buffer. - camera->attach(osg::Camera::COLOR_BUFFER, texture); - camera->attach(osg::Camera::DEPTH_BUFFER, textureD); - - addSlave(camera.get(), osg::Matrixd(), osg::Matrixd()); - } - - // WoW display set up. - { - osg::Texture1D *textureHeader = new osg::Texture1D(); - // Set up the header - { - unsigned char header[]= {0xF1,wow_content,wow_factor,wow_offset,0x00,0x00,0x00,0x00,0x00,0x00}; - // Calc the CRC32 - { - unsigned long _register = 0; - for(int i = 0; i < 10; ++i) { - unsigned char mask = 0x80; - unsigned char byte = header[i]; - for (int j = 0; j < 8; ++j) - { - bool topBit = (_register & 0x80000000) != 0; - _register <<= 1; - _register ^= ((byte & mask) != 0? 0x1: 0x0); - if (topBit) - { - _register ^= 0x04c11db7; - } - mask >>= 1; - } - } - unsigned char *p = (unsigned char*) &_register; - for(size_t i = 0; i < 4; ++i) - { - header[i+6] = p[3-i]; - } - } - - osg::ref_ptr imageheader = new osg::Image(); - imageheader->allocateImage(256,1,1,GL_LUMINANCE,GL_UNSIGNED_BYTE); - { - unsigned char *cheader = imageheader->data(); - for (int x=0; x<256; ++x){ - cheader[x] = 0; - } - for (int x=0; x<=9; ++x){ - for (int y=7; y>=0; --y){ - int i = 2*(7-y)+16*x; - cheader[i] = (((1<<(y))&(header[x])) << (7-(y))); - } - } - } - textureHeader->setImage(imageheader.get()); - } - - // Create the Screen Aligned Quad - osg::Geode* geode = new osg::Geode(); - { - osg::Geometry* geom = new osg::Geometry; - - osg::Vec3Array* vertices = new osg::Vec3Array; - vertices->push_back(osg::Vec3(0,height,0)); - vertices->push_back(osg::Vec3(0,0,0)); - vertices->push_back(osg::Vec3(width,0,0)); - vertices->push_back(osg::Vec3(width,height,0)); - geom->setVertexArray(vertices); - - osg::Vec2Array* tex = new osg::Vec2Array; - tex->push_back(osg::Vec2(0,1)); - tex->push_back(osg::Vec2(0,0)); - tex->push_back(osg::Vec2(1,0)); - tex->push_back(osg::Vec2(1,1)); - geom->setTexCoordArray(0,tex); - - geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4)); - geode->addDrawable(geom); - - // new we need to add the textures to the quad, and setting up the shader. - osg::StateSet* stateset = geode->getOrCreateStateSet(); - stateset->setTextureAttributeAndModes(0, textureHeader,osg::StateAttribute::ON); - stateset->setTextureAttributeAndModes(1, texture,osg::StateAttribute::ON); - stateset->setTextureAttributeAndModes(2, textureD,osg::StateAttribute::ON); - stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); - - osg::ref_ptr programShader = new osg::Program(); - stateset->setAttribute(programShader.get(), osg::StateAttribute::ON); - stateset->addUniform( new osg::Uniform("wow_width", (int)width)); - stateset->addUniform( new osg::Uniform("wow_height", (int)height)); - stateset->addUniform( new osg::Uniform("wow_disparity_M", wow_disparity_M)); - stateset->addUniform( new osg::Uniform("wow_disparity_Zd", wow_disparity_Zd)); - stateset->addUniform( new osg::Uniform("wow_disparity_vz", wow_disparity_vz)); - stateset->addUniform( new osg::Uniform("wow_disparity_C", wow_disparity_C)); - - stateset->addUniform(new osg::Uniform("wow_header", 0)); - stateset->addUniform(new osg::Uniform("wow_tcolor", 1)); - stateset->addUniform(new osg::Uniform("wow_tdepth", 2)); - - osg::Shader *frag = new osg::Shader(osg::Shader::FRAGMENT); - frag->setShaderSource(" "\ - " uniform sampler1D wow_header; " \ - " uniform sampler2D wow_tcolor; " \ - " uniform sampler2D wow_tdepth; " \ - " " \ - " uniform int wow_width; " \ - " uniform int wow_height; " \ - " uniform float wow_disparity_M; " \ - " uniform float wow_disparity_Zd; " \ - " uniform float wow_disparity_vz; " \ - " uniform float wow_disparity_C; " \ - " " \ - " float disparity(float Z) " \ - " { " \ - " return (wow_disparity_M*(1.0-(wow_disparity_vz/(Z-wow_disparity_Zd+wow_disparity_vz))) " \ - " + wow_disparity_C) / 255.0; " \ - " } " \ - " " \ - " void main() " \ - " { " \ - " vec2 pos = (gl_FragCoord.xy / vec2(wow_width/2,wow_height) ); " \ - " if (gl_FragCoord.x > float(wow_width/2)) " \ - " { " \ - " gl_FragColor = vec4(disparity(( texture2D(wow_tdepth, pos - vec2(1,0))).z)); " \ - " } " \ - " else{ " \ - " gl_FragColor = texture2D(wow_tcolor, pos); " \ - " } " \ - " if ( (gl_FragCoord.y >= float(wow_height-1)) && (gl_FragCoord.x < 256.0) ) " \ - " { " \ - " float pos = gl_FragCoord.x/256.0; " \ - " float blue = texture1D(wow_header, pos).b; " \ - " if ( blue < 0.5) " \ - " gl_FragColor.b = 0.0; " \ - " else " \ - " gl_FragColor.b = 1.0; " \ - " } " \ - " } " ); - - programShader->addShader(frag); - } - - // Create the Camera - { - osg::ref_ptr camera = new osg::Camera; - camera->setGraphicsContext(gc.get()); - camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT ); - camera->setClearColor( osg::Vec4(0.0,0.0,0.0,1.0) ); - camera->setViewport(new osg::Viewport(0, 0, width, height)); - GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; - camera->setDrawBuffer(buffer); - camera->setReadBuffer(buffer); - camera->setReferenceFrame(osg::Camera::ABSOLUTE_RF); - camera->setAllowEventFocus(false); - camera->setInheritanceMask(camera->getInheritanceMask() & ~osg::CullSettings::CLEAR_COLOR & ~osg::CullSettings::COMPUTE_NEAR_FAR_MODE); - //camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR); - - camera->setProjectionMatrixAsOrtho2D(0,width,0,height); - camera->setViewMatrix(osg::Matrix::identity()); - - // add subgraph to render - camera->addChild(geode); - - camera->setName("WoWCamera"); - - addSlave(camera.get(), osg::Matrixd(), osg::Matrixd(), false); - } - } -} - -DepthPartitionSettings::DepthPartitionSettings(DepthMode mode): - _mode(mode), - _zNear(1.0), _zMid(5.0), _zFar(1000.0) -{} - -bool DepthPartitionSettings::getDepthRange(osg::View& view, unsigned int partition, double& zNear, double& zFar) -{ - switch(_mode) - { - case(FIXED_RANGE): - { - if (partition==0) - { - zNear = _zNear; - zFar = _zMid; - return true; - } - else if (partition==1) - { - zNear = _zMid; - zFar = _zFar; - return true; - } - return false; - } - case(BOUNDING_VOLUME): - { - osgViewer::View* view_withSceneData = dynamic_cast(&view); - const osg::Node* node = view_withSceneData ? view_withSceneData->getSceneData() : 0; - if (!node) return false; - - const osg::Camera* masterCamera = view.getCamera(); - if (!masterCamera) return false; - - osg::BoundingSphere bs = node->getBound(); - const osg::Matrixd& viewMatrix = masterCamera->getViewMatrix(); - //osg::Matrixd& projectionMatrix = masterCamera->getProjectionMatrix(); - - osg::Vec3d lookVectorInWorldCoords = osg::Matrixd::transform3x3(viewMatrix,osg::Vec3d(0.0,0.0,-1.0)); - lookVectorInWorldCoords.normalize(); - - osg::Vec3d nearPointInWorldCoords = bs.center() - lookVectorInWorldCoords*bs.radius(); - osg::Vec3d farPointInWorldCoords = bs.center() + lookVectorInWorldCoords*bs.radius(); - - osg::Vec3d nearPointInEyeCoords = nearPointInWorldCoords * viewMatrix; - osg::Vec3d farPointInEyeCoords = farPointInWorldCoords * viewMatrix; - -#if 0 - OSG_NOTICE<setNodeMask(0x0); - return; - } - else - { - camera->setNodeMask(0xffffff); - } - - if (camera->getProjectionMatrix()(0,3)==0.0 && - camera->getProjectionMatrix()(1,3)==0.0 && - camera->getProjectionMatrix()(2,3)==0.0) - { - double left, right, bottom, top, zNear, zFar; - camera->getProjectionMatrixAsOrtho(left, right, bottom, top, zNear, zFar); - camera->setProjectionMatrixAsOrtho(left, right, bottom, top, computed_zNear, computed_zFar); - } - else - { - double left, right, bottom, top, zNear, zFar; - camera->getProjectionMatrixAsFrustum(left, right, bottom, top, zNear, zFar); - - double nr = computed_zNear / zNear; - camera->setProjectionMatrixAsFrustum(left * nr, right * nr, bottom * nr, top * nr, computed_zNear, computed_zFar); - } - } - - osg::ref_ptr _dps; - unsigned int _partition; -}; - - -typedef std::list< osg::ref_ptr > Cameras; - -Cameras getActiveCameras(osg::View& view) -{ - Cameras activeCameras; - - if (view.getCamera() && view.getCamera()->getGraphicsContext()) - { - activeCameras.push_back(view.getCamera()); - } - - for(unsigned int i=0; igetGraphicsContext()) - { - activeCameras.push_back(slave._camera.get()); - } - } - return activeCameras; -} - -} - -bool View::setUpDepthPartitionForCamera(osg::Camera* cameraToPartition, DepthPartitionSettings* incomming_dps) -{ - osg::ref_ptr context = cameraToPartition->getGraphicsContext(); - if (!context) return false; - - osg::ref_ptr viewport = cameraToPartition->getViewport(); - if (!viewport) return false; - - osg::ref_ptr dps = incomming_dps; - if (!dps) dps = new DepthPartitionSettings; - - bool useMastersSceneData = true; - osg::Matrixd projectionOffset; - osg::Matrixd viewOffset; - - if (getCamera()==cameraToPartition) - { - // replace main camera with depth partition cameras - OSG_INFO<<"View::setUpDepthPartitionForCamera(..) Replacing main Camera"<=getNumSlaves()) return false; - - osg::View::Slave& slave = getSlave(i); - - useMastersSceneData = slave._useMastersSceneData; - projectionOffset = slave._projectionOffset; - viewOffset = slave._viewOffset; - - OSG_NOTICE<<"View::setUpDepthPartitionForCamera(..) Replacing slave Camera"<setGraphicsContext(0); - cameraToPartition->setViewport(0); - - // far camera - { - osg::ref_ptr camera = new osg::Camera; - camera->setGraphicsContext(context.get()); - camera->setViewport(viewport.get()); - - camera->setDrawBuffer(cameraToPartition->getDrawBuffer()); - camera->setReadBuffer(cameraToPartition->getReadBuffer()); - - camera->setComputeNearFarMode(osg::Camera::DO_NOT_COMPUTE_NEAR_FAR); - camera->setCullingMode(osg::Camera::ENABLE_ALL_CULLING); - - addSlave(camera.get()); - - osg::View::Slave& slave = getSlave(getNumSlaves()-1); - - slave._useMastersSceneData = useMastersSceneData; - slave._projectionOffset = projectionOffset; - slave._viewOffset = viewOffset; - slave._updateSlaveCallback = new osgDepthPartition::MyUpdateSlaveCallback(dps.get(), 1); - } - - // near camera - { - osg::ref_ptr camera = new osg::Camera; - camera->setGraphicsContext(context.get()); - camera->setViewport(viewport.get()); - - camera->setDrawBuffer(cameraToPartition->getDrawBuffer()); - camera->setReadBuffer(cameraToPartition->getReadBuffer()); - - camera->setComputeNearFarMode(osg::Camera::DO_NOT_COMPUTE_NEAR_FAR); - camera->setCullingMode(osg::Camera::ENABLE_ALL_CULLING); - camera->setClearMask(GL_DEPTH_BUFFER_BIT); - - addSlave(camera.get()); - - osg::View::Slave& slave = getSlave(getNumSlaves()-1); - slave._useMastersSceneData = useMastersSceneData; - slave._projectionOffset = projectionOffset; - slave._viewOffset = viewOffset; - slave._updateSlaveCallback = new osgDepthPartition::MyUpdateSlaveCallback(dps.get(), 0); - } - - return true; -} - - - -bool View::setUpDepthPartition(DepthPartitionSettings* dsp) -{ - osgDepthPartition::Cameras originalCameras = osgDepthPartition::getActiveCameras(*this); - if (originalCameras.empty()) - { - OSG_INFO<<"osgView::View::setUpDepthPartition(,..), no windows assigned, doing view.setUpViewAcrossAllScreens()"<areThreadsRunning(); - if (threadsWereRunning) getViewerBase()->stopThreading(); - - for(osgDepthPartition::Cameras::iterator itr = originalCameras.begin(); - itr != originalCameras.end(); - ++itr) - { - setUpDepthPartitionForCamera(itr->get(), dsp); - } - - if (threadsWereRunning) getViewerBase()->startThreading(); - - return true; -} - - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// -// Methods that support Stereo and Keystone correction. -// -osg::Texture* View::createDistortionTexture(int width, int height) -{ - osg::ref_ptr texture = new osg::TextureRectangle; - - texture->setTextureSize(width, height); - texture->setInternalFormat(GL_RGB); - texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); - texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); - texture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE); - texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE); - - return texture.release(); -} - -osg::Camera* View::assignRenderToTextureCamera(osg::GraphicsContext* gc, int width, int height, osg::Texture* texture) -{ - osg::ref_ptr camera = new osg::Camera; - camera->setName("Render to texture camera"); - camera->setGraphicsContext(gc); - camera->setViewport(new osg::Viewport(0,0,width, height)); - camera->setDrawBuffer(GL_FRONT); - camera->setReadBuffer(GL_FRONT); - camera->setAllowEventFocus(false); - camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT); - - // attach the texture and use it as the color buffer. - camera->attach(osg::Camera::COLOR_BUFFER, texture); - - addSlave(camera.get(), osg::Matrixd(), osg::Matrixd()); - - return camera.release(); -} - -osg::Camera* View::assignKeystoneDistortionCamera(osg::DisplaySettings* ds, osg::GraphicsContext* gc, int x, int y, int width, int height, GLenum buffer, osg::Texture* texture, Keystone* keystone) -{ - double screenDistance = ds->getScreenDistance(); - double screenWidth = ds->getScreenWidth(); - double screenHeight = ds->getScreenHeight(); - double fovy = osg::RadiansToDegrees(2.0*atan2(screenHeight/2.0,screenDistance)); - double aspectRatio = screenWidth/screenHeight; - - osg::Geode* geode = keystone->createKeystoneDistortionMesh(); - - // new we need to add the texture to the mesh, we do so by creating a - // StateSet to contain the Texture StateAttribute. - osg::StateSet* stateset = geode->getOrCreateStateSet(); - stateset->setTextureAttributeAndModes(0, texture,osg::StateAttribute::ON); - stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); - - osg::TexMat* texmat = new osg::TexMat; - texmat->setScaleByTextureRectangleSize(true); - stateset->setTextureAttributeAndModes(0, texmat, osg::StateAttribute::ON); - - osg::ref_ptr camera = new osg::Camera; - camera->setGraphicsContext(gc); - camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT ); - camera->setClearColor( osg::Vec4(0.0,0.0,0.0,1.0) ); - camera->setViewport(new osg::Viewport(x, y, width, height)); - camera->setDrawBuffer(buffer); - camera->setReadBuffer(buffer); - camera->setReferenceFrame(osg::Camera::ABSOLUTE_RF); - camera->setInheritanceMask(camera->getInheritanceMask() & ~osg::CullSettings::CLEAR_COLOR & ~osg::CullSettings::COMPUTE_NEAR_FAR_MODE); - //camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR); - - camera->setViewMatrix(osg::Matrix::identity()); - camera->setProjectionMatrixAsPerspective(fovy, aspectRatio, 0.1, 1000.0); - - // add subgraph to render - camera->addChild(geode); - - camera->addChild(keystone->createGrid()); - - camera->setName("DistortionCorrectionCamera"); - - // camera->addEventCallback(new KeystoneHandler(keystone)); - - addSlave(camera.get(), osg::Matrixd(), osg::Matrixd(), false); - - return camera.release(); -} - - - -void View::StereoSlaveCallback::updateSlave(osg::View& view, osg::View::Slave& slave) -{ - osg::Camera* camera = slave._camera.get(); - osgViewer::View* viewer_view = dynamic_cast(&view); - - if (_ds.valid() && camera && viewer_view) - { - - // set projection matrix - if (_eyeScale<0.0) - { - camera->setProjectionMatrix(_ds->computeLeftEyeProjectionImplementation(view.getCamera()->getProjectionMatrix())); - } - else - { - camera->setProjectionMatrix(_ds->computeRightEyeProjectionImplementation(view.getCamera()->getProjectionMatrix())); - } - - double sd = _ds->getScreenDistance(); - double fusionDistance = sd; - switch(viewer_view->getFusionDistanceMode()) - { - case(osgUtil::SceneView::USE_FUSION_DISTANCE_VALUE): - fusionDistance = viewer_view->getFusionDistanceValue(); - break; - case(osgUtil::SceneView::PROPORTIONAL_TO_SCREEN_DISTANCE): - fusionDistance *= viewer_view->getFusionDistanceValue(); - break; - } - double eyeScale = osg::absolute(_eyeScale) * (fusionDistance/sd); - - if (_eyeScale<0.0) - { - camera->setViewMatrix(_ds->computeLeftEyeViewImplementation(view.getCamera()->getViewMatrix(), eyeScale)); - } - else - { - camera->setViewMatrix(_ds->computeRightEyeViewImplementation(view.getCamera()->getViewMatrix(), eyeScale)); - } - } - else - { - slave.updateSlaveImplementation(view); - } -} - -osg::Camera* View::assignStereoCamera(osg::DisplaySettings* ds, osg::GraphicsContext* gc, int x, int y, int width, int height, GLenum buffer, double eyeScale) -{ - osg::ref_ptr camera = new osg::Camera; - - camera->setGraphicsContext(gc); - camera->setViewport(new osg::Viewport(x,y, width, height)); - camera->setDrawBuffer(buffer); - camera->setReadBuffer(buffer); - - // add this slave camera to the viewer, with a shift left of the projection matrix - addSlave(camera.get(), osg::Matrixd::identity(), osg::Matrixd::identity()); - - // assign update callback to maintain the correct view and projection matrices - osg::View::Slave& slave = getSlave(getNumSlaves()-1); - slave._updateSlaveCallback = new StereoSlaveCallback(ds, eyeScale); - - return camera.release(); -} - -static const GLubyte patternVertEven[] = { - 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, - 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, - 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, - 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, - 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, - 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, - 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, - 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, - 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, - 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, - 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, - 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, - 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, - 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, - 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, - 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55}; - -static const GLubyte patternVertOdd[] = { - 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, - 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, - 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, - 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, - 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, - 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, - 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, - 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, - 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, - 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, - 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, - 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, - 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, - 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, - 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, - 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}; - -static const GLubyte patternHorzEven[] = { - 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, - 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, - 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, - 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, - 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, - 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, - 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, - 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, - 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, - 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, - 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, - 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, - 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, - 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, - 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, - 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00}; - -// 32 x 32 bit array every row is a horizontal line of pixels -// and the (bitwise) columns a vertical line -// The following is a checkerboard pattern -static const GLubyte patternCheckerboard[] = { - 0x55, 0x55, 0x55, 0x55, - 0xAA, 0xAA, 0xAA, 0xAA, - 0x55, 0x55, 0x55, 0x55, - 0xAA, 0xAA, 0xAA, 0xAA, - 0x55, 0x55, 0x55, 0x55, - 0xAA, 0xAA, 0xAA, 0xAA, - 0x55, 0x55, 0x55, 0x55, - 0xAA, 0xAA, 0xAA, 0xAA, - 0x55, 0x55, 0x55, 0x55, - 0xAA, 0xAA, 0xAA, 0xAA, - 0x55, 0x55, 0x55, 0x55, - 0xAA, 0xAA, 0xAA, 0xAA, - 0x55, 0x55, 0x55, 0x55, - 0xAA, 0xAA, 0xAA, 0xAA, - 0x55, 0x55, 0x55, 0x55, - 0xAA, 0xAA, 0xAA, 0xAA, - 0x55, 0x55, 0x55, 0x55, - 0xAA, 0xAA, 0xAA, 0xAA, - 0x55, 0x55, 0x55, 0x55, - 0xAA, 0xAA, 0xAA, 0xAA, - 0x55, 0x55, 0x55, 0x55, - 0xAA, 0xAA, 0xAA, 0xAA, - 0x55, 0x55, 0x55, 0x55, - 0xAA, 0xAA, 0xAA, 0xAA, - 0x55, 0x55, 0x55, 0x55, - 0xAA, 0xAA, 0xAA, 0xAA, - 0x55, 0x55, 0x55, 0x55, - 0xAA, 0xAA, 0xAA, 0xAA, - 0x55, 0x55, 0x55, 0x55, - 0xAA, 0xAA, 0xAA, 0xAA, - 0x55, 0x55, 0x55, 0x55, - 0xAA, 0xAA, 0xAA, 0xAA}; - - -void View::setUpViewForStereo() -{ - osg::DisplaySettings* ds = _displaySettings.valid() ? _displaySettings.get() : osg::DisplaySettings::instance().get(); - if (!ds->getStereo()) return; - - ds->setUseSceneViewForStereoHint(false); - - typedef std::vector< osg::ref_ptr > Keystones; - Keystones keystones; - if (ds->getKeystoneHint() && !ds->getKeystones().empty()) - { - for(osg::DisplaySettings::Objects::iterator itr = ds->getKeystones().begin(); - itr != ds->getKeystones().end(); - ++itr) - { - Keystone* keystone = dynamic_cast(itr->get()); - if (keystone) keystones.push_back(keystone); - } - } - - if (ds->getKeystoneHint()) - { - while(keystones.size()<2) keystones.push_back(new Keystone); - } - - - // set up view's main camera - { - double height = osg::DisplaySettings::instance()->getScreenHeight(); - double width = osg::DisplaySettings::instance()->getScreenWidth(); - double distance = osg::DisplaySettings::instance()->getScreenDistance(); - double vfov = osg::RadiansToDegrees(atan2(height/2.0f,distance)*2.0); - - getCamera()->setProjectionMatrixAsPerspective( vfov, width/height, 1.0f,10000.0f); - } - - - int screenNum = 0; - - osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); - if (!wsi) - { - OSG_NOTICE<<"Error, no WindowSystemInterface available, cannot create windows."<getNumScreens(si); - - osg::GraphicsContext::ScreenIdentifier si; - si.readDISPLAY(); - - // displayNum has not been set so reset it to 0. - if (si.displayNum<0) si.displayNum = 0; - - si.screenNum = screenNum; - - unsigned int width, height; - wsi->getScreenResolution(si, width, height); - -// width/=2; height/=2; - - osg::ref_ptr traits = new osg::GraphicsContext::Traits(ds); - traits->hostName = si.hostName; - traits->displayNum = si.displayNum; - traits->screenNum = si.screenNum; - traits->x = 0; - traits->y = 0; - traits->width = width; - traits->height = height; - traits->windowDecoration = false; - traits->doubleBuffer = true; - traits->sharedContext = 0; - - OSG_NOTICE<<"traits->stencil="<stencil< gc = osg::GraphicsContext::createGraphicsContext(traits.get()); - if (!gc) - { - OSG_NOTICE<<"GraphicsWindow has not been created successfully."<getStereoMode()) - { - case(osg::DisplaySettings::QUAD_BUFFER): - { - // left Camera left buffer - osg::ref_ptr left_camera = assignStereoCamera(ds, gc.get(), 0, 0, traits->width, traits->height, traits->doubleBuffer ? GL_BACK_LEFT : GL_FRONT_LEFT, -1.0); - left_camera->setClearMask(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); - left_camera->setRenderOrder(osg::Camera::NESTED_RENDER, 0); - - // right Camera right buffer - osg::ref_ptr right_camera = assignStereoCamera(ds, gc.get(), 0, 0, traits->width, traits->height, traits->doubleBuffer ? GL_BACK_RIGHT : GL_FRONT_RIGHT, 1.0); - right_camera->setClearMask(GL_DEPTH_BUFFER_BIT); - right_camera->setRenderOrder(osg::Camera::NESTED_RENDER, 1); - - // for keystone: - // left camera to render to left texture - // right camera to render to right texture - // left keystone camera to render to left buffer - // left keystone camera to render to right buffer - // one keystone and editing for the one window - - if (!keystones.empty()) - { - // for keystone: - // left camera to render to left texture using whole viewport of left texture - // right camera to render to right texture using whole viewport of right texture - // left keystone camera to render to left viewport/window - // right keystone camera to render to right viewport/window - // two keystone, one for each of the left and right viewports/windows - - osg::ref_ptr keystone = keystones.front(); - - // create distortion texture - osg::ref_ptr left_texture = createDistortionTexture(traits->width, traits->height); - - // convert to RTT Camera - left_camera->setViewport(0, 0, traits->width, traits->height); - left_camera->setDrawBuffer(GL_FRONT); - left_camera->setReadBuffer(GL_FRONT); - left_camera->setAllowEventFocus(true); - left_camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT); - - // attach the texture and use it as the color buffer. - left_camera->attach(osg::Camera::COLOR_BUFFER, left_texture.get()); - - - // create distortion texture - osg::ref_ptr right_texture = createDistortionTexture(traits->width, traits->height); - - // convert to RTT Camera - right_camera->setViewport(0, 0, traits->width, traits->height); - right_camera->setDrawBuffer(GL_FRONT); - right_camera->setReadBuffer(GL_FRONT); - right_camera->setAllowEventFocus(true); - right_camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT); - - // attach the texture and use it as the color buffer. - right_camera->attach(osg::Camera::COLOR_BUFFER, right_texture.get()); - - - // create Keystone left distortion camera - keystone->setGridColor(osg::Vec4(1.0f,0.0f,0.0,1.0)); - osg::ref_ptr left_keystone_camera = assignKeystoneDistortionCamera(ds, gc.get(), - 0, 0, traits->width, traits->height, - traits->doubleBuffer ? GL_BACK_LEFT : GL_FRONT_LEFT, - left_texture.get(), keystone.get()); - - left_keystone_camera->setRenderOrder(osg::Camera::NESTED_RENDER, 2); - - // attach Keystone editing event handler. - left_keystone_camera->addEventCallback(new KeystoneHandler(keystone.get())); - - - // create Keystone right distortion camera - osg::ref_ptr right_keystone_camera = assignKeystoneDistortionCamera(ds, gc.get(), - 0, 0, traits->width, traits->height, - traits->doubleBuffer ? GL_BACK_RIGHT : GL_FRONT_RIGHT, - right_texture.get(), keystone.get()); - - right_keystone_camera->setRenderOrder(osg::Camera::NESTED_RENDER, 3); - right_keystone_camera->setAllowEventFocus(false); - - } - - break; - } - case(osg::DisplaySettings::ANAGLYPHIC): - { - // left Camera red - osg::ref_ptr left_camera = assignStereoCamera(ds, gc.get(), 0, 0, traits->width, traits->height, traits->doubleBuffer ? GL_BACK : GL_FRONT, -1.0); - left_camera->setClearMask(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); - left_camera->getOrCreateStateSet()->setAttribute(new osg::ColorMask(true, false, false, true)); - left_camera->setRenderOrder(osg::Camera::NESTED_RENDER, 0); - - // right Camera cyan - osg::ref_ptr right_camera = assignStereoCamera(ds, gc.get(), 0, 0, traits->width, traits->height, traits->doubleBuffer ? GL_BACK : GL_FRONT, 1.0); - right_camera->setClearMask(GL_DEPTH_BUFFER_BIT); - right_camera->getOrCreateStateSet()->setAttribute(new osg::ColorMask(false, true, true, true)); - right_camera->setRenderOrder(osg::Camera::NESTED_RENDER, 1); - - if (!keystones.empty()) - { - // for keystone: - // left camera to render to texture using red colour mask - // right camera to render to same texture using cyan colour mask - // keystone camera to render to whole screen without colour masks - // one keystone and editing for the one window - - osg::ref_ptr keystone = keystones.front(); - - // create distortion texture - osg::ref_ptr texture = createDistortionTexture(traits->width, traits->height); - - // convert to RTT Camera - left_camera->setDrawBuffer(GL_FRONT); - left_camera->setReadBuffer(GL_FRONT); - left_camera->setAllowEventFocus(false); - right_camera->setRenderOrder(osg::Camera::NESTED_RENDER, 0); - left_camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT); - - // attach the texture and use it as the color buffer. - left_camera->attach(osg::Camera::COLOR_BUFFER, texture.get()); - - - // convert to RTT Camera - right_camera->setDrawBuffer(GL_FRONT); - right_camera->setReadBuffer(GL_FRONT); - right_camera->setAllowEventFocus(false); - right_camera->setRenderOrder(osg::Camera::NESTED_RENDER, 1); - right_camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT); - - // attach the texture and use it as the color buffer. - right_camera->attach(osg::Camera::COLOR_BUFFER, texture.get()); - - - // create Keystone distortion camera - osg::ref_ptr camera = assignKeystoneDistortionCamera(ds, gc.get(), - 0, 0, traits->width, traits->height, - traits->doubleBuffer ? GL_BACK : GL_FRONT, - texture.get(), keystone.get()); - - camera->setRenderOrder(osg::Camera::NESTED_RENDER, 2); - - // attach Keystone editing event handler. - camera->addEventCallback(new KeystoneHandler(keystone.get())); - } - - break; - } - case(osg::DisplaySettings::HORIZONTAL_SPLIT): - { - bool left_eye_left_viewport = ds->getSplitStereoHorizontalEyeMapping()==osg::DisplaySettings::LEFT_EYE_LEFT_VIEWPORT; - int left_start = (left_eye_left_viewport) ? 0 : traits->width/2; - int right_start = (left_eye_left_viewport) ? traits->width/2 : 0; - - // left viewport Camera - osg::ref_ptr left_camera = assignStereoCamera(ds, gc.get(), - left_start, 0, traits->width/2, traits->height, traits->doubleBuffer ? GL_BACK : GL_FRONT, - 1.0); - - // right viewport Camera - osg::ref_ptr right_camera = assignStereoCamera(ds, gc.get(), - right_start, 0, traits->width/2, traits->height, traits->doubleBuffer ? GL_BACK : GL_FRONT, - 1.0); - - if (!keystones.empty()) - { - // for keystone: - // left camera to render to left texture using whole viewport of left texture - // right camera to render to right texture using whole viewport of right texture - // left keystone camera to render to left viewport/window - // right keystone camera to render to right viewport/window - // two keystone, one for each of the left and right viewports/windows - - osg::ref_ptr left_keystone = keystones[0]; - osg::ref_ptr right_keystone = keystones[1]; - - // create distortion texture - osg::ref_ptr left_texture = createDistortionTexture(traits->width/2, traits->height); - - // convert to RTT Camera - left_camera->setViewport(0, 0, traits->width/2, traits->height); - left_camera->setDrawBuffer(GL_FRONT); - left_camera->setReadBuffer(GL_FRONT); - left_camera->setAllowEventFocus(true); - left_camera->setRenderOrder(osg::Camera::NESTED_RENDER, 0); - left_camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT); - - // attach the texture and use it as the color buffer. - left_camera->attach(osg::Camera::COLOR_BUFFER, left_texture.get()); - - - // create distortion texture - osg::ref_ptr right_texture = createDistortionTexture(traits->width/2, traits->height); - - // convert to RTT Camera - right_camera->setViewport(0, 0, traits->width/2, traits->height); - right_camera->setDrawBuffer(GL_FRONT); - right_camera->setReadBuffer(GL_FRONT); - right_camera->setAllowEventFocus(true); - right_camera->setRenderOrder(osg::Camera::NESTED_RENDER, 1); - right_camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT); - - // attach the texture and use it as the color buffer. - right_camera->attach(osg::Camera::COLOR_BUFFER, right_texture.get()); - - - // create Keystone left distortion camera - left_keystone->setGridColor(osg::Vec4(1.0f,0.0f,0.0,1.0)); - osg::ref_ptr left_keystone_camera = assignKeystoneDistortionCamera(ds, gc.get(), - left_start, 0, traits->width/2, traits->height, - traits->doubleBuffer ? GL_BACK : GL_FRONT, - left_texture.get(), left_keystone.get()); - - left_keystone_camera->setRenderOrder(osg::Camera::NESTED_RENDER, 2); - - // attach Keystone editing event handler. - left_keystone_camera->addEventCallback(new KeystoneHandler(left_keystone.get())); - - - // create Keystone right distortion camera - right_keystone->setGridColor(osg::Vec4(0.0f,1.0f,0.0,1.0)); - osg::ref_ptr right_keystone_camera = assignKeystoneDistortionCamera(ds, gc.get(), - right_start, 0, traits->width/2, traits->height, - traits->doubleBuffer ? GL_BACK : GL_FRONT, - right_texture.get(), right_keystone.get()); - - right_keystone_camera->setRenderOrder(osg::Camera::NESTED_RENDER, 3); - - // attach Keystone editing event handler. - right_keystone_camera->addEventCallback(new KeystoneHandler(right_keystone.get())); - - getCamera()->setAllowEventFocus(false); - - } - - break; - } - case(osg::DisplaySettings::VERTICAL_SPLIT): - { - bool left_eye_bottom_viewport = ds->getSplitStereoVerticalEyeMapping()==osg::DisplaySettings::LEFT_EYE_BOTTOM_VIEWPORT; - int left_start = (left_eye_bottom_viewport) ? 0 : traits->height/2; - int right_start = (left_eye_bottom_viewport) ? traits->height/2 : 0; - - // bottom viewport Camera - osg::ref_ptr left_camera = assignStereoCamera(ds, gc.get(), - 0, left_start, traits->width, traits->height/2, traits->doubleBuffer ? GL_BACK : GL_FRONT, - 1.0); - - // top vieport camera - osg::ref_ptr right_camera = assignStereoCamera(ds, gc.get(), - 0, right_start, traits->width, traits->height/2, traits->doubleBuffer ? GL_BACK : GL_FRONT, - 1.0); - - // for keystone: - // left camera to render to left texture using whole viewport of left texture - // right camera to render to right texture using whole viewport of right texture - // left keystone camera to render to left viewport/window - // right keystone camera to render to right viewport/window - // two keystone, one for each of the left and right viewports/windows - - if (!keystones.empty()) - { - // for keystone: - // left camera to render to left texture using whole viewport of left texture - // right camera to render to right texture using whole viewport of right texture - // left keystone camera to render to left viewport/window - // right keystone camera to render to right viewport/window - // two keystone, one for each of the left and right viewports/windows - - osg::ref_ptr left_keystone = keystones[0]; - osg::ref_ptr right_keystone = keystones[1]; - - // create distortion texture - osg::ref_ptr left_texture = createDistortionTexture(traits->width, traits->height/2); - - // convert to RTT Camera - left_camera->setViewport(0, 0, traits->width, traits->height/2); - left_camera->setDrawBuffer(GL_FRONT); - left_camera->setReadBuffer(GL_FRONT); - left_camera->setAllowEventFocus(true); - left_camera->setRenderOrder(osg::Camera::NESTED_RENDER, 0); - left_camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT); - - // attach the texture and use it as the color buffer. - left_camera->attach(osg::Camera::COLOR_BUFFER, left_texture.get()); - - - // create distortion texture - osg::ref_ptr right_texture = createDistortionTexture(traits->width, traits->height/2); - - // convert to RTT Camera - right_camera->setViewport(0, 0, traits->width, traits->height/2); - right_camera->setDrawBuffer(GL_FRONT); - right_camera->setReadBuffer(GL_FRONT); - right_camera->setAllowEventFocus(true); - right_camera->setRenderOrder(osg::Camera::NESTED_RENDER, 1); - right_camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT); - - // attach the texture and use it as the color buffer. - right_camera->attach(osg::Camera::COLOR_BUFFER, right_texture.get()); - - - // create Keystone left distortion camera - left_keystone->setGridColor(osg::Vec4(1.0f,0.0f,0.0,1.0)); - osg::ref_ptr left_keystone_camera = assignKeystoneDistortionCamera(ds, gc.get(), - 0, left_start, traits->width, traits->height/2, - traits->doubleBuffer ? GL_BACK : GL_FRONT, - left_texture.get(), left_keystone.get()); - - left_keystone_camera->setRenderOrder(osg::Camera::NESTED_RENDER, 2); - - // attach Keystone editing event handler. - left_keystone_camera->addEventCallback(new KeystoneHandler(left_keystone.get())); - - - // create Keystone right distortion camera - right_keystone->setGridColor(osg::Vec4(0.0f,1.0f,0.0,1.0)); - osg::ref_ptr right_keystone_camera = assignKeystoneDistortionCamera(ds, gc.get(), - 0, right_start, traits->width, traits->height/2, - traits->doubleBuffer ? GL_BACK : GL_FRONT, - right_texture.get(), right_keystone.get()); - - right_keystone_camera->setRenderOrder(osg::Camera::NESTED_RENDER, 3); - - // attach Keystone editing event handler. - right_keystone_camera->addEventCallback(new KeystoneHandler(right_keystone.get())); - - getCamera()->setAllowEventFocus(false); - - } - - break; - } - case(osg::DisplaySettings::LEFT_EYE): - { - // single window, whole window, just left eye offsets - osg::ref_ptr left_camera = assignStereoCamera(ds, gc.get(), 0, 0, traits->width, traits->height, traits->doubleBuffer ? GL_BACK : GL_FRONT, -1.0); - - // for keystone: - // treat as standard keystone correction. - // left eye camera to render to texture - // keystone camera then render to window - // one keystone and editing for window - - if (!keystones.empty()) - { - // for keystone: - // left camera to render to texture using red colour mask - // right camera to render to same texture using cyan colour mask - // keystone camera to render to whole screen without colour masks - // one keystone and editing for the one window - - osg::ref_ptr keystone = keystones.front(); - - // create distortion texture - osg::ref_ptr texture = createDistortionTexture(traits->width, traits->height); - - // convert to RTT Camera - left_camera->setDrawBuffer(GL_FRONT); - left_camera->setReadBuffer(GL_FRONT); - left_camera->setAllowEventFocus(false); - left_camera->setRenderOrder(osg::Camera::NESTED_RENDER, 0); - left_camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT); - - // attach the texture and use it as the color buffer. - left_camera->attach(osg::Camera::COLOR_BUFFER, texture.get()); - - - // create Keystone distortion camera - osg::ref_ptr camera = assignKeystoneDistortionCamera(ds, gc.get(), - 0, 0, traits->width, traits->height, - traits->doubleBuffer ? GL_BACK : GL_FRONT, - texture.get(), keystone.get()); - - camera->setRenderOrder(osg::Camera::NESTED_RENDER, 2); - - // attach Keystone editing event handler. - camera->addEventCallback(new KeystoneHandler(keystone.get())); - } - break; - } - case(osg::DisplaySettings::RIGHT_EYE): - { - // single window, whole window, just right eye offsets - osg::ref_ptr right_camera = assignStereoCamera(ds, gc.get(), 0, 0, traits->width, traits->height, traits->doubleBuffer ? GL_BACK : GL_FRONT, 1.0); - - // for keystone: - // treat as standard keystone correction. - // left eye camera to render to texture - // keystone camera then render to window - // one keystone and editing for window - - if (!keystones.empty()) - { - // for keystone: - // left camera to render to texture using red colour mask - // right camera to render to same texture using cyan colour mask - // keystone camera to render to whole screen without colour masks - // one keystone and editing for the one window - - osg::ref_ptr keystone = keystones.front(); - - // create distortion texture - osg::ref_ptr texture = createDistortionTexture(traits->width, traits->height); - - // convert to RTT Camera - right_camera->setDrawBuffer(GL_FRONT); - right_camera->setReadBuffer(GL_FRONT); - right_camera->setAllowEventFocus(false); - right_camera->setRenderOrder(osg::Camera::NESTED_RENDER, 0); - right_camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT); - - // attach the texture and use it as the color buffer. - right_camera->attach(osg::Camera::COLOR_BUFFER, texture.get()); - - // create Keystone distortion camera - osg::ref_ptr camera = assignKeystoneDistortionCamera(ds, gc.get(), - 0, 0, traits->width, traits->height, - traits->doubleBuffer ? GL_BACK : GL_FRONT, - texture.get(), keystone.get()); - - camera->setRenderOrder(osg::Camera::NESTED_RENDER, 1); - - // attach Keystone editing event handler. - camera->addEventCallback(new KeystoneHandler(keystone.get())); - } - break; - } - case(osg::DisplaySettings::HORIZONTAL_INTERLACE): - case(osg::DisplaySettings::VERTICAL_INTERLACE): - case(osg::DisplaySettings::CHECKERBOARD): - { - // set up the stencil buffer - { - osg::ref_ptr camera = new osg::Camera; - camera->setGraphicsContext(gc.get()); - camera->setViewport(0, 0, traits->width, traits->height); - camera->setDrawBuffer(traits->doubleBuffer ? GL_BACK : GL_FRONT); - camera->setReadBuffer(camera->getDrawBuffer()); - camera->setReferenceFrame(osg::Camera::ABSOLUTE_RF); - camera->setClearMask(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT); - camera->setClearStencil(0); - camera->setRenderOrder(osg::Camera::NESTED_RENDER, 0); - addSlave(camera.get(), false); - - osg::ref_ptr geometry = osg::createTexturedQuadGeometry(osg::Vec3(-1.0f,-1.0f,0.0f), osg::Vec3(2.0f,0.0f,0.0f), osg::Vec3(0.0f,2.0f,0.0f), 0.0f, 0.0f, 1.0f, 1.0f); - osg::ref_ptr geode = new osg::Geode; - geode->addDrawable(geometry.get()); - camera->addChild(geode.get()); - - geode->setCullingActive(false); - - osg::ref_ptr stateset = geode->getOrCreateStateSet(); - - // set up stencil - osg::ref_ptr stencil = new osg::Stencil; - stencil->setFunction(osg::Stencil::ALWAYS, 1, ~0u); - stencil->setOperation(osg::Stencil::REPLACE, osg::Stencil::REPLACE, osg::Stencil::REPLACE); - stencil->setWriteMask(~0u); - stateset->setAttributeAndModes(stencil.get(), osg::StateAttribute::ON); - - // set up polygon stipple - if(ds->getStereoMode() == osg::DisplaySettings::VERTICAL_INTERLACE) - { - stateset->setAttributeAndModes(new osg::PolygonStipple(patternVertEven), osg::StateAttribute::ON); - } - else if(ds->getStereoMode() == osg::DisplaySettings::HORIZONTAL_INTERLACE) - { - stateset->setAttributeAndModes(new osg::PolygonStipple(patternHorzEven), osg::StateAttribute::ON); - } - else - { - stateset->setAttributeAndModes(new osg::PolygonStipple(patternCheckerboard), osg::StateAttribute::ON); - } - - stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF); - stateset->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF); - - } - - // left Camera - { - osg::ref_ptr camera = assignStereoCamera(ds, gc.get(), 0, 0, traits->width, traits->height, traits->doubleBuffer ? GL_BACK : GL_FRONT, -1.0); - camera->setClearMask(0); - camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); - camera->setRenderOrder(osg::Camera::NESTED_RENDER, 1); - - osg::ref_ptr stencil = new osg::Stencil; - stencil->setFunction(osg::Stencil::EQUAL, 0, ~0u); - stencil->setOperation(osg::Stencil::KEEP, osg::Stencil::KEEP, osg::Stencil::KEEP); - camera->getOrCreateStateSet()->setAttributeAndModes(stencil.get(), osg::StateAttribute::ON); - } - - // right Camera - { - osg::ref_ptr camera = assignStereoCamera(ds, gc.get(), 0, 0, traits->width, traits->height, traits->doubleBuffer ? GL_BACK : GL_FRONT, 1.0); - camera->setClearMask(GL_DEPTH_BUFFER_BIT); - camera->setRenderOrder(osg::Camera::NESTED_RENDER, 2); - - osg::ref_ptr stencil = new osg::Stencil; - stencil->setFunction(osg::Stencil::NOTEQUAL, 0, ~0u); - stencil->setOperation(osg::Stencil::KEEP, osg::Stencil::KEEP, osg::Stencil::KEEP); - camera->getOrCreateStateSet()->setAttributeAndModes(stencil.get(), osg::StateAttribute::ON); - } - break; - } - } -} - - -void View::setUpViewForKeystone(Keystone* keystone) -{ - int screenNum = 0; - - osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); - if (!wsi) - { - OSG_NOTICE<<"Error, no WindowSystemInterface available, cannot create windows."<getScreenResolution(si, width, height); - -// width/=2; height/=2; - - osg::ref_ptr traits = new osg::GraphicsContext::Traits; - traits->hostName = si.hostName; - traits->displayNum = si.displayNum; - traits->screenNum = si.screenNum; - traits->x = 0; - traits->y = 0; - traits->width = width; - traits->height = height; - traits->windowDecoration = false; - traits->doubleBuffer = true; - traits->sharedContext = 0; - - - osg::ref_ptr gc = osg::GraphicsContext::createGraphicsContext(traits.get()); - if (!gc) - { - OSG_NOTICE<<"GraphicsWindow has not been created successfully."< texture = createDistortionTexture(width, height); - - // create RTT Camera - assignRenderToTextureCamera(gc.get(), width, height, texture.get()); - - // create Keystone distortion camera - osg::ref_ptr camera = assignKeystoneDistortionCamera(ds, gc.get(), - 0, 0, width, height, - traits->doubleBuffer ? GL_BACK : GL_FRONT, - texture.get(), keystone); - // attach Keystone editing event handler. - camera->addEventCallback(new KeystoneHandler(keystone)); - -} - -#endif \ No newline at end of file diff --git a/src/osgViewer/View.cpp b/src/osgViewer/View.cpp index 0f226ad97..64daebfce 100644 --- a/src/osgViewer/View.cpp +++ b/src/osgViewer/View.cpp @@ -32,10 +32,24 @@ #include #include +// view configurations. +#include +#include +#include +#include +#include +#include + + #include using namespace osgViewer; +osg::DisplaySettings* ViewConfig::getActiveDisplaySetting(osgViewer::View& view) const +{ + return view.getDisplaySettings() ? view.getDisplaySettings() : osg::DisplaySettings::instance().get(); +} + class CollectedCoordinateSystemNodesVisitor : public osg::NodeVisitor { public: @@ -433,1175 +447,45 @@ void View::computeActiveCoordinateSystemNodePath() setCoordinateSystemNodePath(osg::NodePath()); } + +void View::apply(ViewConfig* config) +{ + if (config) + { + OSG_NOTICE<<"Applying osgViewer::ViewConfig : "<className()<configure(*this); + } + _lastAppliedViewConfig = config; +} + void View::setUpViewAcrossAllScreens() { - osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); - if (!wsi) - { - OSG_NOTICE<<"View::setUpViewAcrossAllScreens() : Error, no WindowSystemInterface available, cannot create windows."<getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar); - - osg::GraphicsContext::ScreenIdentifier si; - si.readDISPLAY(); - - // displayNum has not been set so reset it to 0. - if (si.displayNum<0) si.displayNum = 0; - - unsigned int numScreens = wsi->getNumScreens(si); - if (numScreens==1) - { - if (si.screenNum<0) si.screenNum = 0; - - unsigned int width, height; - wsi->getScreenResolution(si, width, height); - - osg::ref_ptr traits = new osg::GraphicsContext::Traits(ds); - traits->hostName = si.hostName; - traits->displayNum = si.displayNum; - traits->screenNum = si.screenNum; - traits->x = 0; - traits->y = 0; - traits->width = width; - traits->height = height; - traits->windowDecoration = false; - traits->doubleBuffer = true; - traits->sharedContext = 0; - - osg::ref_ptr gc = osg::GraphicsContext::createGraphicsContext(traits.get()); - - _camera->setGraphicsContext(gc.get()); - - osgViewer::GraphicsWindow* gw = dynamic_cast(gc.get()); - if (gw) - { - OSG_INFO<<" GraphicsWindow has been created successfully."<getEventQueue()->getCurrentEventState()->setWindowRectangle(0, 0, width, height ); - } - else - { - OSG_NOTICE<<" GraphicsWindow has not been created successfully."<width) / double(traits->height); - double aspectRatioChange = newAspectRatio / aspectRatio; - if (aspectRatioChange != 1.0) - { - _camera->getProjectionMatrix() *= osg::Matrix::scale(1.0/aspectRatioChange,1.0,1.0); - } - - _camera->setViewport(new osg::Viewport(0, 0, traits->width, traits->height)); - - GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; - - _camera->setDrawBuffer(buffer); - _camera->setReadBuffer(buffer); - - } - else - { - - double translate_x = 0.0; - - for(unsigned int i=0; igetScreenResolution(si, width, height); - translate_x += double(width) / (double(height) * aspectRatio); - } - - bool stereoSplitScreens = numScreens==2 && - ds->getStereoMode()==osg::DisplaySettings::HORIZONTAL_SPLIT && - ds->getStereo(); - - for(unsigned int i=0; igetScreenResolution(si, width, height); - - osg::ref_ptr traits = new osg::GraphicsContext::Traits(ds); - traits->hostName = si.hostName; - traits->displayNum = si.displayNum; - traits->screenNum = si.screenNum; - traits->screenNum = i; - traits->x = 0; - traits->y = 0; - traits->width = width; - traits->height = height; - traits->windowDecoration = false; - traits->doubleBuffer = true; - traits->sharedContext = 0; - - osg::ref_ptr gc = osg::GraphicsContext::createGraphicsContext(traits.get()); - - osg::ref_ptr camera = new osg::Camera; - camera->setGraphicsContext(gc.get()); - - osgViewer::GraphicsWindow* gw = dynamic_cast(gc.get()); - if (gw) - { - OSG_INFO<<" GraphicsWindow has been created successfully."<getEventQueue()->getCurrentEventState()->setWindowRectangle(traits->x, traits->y, traits->width, traits->height ); - } - else - { - OSG_NOTICE<<" GraphicsWindow has not been created successfully."<setViewport(new osg::Viewport(0, 0, traits->width, traits->height)); - - GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; - camera->setDrawBuffer(buffer); - camera->setReadBuffer(buffer); - - if (stereoSplitScreens) - { - unsigned int leftCameraNum = (ds->getSplitStereoHorizontalEyeMapping()==osg::DisplaySettings::LEFT_EYE_LEFT_VIEWPORT) ? 0 : 1; - - osg::ref_ptr ds_local = new osg::DisplaySettings(*ds); - ds_local->setStereoMode(leftCameraNum==i ? osg::DisplaySettings::LEFT_EYE : osg::DisplaySettings::RIGHT_EYE); - camera->setDisplaySettings(ds_local.get()); - - addSlave(camera.get(), osg::Matrixd(), osg::Matrixd() ); - } - else - { - double newAspectRatio = double(traits->width) / double(traits->height); - double aspectRatioChange = newAspectRatio / aspectRatio; - - addSlave(camera.get(), osg::Matrixd::translate( translate_x - aspectRatioChange, 0.0, 0.0) * osg::Matrix::scale(1.0/aspectRatioChange,1.0,1.0), osg::Matrixd() ); - translate_x -= aspectRatioChange * 2.0; - } - } - } - - assignSceneDataToCameras(); + apply(new osgViewer::AcrossAllScreens()); } void View::setUpViewInWindow(int x, int y, int width, int height, unsigned int screenNum) { - osg::DisplaySettings* ds = _displaySettings.valid() ? _displaySettings.get() : osg::DisplaySettings::instance().get(); - - osg::ref_ptr traits = new osg::GraphicsContext::Traits(ds); - - traits->readDISPLAY(); - if (traits->displayNum<0) traits->displayNum = 0; - - traits->screenNum = screenNum; - traits->x = x; - traits->y = y; - traits->width = width; - traits->height = height; - traits->windowDecoration = true; - traits->doubleBuffer = true; - traits->sharedContext = 0; - - osg::ref_ptr gc = osg::GraphicsContext::createGraphicsContext(traits.get()); - - _camera->setGraphicsContext(gc.get()); - - osgViewer::GraphicsWindow* gw = dynamic_cast(gc.get()); - if (gw) - { - OSG_INFO<<"View::setUpViewOnSingleScreen - GraphicsWindow has been created successfully."<getEventQueue()->getCurrentEventState()->setWindowRectangle(x, y, width, height ); - } - else - { - OSG_NOTICE<<" GraphicsWindow has not been created successfully."<getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar); - - double newAspectRatio = double(traits->width) / double(traits->height); - double aspectRatioChange = newAspectRatio / aspectRatio; - if (aspectRatioChange != 1.0) - { - _camera->getProjectionMatrix() *= osg::Matrix::scale(1.0/aspectRatioChange,1.0,1.0); - } - - _camera->setViewport(new osg::Viewport(0, 0, traits->width, traits->height)); - - GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; - - _camera->setDrawBuffer(buffer); - _camera->setReadBuffer(buffer); + apply(new osgViewer::SingleWindow(x,y,width,screenNum)); } void View::setUpViewOnSingleScreen(unsigned int screenNum) { - osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); - if (!wsi) - { - OSG_NOTICE<<"View::setUpViewOnSingleScreen() : Error, no WindowSystemInterface available, cannot create windows."<getScreenResolution(si, width, height); - - osg::ref_ptr traits = new osg::GraphicsContext::Traits(ds); - traits->hostName = si.hostName; - traits->displayNum = si.displayNum; - traits->screenNum = si.screenNum; - traits->x = 0; - traits->y = 0; - traits->width = width; - traits->height = height; - traits->windowDecoration = false; - traits->doubleBuffer = true; - traits->sharedContext = 0; - - osg::ref_ptr gc = osg::GraphicsContext::createGraphicsContext(traits.get()); - - _camera->setGraphicsContext(gc.get()); - - osgViewer::GraphicsWindow* gw = dynamic_cast(gc.get()); - if (gw) - { - OSG_INFO<<"View::setUpViewOnSingleScreen - GraphicsWindow has been created successfully."<getEventQueue()->getCurrentEventState()->setWindowRectangle(0, 0, width, height ); - } - else - { - OSG_NOTICE<<" GraphicsWindow has not been created successfully."<getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar); - - double newAspectRatio = double(traits->width) / double(traits->height); - double aspectRatioChange = newAspectRatio / aspectRatio; - if (aspectRatioChange != 1.0) - { - _camera->getProjectionMatrix() *= osg::Matrix::scale(1.0/aspectRatioChange,1.0,1.0); - } - - _camera->setViewport(new osg::Viewport(0, 0, traits->width, traits->height)); - - GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; - - _camera->setDrawBuffer(buffer); - _camera->setReadBuffer(buffer); -} - -static osg::Geometry* create3DSphericalDisplayDistortionMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector, double sphere_radius, double collar_radius,osg::Image* intensityMap, const osg::Matrix& projectorMatrix) -{ - osg::Vec3d center(0.0,0.0,0.0); - osg::Vec3d eye(0.0,0.0,0.0); - - double distance = sqrt(sphere_radius*sphere_radius - collar_radius*collar_radius); - - bool centerProjection = false; - - osg::Vec3d projector = eye - osg::Vec3d(0.0,0.0, distance); - - OSG_INFO<<"create3DSphericalDisplayDistortionMesh : Projector position = "<getScreenResolution(si, width, height); - - - osg::ref_ptr traits = new osg::GraphicsContext::Traits; - traits->hostName = si.hostName; - traits->displayNum = si.displayNum; - traits->screenNum = si.screenNum; - traits->x = 0; - traits->y = 0; - traits->width = width; - traits->height = height; - traits->windowDecoration = false; - traits->doubleBuffer = true; - traits->sharedContext = 0; - - - osg::ref_ptr gc = osg::GraphicsContext::createGraphicsContext(traits.get()); - if (!gc) - { - OSG_NOTICE<<"GraphicsWindow has not been created successfully."<setTextureSize(tex_width, tex_height); - texture->setInternalFormat(GL_RGB); - texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); - texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); - texture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE); - texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE); - texture->setWrap(osg::Texture::WRAP_R,osg::Texture::CLAMP_TO_EDGE); - -#if 0 - osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::SEPERATE_WINDOW; - GLenum buffer = GL_FRONT; -#else - osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::FRAME_BUFFER_OBJECT; - GLenum buffer = GL_FRONT; -#endif - - // front face - { - osg::ref_ptr camera = new osg::Camera; - camera->setName("Front face camera"); - camera->setGraphicsContext(gc.get()); - camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height)); - camera->setDrawBuffer(buffer); - camera->setReadBuffer(buffer); - camera->setAllowEventFocus(false); - // tell the camera to use OpenGL frame buffer object where supported. - camera->setRenderTargetImplementation(renderTargetImplementation); - - // attach the texture and use it as the color buffer. - camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::POSITIVE_Y); - - addSlave(camera.get(), osg::Matrixd(), osg::Matrixd()); - } - - - // top face - { - osg::ref_ptr camera = new osg::Camera; - camera->setName("Top face camera"); - camera->setGraphicsContext(gc.get()); - camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height)); - camera->setDrawBuffer(buffer); - camera->setReadBuffer(buffer); - camera->setAllowEventFocus(false); - - // tell the camera to use OpenGL frame buffer object where supported. - camera->setRenderTargetImplementation(renderTargetImplementation); - - // attach the texture and use it as the color buffer. - camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::POSITIVE_Z); - - addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(-90.0f), 1.0,0.0,0.0)); - } - - // left face - { - osg::ref_ptr camera = new osg::Camera; - camera->setName("Left face camera"); - camera->setGraphicsContext(gc.get()); - camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height)); - camera->setDrawBuffer(buffer); - camera->setReadBuffer(buffer); - camera->setAllowEventFocus(false); - - // tell the camera to use OpenGL frame buffer object where supported. - camera->setRenderTargetImplementation(renderTargetImplementation); - - // attach the texture and use it as the color buffer. - camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::NEGATIVE_X); - - addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(-90.0f), 0.0,1.0,0.0) * osg::Matrixd::rotate(osg::inDegrees(-90.0f), 0.0,0.0,1.0)); - } - - // right face - { - osg::ref_ptr camera = new osg::Camera; - camera->setName("Right face camera"); - camera->setGraphicsContext(gc.get()); - camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height)); - camera->setDrawBuffer(buffer); - camera->setReadBuffer(buffer); - camera->setAllowEventFocus(false); - - // tell the camera to use OpenGL frame buffer object where supported. - camera->setRenderTargetImplementation(renderTargetImplementation); - - // attach the texture and use it as the color buffer. - camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::POSITIVE_X); - - addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(90.0f), 0.0,1.0,0.0 ) * osg::Matrixd::rotate(osg::inDegrees(90.0f), 0.0,0.0,1.0)); - } - - // bottom face - { - osg::ref_ptr camera = new osg::Camera; - camera->setGraphicsContext(gc.get()); - camera->setName("Bottom face camera"); - camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height)); - camera->setDrawBuffer(buffer); - camera->setReadBuffer(buffer); - camera->setAllowEventFocus(false); - - // tell the camera to use OpenGL frame buffer object where supported. - camera->setRenderTargetImplementation(renderTargetImplementation); - - // attach the texture and use it as the color buffer. - camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::NEGATIVE_Z); - - addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(90.0f), 1.0,0.0,0.0) * osg::Matrixd::rotate(osg::inDegrees(180.0f), 0.0,0.0,1.0)); - } - - // back face - { - osg::ref_ptr camera = new osg::Camera; - camera->setName("Back face camera"); - camera->setGraphicsContext(gc.get()); - camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height)); - camera->setDrawBuffer(buffer); - camera->setReadBuffer(buffer); - camera->setAllowEventFocus(false); - - // tell the camera to use OpenGL frame buffer object where supported. - camera->setRenderTargetImplementation(renderTargetImplementation); - - // attach the texture and use it as the color buffer. - camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::NEGATIVE_Y); - - addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(180.0f), 1.0,0.0,0.0)); - } - - getCamera()->setProjectionMatrixAsPerspective(90.0f, 1.0, 1, 1000.0); - - // distortion correction set up. - { - osg::Geode* geode = new osg::Geode(); - geode->addDrawable(create3DSphericalDisplayDistortionMesh(osg::Vec3(0.0f,0.0f,0.0f), osg::Vec3(width,0.0f,0.0f), osg::Vec3(0.0f,height,0.0f), radius, collar, applyIntensityMapAsColours ? intensityMap : 0, projectorMatrix)); - - // new we need to add the texture to the mesh, we do so by creating a - // StateSet to contain the Texture StateAttribute. - osg::StateSet* stateset = geode->getOrCreateStateSet(); - stateset->setTextureAttributeAndModes(0, texture,osg::StateAttribute::ON); - stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); - - if (!applyIntensityMapAsColours && intensityMap) - { - stateset->setTextureAttributeAndModes(1, new osg::Texture2D(intensityMap), osg::StateAttribute::ON); - } - - osg::ref_ptr camera = new osg::Camera; - camera->setGraphicsContext(gc.get()); - camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT ); - camera->setClearColor( osg::Vec4(0.0,0.0,0.0,1.0) ); - camera->setViewport(new osg::Viewport(0, 0, width, height)); - GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; - camera->setDrawBuffer(buffer); - camera->setReadBuffer(buffer); - camera->setReferenceFrame(osg::Camera::ABSOLUTE_RF); - camera->setAllowEventFocus(true); - camera->setInheritanceMask(camera->getInheritanceMask() & ~osg::CullSettings::CLEAR_COLOR & ~osg::CullSettings::COMPUTE_NEAR_FAR_MODE); - //camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR); - - camera->setProjectionMatrixAsOrtho2D(0,width,0,height); - camera->setViewMatrix(osg::Matrix::identity()); - - // add subgraph to render - camera->addChild(geode); - - camera->setName("DistortionCorrectionCamera"); - - addSlave(camera.get(), osg::Matrixd(), osg::Matrixd(), false); - } - - getCamera()->setNearFarRatio(0.0001f); - - if (getLightingMode()==osg::View::HEADLIGHT) - { - // set a local light source for headlight to ensure that lighting is consistent across sides of cube. - getLight()->setPosition(osg::Vec4(0.0f,0.0f,0.0f,1.0f)); - } -} - -static osg::Geometry* createParoramicSphericalDisplayDistortionMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector, double sphere_radius, double collar_radius, osg::Image* intensityMap, const osg::Matrix& projectorMatrix) -{ - osg::Vec3d center(0.0,0.0,0.0); - osg::Vec3d eye(0.0,0.0,0.0); - - double distance = sqrt(sphere_radius*sphere_radius - collar_radius*collar_radius); - bool flip = false; - bool texcoord_flip = false; - - osg::Vec3d projector = eye - osg::Vec3d(0.0,0.0, distance); - - - OSG_INFO<<"createParoramicSphericalDisplayDistortionMesh : Projector position = "<getScreenResolution(si, width, height); - - osg::ref_ptr traits = new osg::GraphicsContext::Traits; - traits->hostName = si.hostName; - traits->displayNum = si.displayNum; - traits->screenNum = si.screenNum; - traits->x = 0; - traits->y = 0; - traits->width = width; - traits->height = height; - traits->windowDecoration = false; - traits->doubleBuffer = true; - traits->sharedContext = 0; - - - bool applyIntensityMapAsColours = true; - - osg::ref_ptr gc = osg::GraphicsContext::createGraphicsContext(traits.get()); - if (!gc) - { - OSG_NOTICE<<"GraphicsWindow has not been created successfully."<setTextureSize(tex_width, tex_height); - texture->setInternalFormat(GL_RGB); - texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); - texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); - texture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE); - texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE); - -#if 0 - osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::SEPERATE_WINDOW; - GLenum buffer = GL_FRONT; -#else - osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::FRAME_BUFFER_OBJECT; - GLenum buffer = GL_FRONT; -#endif - - // front face - { - osg::ref_ptr camera = new osg::Camera; - camera->setName("Front face camera"); - camera->setGraphicsContext(gc.get()); - camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height)); - camera->setDrawBuffer(buffer); - camera->setReadBuffer(buffer); - camera->setAllowEventFocus(false); - // tell the camera to use OpenGL frame buffer object where supported. - camera->setRenderTargetImplementation(renderTargetImplementation); - - // attach the texture and use it as the color buffer. - camera->attach(osg::Camera::COLOR_BUFFER, texture); - - addSlave(camera.get(), osg::Matrixd(), osg::Matrixd()); - } - - // distortion correction set up. - { - osg::Geode* geode = new osg::Geode(); - geode->addDrawable(createParoramicSphericalDisplayDistortionMesh(osg::Vec3(0.0f,0.0f,0.0f), osg::Vec3(width,0.0f,0.0f), osg::Vec3(0.0f,height,0.0f), radius, collar, applyIntensityMapAsColours ? intensityMap : 0, projectorMatrix)); - - // new we need to add the texture to the mesh, we do so by creating a - // StateSet to contain the Texture StateAttribute. - osg::StateSet* stateset = geode->getOrCreateStateSet(); - stateset->setTextureAttributeAndModes(0, texture,osg::StateAttribute::ON); - stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); - - osg::TexMat* texmat = new osg::TexMat; - texmat->setScaleByTextureRectangleSize(true); - stateset->setTextureAttributeAndModes(0, texmat, osg::StateAttribute::ON); - - if (!applyIntensityMapAsColours && intensityMap) - { - stateset->setTextureAttributeAndModes(1, new osg::Texture2D(intensityMap), osg::StateAttribute::ON); - } - - osg::ref_ptr camera = new osg::Camera; - camera->setGraphicsContext(gc.get()); - camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT ); - camera->setClearColor( osg::Vec4(0.0,0.0,0.0,1.0) ); - camera->setViewport(new osg::Viewport(0, 0, width, height)); - GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; - camera->setDrawBuffer(buffer); - camera->setReadBuffer(buffer); - camera->setReferenceFrame(osg::Camera::ABSOLUTE_RF); - camera->setAllowEventFocus(false); - camera->setInheritanceMask(camera->getInheritanceMask() & ~osg::CullSettings::CLEAR_COLOR & ~osg::CullSettings::COMPUTE_NEAR_FAR_MODE); - //camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR); - - camera->setProjectionMatrixAsOrtho2D(0,width,0,height); - camera->setViewMatrix(osg::Matrix::identity()); - - // add subgraph to render - camera->addChild(geode); - - camera->setName("DistortionCorrectionCamera"); - - addSlave(camera.get(), osg::Matrixd(), osg::Matrixd(), false); - } + apply(new osgViewer::PanoramicSphericalDisplay(radius, collar, screenNum, intensityMap, projectorMatrix)); } void View::setUpViewForWoWVxDisplay(unsigned int screenNum, unsigned char wow_content, unsigned char wow_factor, unsigned char wow_offset, float wow_disparity_Zd, float wow_disparity_vz, float wow_disparity_M, float wow_disparity_C) { - OSG_INFO<<"View::setUpViewForWoWVxDisplay(...)"<getScreenResolution(si, width, height); - - osg::ref_ptr traits = new osg::GraphicsContext::Traits; - traits->hostName = si.hostName; - traits->displayNum = si.displayNum; - traits->screenNum = si.screenNum; - traits->x = 0; - traits->y = 0; - traits->width = width; - traits->height = height; - traits->windowDecoration = false; - traits->doubleBuffer = true; - traits->sharedContext = 0; - - - osg::ref_ptr gc = osg::GraphicsContext::createGraphicsContext(traits.get()); - if (!gc) - { - OSG_NOTICE<<"GraphicsWindow has not been created successfully."<setTextureSize(tex_width, tex_height); - texture->setInternalFormat(GL_RGB); - texture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR); - texture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR); - - osg::Texture2D* textureD = new osg::Texture2D; - textureD->setTextureSize(tex_width, tex_height); - textureD->setInternalFormat(GL_DEPTH_COMPONENT); - textureD->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR); - textureD->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR); - -#if 0 - osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::SEPERATE_WINDOW; - GLenum buffer = GL_FRONT; -#else - osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::FRAME_BUFFER_OBJECT; - GLenum buffer = GL_FRONT; -#endif - - // front face - { - osg::ref_ptr camera = new osg::Camera; - camera->setName("Front face camera"); - camera->setGraphicsContext(gc.get()); - camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height)); - camera->setDrawBuffer(buffer); - camera->setReadBuffer(buffer); - camera->setAllowEventFocus(false); - // tell the camera to use OpenGL frame buffer object where supported. - camera->setRenderTargetImplementation(renderTargetImplementation); - - // attach the texture and use it as the color buffer. - camera->attach(osg::Camera::COLOR_BUFFER, texture); - camera->attach(osg::Camera::DEPTH_BUFFER, textureD); - - addSlave(camera.get(), osg::Matrixd(), osg::Matrixd()); - } - - // WoW display set up. - { - osg::Texture1D *textureHeader = new osg::Texture1D(); - // Set up the header - { - unsigned char header[]= {0xF1,wow_content,wow_factor,wow_offset,0x00,0x00,0x00,0x00,0x00,0x00}; - // Calc the CRC32 - { - unsigned long _register = 0; - for(int i = 0; i < 10; ++i) { - unsigned char mask = 0x80; - unsigned char byte = header[i]; - for (int j = 0; j < 8; ++j) - { - bool topBit = (_register & 0x80000000) != 0; - _register <<= 1; - _register ^= ((byte & mask) != 0? 0x1: 0x0); - if (topBit) - { - _register ^= 0x04c11db7; - } - mask >>= 1; - } - } - unsigned char *p = (unsigned char*) &_register; - for(size_t i = 0; i < 4; ++i) - { - header[i+6] = p[3-i]; - } - } - - osg::ref_ptr imageheader = new osg::Image(); - imageheader->allocateImage(256,1,1,GL_LUMINANCE,GL_UNSIGNED_BYTE); - { - unsigned char *cheader = imageheader->data(); - for (int x=0; x<256; ++x){ - cheader[x] = 0; - } - for (int x=0; x<=9; ++x){ - for (int y=7; y>=0; --y){ - int i = 2*(7-y)+16*x; - cheader[i] = (((1<<(y))&(header[x])) << (7-(y))); - } - } - } - textureHeader->setImage(imageheader.get()); - } - - // Create the Screen Aligned Quad - osg::Geode* geode = new osg::Geode(); - { - osg::Geometry* geom = new osg::Geometry; - - osg::Vec3Array* vertices = new osg::Vec3Array; - vertices->push_back(osg::Vec3(0,height,0)); - vertices->push_back(osg::Vec3(0,0,0)); - vertices->push_back(osg::Vec3(width,0,0)); - vertices->push_back(osg::Vec3(width,height,0)); - geom->setVertexArray(vertices); - - osg::Vec2Array* tex = new osg::Vec2Array; - tex->push_back(osg::Vec2(0,1)); - tex->push_back(osg::Vec2(0,0)); - tex->push_back(osg::Vec2(1,0)); - tex->push_back(osg::Vec2(1,1)); - geom->setTexCoordArray(0,tex); - - geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4)); - geode->addDrawable(geom); - - // new we need to add the textures to the quad, and setting up the shader. - osg::StateSet* stateset = geode->getOrCreateStateSet(); - stateset->setTextureAttributeAndModes(0, textureHeader,osg::StateAttribute::ON); - stateset->setTextureAttributeAndModes(1, texture,osg::StateAttribute::ON); - stateset->setTextureAttributeAndModes(2, textureD,osg::StateAttribute::ON); - stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); - - osg::ref_ptr programShader = new osg::Program(); - stateset->setAttribute(programShader.get(), osg::StateAttribute::ON); - stateset->addUniform( new osg::Uniform("wow_width", (int)width)); - stateset->addUniform( new osg::Uniform("wow_height", (int)height)); - stateset->addUniform( new osg::Uniform("wow_disparity_M", wow_disparity_M)); - stateset->addUniform( new osg::Uniform("wow_disparity_Zd", wow_disparity_Zd)); - stateset->addUniform( new osg::Uniform("wow_disparity_vz", wow_disparity_vz)); - stateset->addUniform( new osg::Uniform("wow_disparity_C", wow_disparity_C)); - - stateset->addUniform(new osg::Uniform("wow_header", 0)); - stateset->addUniform(new osg::Uniform("wow_tcolor", 1)); - stateset->addUniform(new osg::Uniform("wow_tdepth", 2)); - - osg::Shader *frag = new osg::Shader(osg::Shader::FRAGMENT); - frag->setShaderSource(" "\ - " uniform sampler1D wow_header; " \ - " uniform sampler2D wow_tcolor; " \ - " uniform sampler2D wow_tdepth; " \ - " " \ - " uniform int wow_width; " \ - " uniform int wow_height; " \ - " uniform float wow_disparity_M; " \ - " uniform float wow_disparity_Zd; " \ - " uniform float wow_disparity_vz; " \ - " uniform float wow_disparity_C; " \ - " " \ - " float disparity(float Z) " \ - " { " \ - " return (wow_disparity_M*(1.0-(wow_disparity_vz/(Z-wow_disparity_Zd+wow_disparity_vz))) " \ - " + wow_disparity_C) / 255.0; " \ - " } " \ - " " \ - " void main() " \ - " { " \ - " vec2 pos = (gl_FragCoord.xy / vec2(wow_width/2,wow_height) ); " \ - " if (gl_FragCoord.x > float(wow_width/2)) " \ - " { " \ - " gl_FragColor = vec4(disparity(( texture2D(wow_tdepth, pos - vec2(1,0))).z)); " \ - " } " \ - " else{ " \ - " gl_FragColor = texture2D(wow_tcolor, pos); " \ - " } " \ - " if ( (gl_FragCoord.y >= float(wow_height-1)) && (gl_FragCoord.x < 256.0) ) " \ - " { " \ - " float pos = gl_FragCoord.x/256.0; " \ - " float blue = texture1D(wow_header, pos).b; " \ - " if ( blue < 0.5) " \ - " gl_FragColor.b = 0.0; " \ - " else " \ - " gl_FragColor.b = 1.0; " \ - " } " \ - " } " ); - - programShader->addShader(frag); - } - - // Create the Camera - { - osg::ref_ptr camera = new osg::Camera; - camera->setGraphicsContext(gc.get()); - camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT ); - camera->setClearColor( osg::Vec4(0.0,0.0,0.0,1.0) ); - camera->setViewport(new osg::Viewport(0, 0, width, height)); - GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; - camera->setDrawBuffer(buffer); - camera->setReadBuffer(buffer); - camera->setReferenceFrame(osg::Camera::ABSOLUTE_RF); - camera->setAllowEventFocus(false); - camera->setInheritanceMask(camera->getInheritanceMask() & ~osg::CullSettings::CLEAR_COLOR & ~osg::CullSettings::COMPUTE_NEAR_FAR_MODE); - //camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR); - - camera->setProjectionMatrixAsOrtho2D(0,width,0,height); - camera->setViewMatrix(osg::Matrix::identity()); - - // add subgraph to render - camera->addChild(geode); - - camera->setName("WoWCamera"); - - addSlave(camera.get(), osg::Matrixd(), osg::Matrixd(), false); - } - } + apply(new osgViewer::WoWVxDisplay(screenNum, wow_content, wow_factor, wow_offset, wow_disparity_Zd,wow_disparity_vz, wow_disparity_M, wow_disparity_C)); } DepthPartitionSettings::DepthPartitionSettings(DepthMode mode): diff --git a/src/osgViewer/Viewer.cpp b/src/osgViewer/Viewer.cpp index 3b4115508..75bfe2266 100644 --- a/src/osgViewer/Viewer.cpp +++ b/src/osgViewer/Viewer.cpp @@ -26,7 +26,6 @@ #include #include #include -#include #include #include @@ -301,11 +300,10 @@ bool Viewer::readConfiguration(const std::string& filename) return false; } - Config* config = dynamic_cast(object.get()); + ViewConfig* config = dynamic_cast(object.get()); if (config) { - OSG_NOTICE<<"Using osgViewer::Config : "<className()<configure(*this); + apply(config); return true; } diff --git a/src/osgWrappers/serializers/osgViewer/Config.cpp b/src/osgWrappers/serializers/osgViewer/Config.cpp index 4637c350e..f9bdb64d6 100644 --- a/src/osgWrappers/serializers/osgViewer/Config.cpp +++ b/src/osgWrappers/serializers/osgViewer/Config.cpp @@ -1,12 +1,12 @@ -#include +#include #include #include #include -REGISTER_OBJECT_WRAPPER( osgViewer_Config, - new osgViewer::Config, - osgViewer::Config, - "osg::Object osgViewer::Config" ) +REGISTER_OBJECT_WRAPPER( osgViewer_ViewConfig, + new osgViewer::ViewConfig, + osgViewer::ViewConfig, + "osg::Object osgViewer::ViewConfig" ) { } diff --git a/src/osgWrappers/serializers/osgViewer/PanoramicSphericalDisplay.cpp b/src/osgWrappers/serializers/osgViewer/PanoramicSphericalDisplay.cpp index cc384e557..d8e5038e5 100644 --- a/src/osgWrappers/serializers/osgViewer/PanoramicSphericalDisplay.cpp +++ b/src/osgWrappers/serializers/osgViewer/PanoramicSphericalDisplay.cpp @@ -7,7 +7,7 @@ REGISTER_OBJECT_WRAPPER( osgViewer_PanoramicSphericalDisplay, new osgViewer::PanoramicSphericalDisplay, osgViewer::PanoramicSphericalDisplay, - "osg::Object osgViewer::Config osgViewer::PanoramicSphericalDisplay" ) + "osg::Object osgViewer::ViewConfig osgViewer::PanoramicSphericalDisplay" ) { ADD_DOUBLE_SERIALIZER(Radius, 1.0); ADD_DOUBLE_SERIALIZER(Collar, 0.45); diff --git a/src/osgWrappers/serializers/osgViewer/SingleScreen.cpp b/src/osgWrappers/serializers/osgViewer/SingleScreen.cpp index 31ebe1042..24de055d7 100644 --- a/src/osgWrappers/serializers/osgViewer/SingleScreen.cpp +++ b/src/osgWrappers/serializers/osgViewer/SingleScreen.cpp @@ -7,7 +7,7 @@ REGISTER_OBJECT_WRAPPER( osgViewer_SingleScreen, new osgViewer::SingleScreen, osgViewer::SingleScreen, - "osg::Object osgViewer::Config osgViewer::SingleScreen" ) + "osg::Object osgViewer::ViewConfig osgViewer::SingleScreen" ) { ADD_UINT_SERIALIZER( ScreenNum, 0u); } diff --git a/src/osgWrappers/serializers/osgViewer/SingleWindow.cpp b/src/osgWrappers/serializers/osgViewer/SingleWindow.cpp index a1c86d49e..183953203 100644 --- a/src/osgWrappers/serializers/osgViewer/SingleWindow.cpp +++ b/src/osgWrappers/serializers/osgViewer/SingleWindow.cpp @@ -7,7 +7,7 @@ REGISTER_OBJECT_WRAPPER( osgViewer_SingleWindow, new osgViewer::SingleWindow, osgViewer::SingleWindow, - "osg::Object osgViewer::Config osgViewer::SingleWindow" ) + "osg::Object osgViewer::ViewConfig osgViewer::SingleWindow" ) { ADD_INT_SERIALIZER( X, 0); ADD_INT_SERIALIZER( Y, 0); diff --git a/src/osgWrappers/serializers/osgViewer/SphericalDisplay.cpp b/src/osgWrappers/serializers/osgViewer/SphericalDisplay.cpp index 27cff3db9..56d0fd427 100644 --- a/src/osgWrappers/serializers/osgViewer/SphericalDisplay.cpp +++ b/src/osgWrappers/serializers/osgViewer/SphericalDisplay.cpp @@ -7,7 +7,7 @@ REGISTER_OBJECT_WRAPPER( osgViewer_SphericalDisplay, new osgViewer::SphericalDisplay, osgViewer::SphericalDisplay, - "osg::Object osgViewer::Config osgViewer::SphericalDisplay" ) + "osg::Object osgViewer::ViewConfig osgViewer::SphericalDisplay" ) { ADD_DOUBLE_SERIALIZER(Radius, 1.0); ADD_DOUBLE_SERIALIZER(Collar, 0.45); diff --git a/src/osgWrappers/serializers/osgViewer/WoWVxDisplay.cpp b/src/osgWrappers/serializers/osgViewer/WoWVxDisplay.cpp index 82dee7617..26608818a 100644 --- a/src/osgWrappers/serializers/osgViewer/WoWVxDisplay.cpp +++ b/src/osgWrappers/serializers/osgViewer/WoWVxDisplay.cpp @@ -7,16 +7,17 @@ REGISTER_OBJECT_WRAPPER( osgViewer_WoWVxDisplay, new osgViewer::WoWVxDisplay, osgViewer::WoWVxDisplay, - "osg::Object osgViewer::Config osgViewer::WoWVxDisplay" ) + "osg::Object osgViewer::ViewConfig osgViewer::WoWVxDisplay" ) { ADD_UINT_SERIALIZER(ScreenNum, 0u); - - ADD_UCHAR_SERIALIZER(Content, 0); - ADD_UCHAR_SERIALIZER(Factor, 0); - ADD_UCHAR_SERIALIZER(Offset, 0); - - ADD_FLOAT_SERIALIZER(DisparityZD, 0); - ADD_FLOAT_SERIALIZER(DisparityVZ, 0); - ADD_FLOAT_SERIALIZER(DisparityM, 0); - ADD_FLOAT_SERIALIZER(DisparityC, 0); +#if 0 + ADD_UCHAR_SERIALIZER(Content, 0x02); + ADD_UCHAR_SERIALIZER(Factor, 0x40); + ADD_UCHAR_SERIALIZER(Offset, 0x80); +#endif + + ADD_FLOAT_SERIALIZER(DisparityZD, 0.459813f); + ADD_FLOAT_SERIALIZER(DisparityVZ, 6.180772f); + ADD_FLOAT_SERIALIZER(DisparityM, -1586.34f); + ADD_FLOAT_SERIALIZER(DisparityC, 127.5f); }