Equalizer  1.4.1
sceneView.h
00001 
00002 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield 
00003  *                           2010 Stefan Eilemann <eile@eyescale.ch>
00004  *
00005  * This library is open source and may be redistributed and/or modified under  
00006  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 
00007  * (at your option) any later version.  The full license is in LICENSE file
00008  * included with this distribution, and on the openscenegraph.org website.
00009  * 
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
00013  * OpenSceneGraph Public License for more details.
00014  */
00015 
00016 #ifndef OSG_SV_SCENEVIEW
00017 #define OSG_SV_SCENEVIEW
00018 
00019 #include <osg/Node>
00020 #include <osg/StateSet>
00021 #include <osg/Light>
00022 #include <osg/FrameStamp>
00023 #include <osg/DisplaySettings>
00024 #include <osg/CollectOccludersVisitor>
00025 #include <osg/CullSettings>
00026 #include <osg/Camera>
00027 
00028 #include <osgUtil/CullVisitor>
00029 
00030 namespace osgScaleViewer {
00031 
00041 class SceneView : public osg::Object, public osg::CullSettings
00042 {
00043     public:
00044 
00046         SceneView(osg::DisplaySettings* ds=NULL);
00047 
00048         SceneView(const SceneView& sceneview, const osg::CopyOp& copyop = osg::CopyOp());
00049 
00050         META_Object(osgUtil, SceneView);
00051 
00052         enum Options
00053         {
00054             NO_SCENEVIEW_LIGHT = 0x0,
00055             HEADLIGHT = 0x1,
00056             SKY_LIGHT = 0x2,
00057             COMPILE_GLOBJECTS_AT_INIT = 0x4,
00058             STANDARD_SETTINGS = SKY_LIGHT |
00059                                 COMPILE_GLOBJECTS_AT_INIT
00060         };
00061 
00062         /* Set defaults. */
00063         virtual void setDefaults() { setDefaults(STANDARD_SETTINGS); }
00064 
00068         virtual void setDefaults(unsigned int options);
00069 
00071         void setCamera(osg::Camera* camera, bool assumeOwnershipOfCamera = true);
00072 
00074         osg::Camera* getCamera() { return _camera.get(); }
00075 
00077         const osg::Camera* getCamera() const { return _camera.get(); }
00078 
00082         void setSceneData(osg::Node* node);
00083         
00087         osg::Node* getSceneData(unsigned int childNo=0) { return (_camera->getNumChildren()>childNo) ? _camera->getChild(childNo) : 0; }
00088 
00092         const osg::Node* getSceneData(unsigned int childNo=0) const { return (_camera->getNumChildren()>childNo) ? _camera->getChild(childNo) : 0; }
00093         
00095         unsigned int getNumSceneData() const { return _camera->getNumChildren(); }
00096 
00098         void setViewport(osg::Viewport* viewport) { _camera->setViewport(viewport); }
00099 
00101         void setViewport(int x,int y,int width,int height) { _camera->setViewport(x,y,width,height); }
00102 
00103 
00105         osg::Viewport* getViewport() { return (_camera->getViewport()!=0) ? _camera->getViewport() : 0; }
00106 
00108         const osg::Viewport* getViewport() const { return (_camera->getViewport()!=0) ? _camera->getViewport() : 0; }
00109         
00111         inline void setDisplaySettings(osg::DisplaySettings* vs) { _displaySettings = vs; }
00112         
00114         inline const osg::DisplaySettings* getDisplaySettings() const { return _displaySettings.get(); }
00115 
00117         inline osg::DisplaySettings* getDisplaySettings() { return _displaySettings.get(); }
00118 
00119 
00122         void setClearColor(const osg::Vec4& color) { _camera->setClearColor(color); }
00123 
00125         const osg::Vec4& getClearColor() const { return _camera->getClearColor(); }
00126         
00127         void setGlobalStateSet(osg::StateSet* state) { _globalStateSet = state; }
00128         osg::StateSet* getGlobalStateSet() { return _globalStateSet.get(); }
00129         const osg::StateSet* getGlobalStateSet() const { return _globalStateSet.get(); }
00130 
00131         void setSecondaryStateSet(osg::StateSet* state) { _secondaryStateSet = state; }
00132         osg::StateSet* getSecondaryStateSet() { return _secondaryStateSet.get(); }
00133         const osg::StateSet* getSecondaryStateSet() const { return _secondaryStateSet.get(); }
00134 
00135         void setLocalStateSet(osg::StateSet* state) { _localStateSet = state; }
00136         osg::StateSet* getLocalStateSet() { return _localStateSet.get(); }
00137         const osg::StateSet* getLocalStateSet() const { return _localStateSet.get(); }
00138         
00139         enum ActiveUniforms
00140         {
00141             FRAME_NUMBER_UNIFORM            = 1,
00142             FRAME_TIME_UNIFORM              = 2,
00143             DELTA_FRAME_TIME_UNIFORM        = 4,
00144             SIMULATION_TIME_UNIFORM         = 8,
00145             DELTA_SIMULATION_TIME_UNIFORM   = 16,
00146             VIEW_MATRIX_UNIFORM             = 32,
00147             VIEW_MATRIX_INVERSE_UNIFORM     = 64,
00148             DEFAULT_UNIFORMS                = FRAME_NUMBER_UNIFORM |
00149                                               FRAME_TIME_UNIFORM |
00150                                               DELTA_FRAME_TIME_UNIFORM |
00151                                               SIMULATION_TIME_UNIFORM |
00152                                               DELTA_SIMULATION_TIME_UNIFORM |
00153                                               VIEW_MATRIX_UNIFORM |
00154                                               VIEW_MATRIX_INVERSE_UNIFORM,
00155             ALL_UNIFORMS                    = 0x7FFFFFFF
00156         };
00157 
00159         void setActiveUniforms(int activeUniforms) { _activeUniforms = activeUniforms; }
00160 
00162         int getActiveUniforms() const { return _activeUniforms; }
00163 
00164         void updateUniforms();
00165         
00166 
00167         typedef Options LightingMode;
00168 
00169         void setLightingMode(LightingMode mode);
00170         LightingMode getLightingMode() const { return _lightingMode; }
00171 
00172         void setLight(osg::Light* light) { _light = light; }
00173         osg::Light* getLight() { return _light.get(); }
00174         const osg::Light* getLight() const { return _light.get(); }
00175         
00176         void setState(osg::State* state) { _renderInfo.setState(state); }
00177         osg::State* getState() { return _renderInfo.getState(); }
00178         const osg::State* getState() const { return _renderInfo.getState(); }
00179         
00180         void setView(osg::View* view) { _camera->setView(view); }
00181         osg::View* getView() { return _camera->getView(); }
00182         const osg::View* getView() const { return _camera->getView(); }
00183 
00184         void setRenderInfo(osg::RenderInfo& renderInfo) { _renderInfo = renderInfo; }
00185         osg::RenderInfo& getRenderInfo() { return _renderInfo; }
00186         const osg::RenderInfo& getRenderInfo() const { return _renderInfo; }
00187         
00188 
00189 
00191         inline void setProjectionMatrix(const osg::Matrixf& matrix) { _camera->setProjectionMatrix(matrix); }
00192 
00194         inline void setProjectionMatrix(const osg::Matrixd& matrix) { _camera->setProjectionMatrix(matrix); }
00195 
00197         void setProjectionMatrixAsOrtho(double left, double right,
00198                                         double bottom, double top,
00199                                         double zNear, double zFar);
00200 
00202         void setProjectionMatrixAsOrtho2D(double left, double right,
00203                                           double bottom, double top);
00204 
00206         void setProjectionMatrixAsFrustum(double left, double right,
00207                                           double bottom, double top,
00208                                           double zNear, double zFar);
00209 
00212         void setProjectionMatrixAsPerspective(double fovy,double aspectRatio,
00213                                               double zNear, double zFar);
00214 
00216         osg::Matrixd& getProjectionMatrix() { return _camera->getProjectionMatrix(); }
00217 
00219         const osg::Matrixd& getProjectionMatrix() const { return _camera->getProjectionMatrix(); }
00220 
00223         bool getProjectionMatrixAsOrtho(double& left, double& right,
00224                                         double& bottom, double& top,
00225                                         double& zNear, double& zFar) const;
00226 
00229         bool getProjectionMatrixAsFrustum(double& left, double& right,
00230                                           double& bottom, double& top,
00231                                           double& zNear, double& zFar) const;
00232 
00238         bool getProjectionMatrixAsPerspective(double& fovy,double& aspectRatio,
00239                                               double& zNear, double& zFar) const;
00240 
00241 
00243         inline void setViewMatrix(const osg::Matrixf& matrix) { _camera->setViewMatrix(matrix); }
00244         
00246         inline void setViewMatrix(const osg::Matrixd& matrix) { _camera->setViewMatrix(matrix); }
00247 
00249         void setViewMatrixAsLookAt(const osg::Vec3& eye,const osg::Vec3& center,const osg::Vec3& up);
00250 
00252         osg::Matrixd& getViewMatrix() { return _camera->getViewMatrix(); }
00253 
00255         const osg::Matrixd& getViewMatrix() const { return _camera->getViewMatrix(); }
00256 
00258         void getViewMatrixAsLookAt(osg::Vec3& eye,osg::Vec3& center,osg::Vec3& up,float lookDistance=1.0f) const;
00259 
00260 
00261 
00262         
00263         void setInitVisitor(osg::NodeVisitor* av) { _initVisitor = av; }
00264         osg::NodeVisitor* getInitVisitor() { return _initVisitor.get(); }
00265         const osg::NodeVisitor* getInitVisitor() const { return _initVisitor.get(); }
00266 
00267 
00268         void setUpdateVisitor(osg::NodeVisitor* av) { _updateVisitor = av; }
00269         osg::NodeVisitor* getUpdateVisitor() { return _updateVisitor.get(); }
00270         const osg::NodeVisitor* getUpdateVisitor() const { return _updateVisitor.get(); }
00271 
00272 
00273         void setCullVisitor(osgUtil::CullVisitor* cv) { _cullVisitor = cv; }
00274         osgUtil::CullVisitor* getCullVisitor() { return _cullVisitor.get(); }
00275         const osgUtil::CullVisitor* getCullVisitor() const { return _cullVisitor.get(); }
00276 
00277         void setCollectOccludersVisitor(osg::CollectOccludersVisitor* cov) { _collectOccludersVisitor = cov; }
00278         osg::CollectOccludersVisitor* getCollectOccludersVisitor() { return _collectOccludersVisitor.get(); }
00279         const osg::CollectOccludersVisitor* getCollectOccludersVisitor() const { return _collectOccludersVisitor.get(); }
00280 
00281 
00282         void setStateGraph(osgUtil::StateGraph* rg) { _stateGraph = rg; }
00283         osgUtil::StateGraph* getStateGraph() { return _stateGraph.get(); }
00284         const osgUtil::StateGraph* getStateGraph() const { return _stateGraph.get(); }
00285 
00286         void setRenderStage(osgUtil::RenderStage* rs) { _renderStage = rs; }
00287         osgUtil::RenderStage* getRenderStage() { return _renderStage.get(); }
00288         const osgUtil::RenderStage* getRenderStage() const { return _renderStage.get(); }
00289 
00291         void collateReferencesToDependentCameras();
00292 
00294         void clearReferencesToDependentCameras();
00295 
00296 
00298         void setDrawBufferValue( GLenum drawBufferValue ) { _camera->setDrawBuffer(drawBufferValue); }
00299 
00301         GLenum getDrawBufferValue() const { return _camera->getDrawBuffer(); }
00302 
00303 
00305         void setPrioritizeTextures(bool pt) { _prioritizeTextures = pt; }
00306         
00308         bool getPrioritizeTextures() const { return _prioritizeTextures; }
00309 
00316         bool projectWindowIntoObject(const osg::Vec3& window,osg::Vec3& object) const;
00317 
00324         bool projectWindowXYIntoObject(int x,int y,osg::Vec3& near_point,osg::Vec3& far_point) const;
00325 
00334         bool projectObjectIntoWindow(const osg::Vec3& object,osg::Vec3& window) const;
00335 
00336 
00338         inline void setFrameStamp(osg::FrameStamp* fs) { _frameStamp = fs; }
00339 
00341         inline const osg::FrameStamp* getFrameStamp() const { return _frameStamp.get(); }
00342 
00343 
00345         virtual void inheritCullSettings(const osg::CullSettings& settings) { inheritCullSettings(settings, _inheritanceMask); }
00346 
00348         virtual void inheritCullSettings(const osg::CullSettings& settings, unsigned int inheritanceMask);
00349 
00350 
00358         virtual void init();
00359 
00361         virtual void cull();
00362 
00364         virtual void draw();
00365         
00367         unsigned int getDynamicObjectCount() const { return _dynamicObjectCount; }
00368         
00372         virtual void releaseAllGLObjects();
00373 
00375         virtual void flushAllDeletedGLObjects();
00376 
00378         virtual void flushDeletedGLObjects(double& availableTime);
00379         
00381         bool getStats(osgUtil::Statistics& primStats); 
00382 
00383     protected:
00384 
00385         virtual ~SceneView();
00386 
00388         virtual bool cullStage(const osg::Matrixd& projection,const osg::Matrixd& modelview,osgUtil::CullVisitor* cullVisitor, osgUtil::StateGraph* rendergraph, osgUtil::RenderStage* renderStage, osg::Viewport *viewport);
00389         
00390         const osg::Matrix computeMVPW() const;
00391 
00392         void clearArea(int x,int y,int width,int height,const osg::Vec4& color);
00393 
00394         osg::ref_ptr<osg::StateSet>                 _localStateSet;
00395         osg::RenderInfo                             _renderInfo;
00396         
00397         bool                                        _initCalled;
00398         osg::ref_ptr<osg::NodeVisitor>              _initVisitor;
00399         osg::ref_ptr<osg::NodeVisitor>              _updateVisitor;
00400         osg::ref_ptr<osgUtil::CullVisitor>          _cullVisitor;
00401         osg::ref_ptr<osgUtil::StateGraph>           _stateGraph;
00402         osg::ref_ptr<osgUtil::RenderStage>          _renderStage;
00403 
00404         osg::ref_ptr<osg::CollectOccludersVisitor>  _collectOccludersVisitor;
00405         
00406         osg::ref_ptr<osg::FrameStamp>               _frameStamp;
00407         
00408         osg::observer_ptr<osg::Camera>              _camera;
00409         osg::ref_ptr<osg::Camera>                   _cameraWithOwnership;
00410         
00411         osg::ref_ptr<osg::StateSet>                 _globalStateSet;
00412         osg::ref_ptr<osg::Light>                    _light;
00413         osg::ref_ptr<osg::DisplaySettings>          _displaySettings;
00414         
00415         osg::ref_ptr<osg::StateSet>                 _secondaryStateSet;
00416 
00417         float                                       _fusionDistanceValue;
00418 
00419         LightingMode                                _lightingMode;
00420         
00421         bool                                        _prioritizeTextures;
00422         
00423         bool                                        _requiresFlush;
00424         
00425         int                                         _activeUniforms;        
00426         double                                      _previousFrameTime;
00427         double                                      _previousSimulationTime;
00428         
00429         unsigned int                                _dynamicObjectCount;        
00430 };
00431 
00432 }
00433 
00434 #endif
00435 
Generated on Mon Nov 26 2012 14:41:49 for Equalizer 1.4.1 by  doxygen 1.7.6.1