| 1 | /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield |
|---|
| 2 | * |
|---|
| 3 | * This library is open source and may be redistributed and/or modified under |
|---|
| 4 | * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or |
|---|
| 5 | * (at your option) any later version. The full license is in LICENSE file |
|---|
| 6 | * included with this distribution, and on the openscenegraph.org website. |
|---|
| 7 | * |
|---|
| 8 | * This library is distributed in the hope that it will be useful, |
|---|
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 11 | * OpenSceneGraph Public License for more details. |
|---|
| 12 | */ |
|---|
| 13 | |
|---|
| 14 | #ifndef OSGUTIL_SCENEVIEW |
|---|
| 15 | #define OSGUTIL_SCENEVIEW 1 |
|---|
| 16 | |
|---|
| 17 | #include <osg/Node> |
|---|
| 18 | #include <osg/StateSet> |
|---|
| 19 | #include <osg/Light> |
|---|
| 20 | #include <osg/FrameStamp> |
|---|
| 21 | #include <osg/DisplaySettings> |
|---|
| 22 | #include <osg/CollectOccludersVisitor> |
|---|
| 23 | #include <osg/CullSettings> |
|---|
| 24 | #include <osg/Camera> |
|---|
| 25 | |
|---|
| 26 | #include <osgUtil/CullVisitor> |
|---|
| 27 | |
|---|
| 28 | namespace osgUtil { |
|---|
| 29 | |
|---|
| 30 | /** |
|---|
| 31 | * SceneView is deprecated, and is now just kept for backwards compatibility. |
|---|
| 32 | * It is recommend that you use osgViewer::Viewer/Composite in combination |
|---|
| 33 | * with osgViewer::GraphicsWindowEmbedded for embedded rendering support as |
|---|
| 34 | * this provides a greater range of functionality and consistency of API. |
|---|
| 35 | */ |
|---|
| 36 | class OSGUTIL_EXPORT SceneView : public osg::Object, public osg::CullSettings |
|---|
| 37 | { |
|---|
| 38 | public: |
|---|
| 39 | |
|---|
| 40 | /** Construct a default scene view.*/ |
|---|
| 41 | SceneView(osg::DisplaySettings* ds=NULL); |
|---|
| 42 | |
|---|
| 43 | SceneView(const SceneView& sceneview, const osg::CopyOp& copyop = osg::CopyOp()); |
|---|
| 44 | |
|---|
| 45 | META_Object(osgUtil, SceneView); |
|---|
| 46 | |
|---|
| 47 | enum Options |
|---|
| 48 | { |
|---|
| 49 | NO_SCENEVIEW_LIGHT = 0x0, |
|---|
| 50 | HEADLIGHT = 0x1, |
|---|
| 51 | SKY_LIGHT = 0x2, |
|---|
| 52 | COMPILE_GLOBJECTS_AT_INIT = 0x4, |
|---|
| 53 | STANDARD_SETTINGS = HEADLIGHT | |
|---|
| 54 | COMPILE_GLOBJECTS_AT_INIT |
|---|
| 55 | }; |
|---|
| 56 | |
|---|
| 57 | /* Set defaults. */ |
|---|
| 58 | virtual void setDefaults() { setDefaults(STANDARD_SETTINGS); } |
|---|
| 59 | |
|---|
| 60 | /** Set scene view to use default global state, light, camera |
|---|
| 61 | * and render visitor. |
|---|
| 62 | */ |
|---|
| 63 | virtual void setDefaults(unsigned int options); |
|---|
| 64 | |
|---|
| 65 | /** Set the camera used to represent the camera view of this SceneView.*/ |
|---|
| 66 | void setCamera(osg::Camera* camera, bool assumeOwnershipOfCamera = true); |
|---|
| 67 | |
|---|
| 68 | /** Get the camera used to represent the camera view of this SceneView.*/ |
|---|
| 69 | osg::Camera* getCamera() { return _camera.get(); } |
|---|
| 70 | |
|---|
| 71 | /** Get the const camera used to represent the camera view of this SceneView.*/ |
|---|
| 72 | const osg::Camera* getCamera() const { return _camera.get(); } |
|---|
| 73 | |
|---|
| 74 | /** Set the data to view. The data will typically be |
|---|
| 75 | * an osg::Scene but can be any osg::Node type. |
|---|
| 76 | */ |
|---|
| 77 | void setSceneData(osg::Node* node); |
|---|
| 78 | |
|---|
| 79 | /** Get the scene data to view. The data will typically be |
|---|
| 80 | * an osg::Scene but can be any osg::Node type. |
|---|
| 81 | */ |
|---|
| 82 | osg::Node* getSceneData(unsigned int childNo=0) { return (_camera->getNumChildren()>childNo) ? _camera->getChild(childNo) : 0; } |
|---|
| 83 | |
|---|
| 84 | /** Get the const scene data which to view. The data will typically be |
|---|
| 85 | * an osg::Scene but can be any osg::Node type. |
|---|
| 86 | */ |
|---|
| 87 | const osg::Node* getSceneData(unsigned int childNo=0) const { return (_camera->getNumChildren()>childNo) ? _camera->getChild(childNo) : 0; } |
|---|
| 88 | |
|---|
| 89 | /** Get the number of scene data subgraphs added to the SceneView's camera.*/ |
|---|
| 90 | unsigned int getNumSceneData() const { return _camera->getNumChildren(); } |
|---|
| 91 | |
|---|
| 92 | /** Set the viewport of the scene view to use specified osg::Viewport. */ |
|---|
| 93 | void setViewport(osg::Viewport* viewport) { _camera->setViewport(viewport); } |
|---|
| 94 | |
|---|
| 95 | /** Set the viewport of the scene view to specified dimensions. */ |
|---|
| 96 | void setViewport(int x,int y,int width,int height) { _camera->setViewport(x,y,width,height); } |
|---|
| 97 | |
|---|
| 98 | |
|---|
| 99 | /** Get the viewport. */ |
|---|
| 100 | osg::Viewport* getViewport() { return (_camera->getViewport()!=0) ? _camera->getViewport() : 0; } |
|---|
| 101 | |
|---|
| 102 | /** Get the const viewport. */ |
|---|
| 103 | const osg::Viewport* getViewport() const { return (_camera->getViewport()!=0) ? _camera->getViewport() : 0; } |
|---|
| 104 | |
|---|
| 105 | /** Set the DisplaySettings. */ |
|---|
| 106 | inline void setDisplaySettings(osg::DisplaySettings* vs) { _displaySettings = vs; } |
|---|
| 107 | |
|---|
| 108 | /** Get the const DisplaySettings */ |
|---|
| 109 | inline const osg::DisplaySettings* getDisplaySettings() const { return _displaySettings.get(); } |
|---|
| 110 | |
|---|
| 111 | /** Get the DisplaySettings */ |
|---|
| 112 | inline osg::DisplaySettings* getDisplaySettings() { return _displaySettings.get(); } |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | /** Set the color used in glClearColor(). |
|---|
| 116 | Defaults to an off blue color.*/ |
|---|
| 117 | void setClearColor(const osg::Vec4& color) { _camera->setClearColor(color); } |
|---|
| 118 | |
|---|
| 119 | /** Get the color used in glClearColor.*/ |
|---|
| 120 | const osg::Vec4& getClearColor() const { return _camera->getClearColor(); } |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | /** Manually set the redraw interlaced stereo stencil mask request flag to control whether to redraw the stencil buffer on the next frame.*/ |
|---|
| 124 | void setRedrawInterlacedStereoStencilMask(bool flag) { _redrawInterlacedStereoStencilMask = flag; } |
|---|
| 125 | |
|---|
| 126 | /** Get the redraw interlaced stereo stencil mask request flag.*/ |
|---|
| 127 | bool getRedrawInterlacedStereoStencilMask() const { return _redrawInterlacedStereoStencilMask; } |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | void setGlobalStateSet(osg::StateSet* state) { _globalStateSet = state; } |
|---|
| 131 | osg::StateSet* getGlobalStateSet() { return _globalStateSet.get(); } |
|---|
| 132 | const osg::StateSet* getGlobalStateSet() const { return _globalStateSet.get(); } |
|---|
| 133 | |
|---|
| 134 | void setSecondaryStateSet(osg::StateSet* state) { _secondaryStateSet = state; } |
|---|
| 135 | osg::StateSet* getSecondaryStateSet() { return _secondaryStateSet.get(); } |
|---|
| 136 | const osg::StateSet* getSecondaryStateSet() const { return _secondaryStateSet.get(); } |
|---|
| 137 | |
|---|
| 138 | void setLocalStateSet(osg::StateSet* state) { _localStateSet = state; } |
|---|
| 139 | osg::StateSet* getLocalStateSet() { return _localStateSet.get(); } |
|---|
| 140 | const osg::StateSet* getLocalStateSet() const { return _localStateSet.get(); } |
|---|
| 141 | |
|---|
| 142 | enum ActiveUniforms |
|---|
| 143 | { |
|---|
| 144 | FRAME_NUMBER_UNIFORM = 1, |
|---|
| 145 | FRAME_TIME_UNIFORM = 2, |
|---|
| 146 | DELTA_FRAME_TIME_UNIFORM = 4, |
|---|
| 147 | SIMULATION_TIME_UNIFORM = 8, |
|---|
| 148 | DELTA_SIMULATION_TIME_UNIFORM = 16, |
|---|
| 149 | VIEW_MATRIX_UNIFORM = 32, |
|---|
| 150 | VIEW_MATRIX_INVERSE_UNIFORM = 64, |
|---|
| 151 | DEFAULT_UNIFORMS = FRAME_NUMBER_UNIFORM | |
|---|
| 152 | FRAME_TIME_UNIFORM | |
|---|
| 153 | DELTA_FRAME_TIME_UNIFORM | |
|---|
| 154 | SIMULATION_TIME_UNIFORM | |
|---|
| 155 | DELTA_SIMULATION_TIME_UNIFORM | |
|---|
| 156 | VIEW_MATRIX_UNIFORM | |
|---|
| 157 | VIEW_MATRIX_INVERSE_UNIFORM, |
|---|
| 158 | ALL_UNIFORMS = 0x7FFFFFFF |
|---|
| 159 | }; |
|---|
| 160 | |
|---|
| 161 | /** Set the uniforms that SceneView should set set up on each frame.*/ |
|---|
| 162 | void setActiveUniforms(int activeUniforms) { _activeUniforms = activeUniforms; } |
|---|
| 163 | |
|---|
| 164 | /** Get the uniforms that SceneView should set set up on each frame.*/ |
|---|
| 165 | int getActiveUniforms() const { return _activeUniforms; } |
|---|
| 166 | |
|---|
| 167 | void updateUniforms(); |
|---|
| 168 | |
|---|
| 169 | |
|---|
| 170 | typedef Options LightingMode; |
|---|
| 171 | |
|---|
| 172 | void setLightingMode(LightingMode mode); |
|---|
| 173 | LightingMode getLightingMode() const { return _lightingMode; } |
|---|
| 174 | |
|---|
| 175 | void setLight(osg::Light* light) { _light = light; } |
|---|
| 176 | osg::Light* getLight() { return _light.get(); } |
|---|
| 177 | const osg::Light* getLight() const { return _light.get(); } |
|---|
| 178 | |
|---|
| 179 | void setState(osg::State* state) { _renderInfo.setState(state); } |
|---|
| 180 | osg::State* getState() { return _renderInfo.getState(); } |
|---|
| 181 | const osg::State* getState() const { return _renderInfo.getState(); } |
|---|
| 182 | |
|---|
| 183 | void setView(osg::View* view) { _camera->setView(view); } |
|---|
| 184 | osg::View* getView() { return _camera->getView(); } |
|---|
| 185 | const osg::View* getView() const { return _camera->getView(); } |
|---|
| 186 | |
|---|
| 187 | void setRenderInfo(osg::RenderInfo& renderInfo) { _renderInfo = renderInfo; } |
|---|
| 188 | osg::RenderInfo& getRenderInfo() { return _renderInfo; } |
|---|
| 189 | const osg::RenderInfo& getRenderInfo() const { return _renderInfo; } |
|---|
| 190 | |
|---|
| 191 | |
|---|
| 192 | |
|---|
| 193 | /** Set the projection matrix. Can be thought of as setting the lens of a camera. */ |
|---|
| 194 | inline void setProjectionMatrix(const osg::Matrixf& matrix) { _camera->setProjectionMatrix(matrix); } |
|---|
| 195 | |
|---|
| 196 | /** Set the projection matrix. Can be thought of as setting the lens of a camera. */ |
|---|
| 197 | inline void setProjectionMatrix(const osg::Matrixd& matrix) { _camera->setProjectionMatrix(matrix); } |
|---|
| 198 | |
|---|
| 199 | /** Set to an orthographic projection. See OpenGL glOrtho documentation for further details.*/ |
|---|
| 200 | void setProjectionMatrixAsOrtho(double left, double right, |
|---|
| 201 | double bottom, double top, |
|---|
| 202 | double zNear, double zFar); |
|---|
| 203 | |
|---|
| 204 | /** Set to a 2D orthographic projection. See OpenGL glOrtho2D documentation for further details.*/ |
|---|
| 205 | void setProjectionMatrixAsOrtho2D(double left, double right, |
|---|
| 206 | double bottom, double top); |
|---|
| 207 | |
|---|
| 208 | /** Set to a perspective projection. See OpenGL glFrustum documentation for further details.*/ |
|---|
| 209 | void setProjectionMatrixAsFrustum(double left, double right, |
|---|
| 210 | double bottom, double top, |
|---|
| 211 | double zNear, double zFar); |
|---|
| 212 | |
|---|
| 213 | /** Create a symmetrical perspective projection, See OpenGL gluPerspective documentation for further details. |
|---|
| 214 | * Aspect ratio is defined as width/height.*/ |
|---|
| 215 | void setProjectionMatrixAsPerspective(double fovy,double aspectRatio, |
|---|
| 216 | double zNear, double zFar); |
|---|
| 217 | |
|---|
| 218 | /** Get the projection matrix.*/ |
|---|
| 219 | osg::Matrixd& getProjectionMatrix() { return _camera->getProjectionMatrix(); } |
|---|
| 220 | |
|---|
| 221 | /** Get the const projection matrix.*/ |
|---|
| 222 | const osg::Matrixd& getProjectionMatrix() const { return _camera->getProjectionMatrix(); } |
|---|
| 223 | |
|---|
| 224 | /** Get the orthographic settings of the orthographic projection matrix. |
|---|
| 225 | * Returns false if matrix is not an orthographic matrix, where parameter values are undefined.*/ |
|---|
| 226 | bool getProjectionMatrixAsOrtho(double& left, double& right, |
|---|
| 227 | double& bottom, double& top, |
|---|
| 228 | double& zNear, double& zFar) const; |
|---|
| 229 | |
|---|
| 230 | /** Get the frustum setting of a perspective projection matrix. |
|---|
| 231 | * Returns false if matrix is not a perspective matrix, where parameter values are undefined.*/ |
|---|
| 232 | bool getProjectionMatrixAsFrustum(double& left, double& right, |
|---|
| 233 | double& bottom, double& top, |
|---|
| 234 | double& zNear, double& zFar) const; |
|---|
| 235 | |
|---|
| 236 | /** Get the frustum setting of a symmetric perspective projection matrix. |
|---|
| 237 | * Returns false if matrix is not a perspective matrix, where parameter values are undefined. |
|---|
| 238 | * Note, if matrix is not a symmetric perspective matrix then the shear will be lost. |
|---|
| 239 | * Asymmetric matrices occur when stereo, power walls, caves and reality center display are used. |
|---|
| 240 | * In these configurations one should use the 'getProjectionMatrixAsFrustum' method instead.*/ |
|---|
| 241 | bool getProjectionMatrixAsPerspective(double& fovy,double& aspectRatio, |
|---|
| 242 | double& zNear, double& zFar) const; |
|---|
| 243 | |
|---|
| 244 | |
|---|
| 245 | /** Set the view matrix. Can be thought of as setting the position of the world relative to the camera in camera coordinates. */ |
|---|
| 246 | inline void setViewMatrix(const osg::Matrixf& matrix) { _camera->setViewMatrix(matrix); } |
|---|
| 247 | |
|---|
| 248 | /** Set the view matrix. Can be thought of as setting the position of the world relative to the camera in camera coordinates. */ |
|---|
| 249 | inline void setViewMatrix(const osg::Matrixd& matrix) { _camera->setViewMatrix(matrix); } |
|---|
| 250 | |
|---|
| 251 | /** Set the position and orientation of view matrix, using the same convention as gluLookAt. */ |
|---|
| 252 | void setViewMatrixAsLookAt(const osg::Vec3& eye,const osg::Vec3& center,const osg::Vec3& up); |
|---|
| 253 | |
|---|
| 254 | /** Get the view matrix. */ |
|---|
| 255 | osg::Matrixd& getViewMatrix() { return _camera->getViewMatrix(); } |
|---|
| 256 | |
|---|
| 257 | /** Get the const view matrix. */ |
|---|
| 258 | const osg::Matrixd& getViewMatrix() const { return _camera->getViewMatrix(); } |
|---|
| 259 | |
|---|
| 260 | /** Get the position and orientation of a modelview matrix, using the same convention as gluLookAt. */ |
|---|
| 261 | void getViewMatrixAsLookAt(osg::Vec3& eye,osg::Vec3& center,osg::Vec3& up,float lookDistance=1.0f) const; |
|---|
| 262 | |
|---|
| 263 | |
|---|
| 264 | |
|---|
| 265 | |
|---|
| 266 | void setInitVisitor(osg::NodeVisitor* av) { _initVisitor = av; } |
|---|
| 267 | osg::NodeVisitor* getInitVisitor() { return _initVisitor.get(); } |
|---|
| 268 | const osg::NodeVisitor* getInitVisitor() const { return _initVisitor.get(); } |
|---|
| 269 | |
|---|
| 270 | |
|---|
| 271 | void setUpdateVisitor(osg::NodeVisitor* av) { _updateVisitor = av; } |
|---|
| 272 | osg::NodeVisitor* getUpdateVisitor() { return _updateVisitor.get(); } |
|---|
| 273 | const osg::NodeVisitor* getUpdateVisitor() const { return _updateVisitor.get(); } |
|---|
| 274 | |
|---|
| 275 | |
|---|
| 276 | void setCullVisitor(osgUtil::CullVisitor* cv) { _cullVisitor = cv; } |
|---|
| 277 | osgUtil::CullVisitor* getCullVisitor() { return _cullVisitor.get(); } |
|---|
| 278 | const osgUtil::CullVisitor* getCullVisitor() const { return _cullVisitor.get(); } |
|---|
| 279 | |
|---|
| 280 | void setCullVisitorLeft(osgUtil::CullVisitor* cv) { _cullVisitorLeft = cv; } |
|---|
| 281 | osgUtil::CullVisitor* getCullVisitorLeft() { return _cullVisitorLeft.get(); } |
|---|
| 282 | const osgUtil::CullVisitor* getCullVisitorLeft() const { return _cullVisitorLeft.get(); } |
|---|
| 283 | |
|---|
| 284 | void setCullVisitorRight(osgUtil::CullVisitor* cv) { _cullVisitorRight = cv; } |
|---|
| 285 | osgUtil::CullVisitor* getCullVisitorRight() { return _cullVisitorRight.get(); } |
|---|
| 286 | const osgUtil::CullVisitor* getCullVisitorRight() const { return _cullVisitorRight.get(); } |
|---|
| 287 | |
|---|
| 288 | void setCollectOccludersVisitor(osg::CollectOccludersVisitor* cov) { _collectOccludersVisitor = cov; } |
|---|
| 289 | osg::CollectOccludersVisitor* getCollectOccludersVisitor() { return _collectOccludersVisitor.get(); } |
|---|
| 290 | const osg::CollectOccludersVisitor* getCollectOccludersVisitor() const { return _collectOccludersVisitor.get(); } |
|---|
| 291 | |
|---|
| 292 | |
|---|
| 293 | void setStateGraph(osgUtil::StateGraph* rg) { _stateGraph = rg; } |
|---|
| 294 | osgUtil::StateGraph* getStateGraph() { return _stateGraph.get(); } |
|---|
| 295 | const osgUtil::StateGraph* getStateGraph() const { return _stateGraph.get(); } |
|---|
| 296 | |
|---|
| 297 | void setStateGraphLeft(osgUtil::StateGraph* rg) { _stateGraphLeft = rg; } |
|---|
| 298 | osgUtil::StateGraph* getStateGraphLeft() { return _stateGraphLeft.get(); } |
|---|
| 299 | const osgUtil::StateGraph* getStateGraphLeft() const { return _stateGraphLeft.get(); } |
|---|
| 300 | |
|---|
| 301 | void setStateGraphRight(osgUtil::StateGraph* rg) { _stateGraphRight = rg; } |
|---|
| 302 | osgUtil::StateGraph* getStateGraphRight() { return _stateGraphRight.get(); } |
|---|
| 303 | const osgUtil::StateGraph* getStateGraphRight() const { return _stateGraphRight.get(); } |
|---|
| 304 | |
|---|
| 305 | |
|---|
| 306 | void setRenderStage(osgUtil::RenderStage* rs) { _renderStage = rs; } |
|---|
| 307 | osgUtil::RenderStage* getRenderStage() { return _renderStage.get(); } |
|---|
| 308 | const osgUtil::RenderStage* getRenderStage() const { return _renderStage.get(); } |
|---|
| 309 | |
|---|
| 310 | void setRenderStageLeft(osgUtil::RenderStage* rs) { _renderStageLeft = rs; } |
|---|
| 311 | osgUtil::RenderStage* getRenderStageLeft() { return _renderStageLeft.get(); } |
|---|
| 312 | const osgUtil::RenderStage* getRenderStageLeft() const { return _renderStageLeft.get(); } |
|---|
| 313 | |
|---|
| 314 | void setRenderStageRight(osgUtil::RenderStage* rs) { _renderStageRight = rs; } |
|---|
| 315 | osgUtil::RenderStage* getRenderStageRight() { return _renderStageRight.get(); } |
|---|
| 316 | const osgUtil::RenderStage* getRenderStageRight() const { return _renderStageRight.get(); } |
|---|
| 317 | |
|---|
| 318 | /** search through any pre and post RenderStages that reference a Camera, and take a reference to each of these cameras to prevent them being deleted while they are still be used by the drawing thread.*/ |
|---|
| 319 | void collateReferencesToDependentCameras(); |
|---|
| 320 | |
|---|
| 321 | /** clear the refence to any any dependent cameras.*/ |
|---|
| 322 | void clearReferencesToDependentCameras(); |
|---|
| 323 | |
|---|
| 324 | |
|---|
| 325 | /** Set the draw buffer value used at the start of each frame draw. Note, overridden in quad buffer stereo mode */ |
|---|
| 326 | void setDrawBufferValue( GLenum drawBufferValue ) { _camera->setDrawBuffer(drawBufferValue); } |
|---|
| 327 | |
|---|
| 328 | /** Get the draw buffer value used at the start of each frame draw. */ |
|---|
| 329 | GLenum getDrawBufferValue() const { return _camera->getDrawBuffer(); } |
|---|
| 330 | |
|---|
| 331 | |
|---|
| 332 | /** FusionDistanceMode is used only when working in stereo.*/ |
|---|
| 333 | enum FusionDistanceMode |
|---|
| 334 | { |
|---|
| 335 | /** Use fusion distance from the value set on the SceneView.*/ |
|---|
| 336 | USE_FUSION_DISTANCE_VALUE, |
|---|
| 337 | /** Compute the fusion distance by multiplying the screen distance by the fusion distance value.*/ |
|---|
| 338 | PROPORTIONAL_TO_SCREEN_DISTANCE |
|---|
| 339 | }; |
|---|
| 340 | |
|---|
| 341 | /** Set the FusionDistanceMode and Value. Note, is used only when working in stereo.*/ |
|---|
| 342 | void setFusionDistance(FusionDistanceMode mode,float value=1.0f) |
|---|
| 343 | { |
|---|
| 344 | _fusionDistanceMode = mode; |
|---|
| 345 | _fusionDistanceValue = value; |
|---|
| 346 | } |
|---|
| 347 | |
|---|
| 348 | /** Get the FusionDistanceMode.*/ |
|---|
| 349 | FusionDistanceMode getFusionDistanceMode() const { return _fusionDistanceMode; } |
|---|
| 350 | |
|---|
| 351 | /** Get the FusionDistanceValue. Note, only used for USE_FUSION_DISTANCE_VALUE & PROPORTIONAL_TO_SCREEN_DISTANCE modes.*/ |
|---|
| 352 | float getFusionDistanceValue() const { return _fusionDistanceValue; } |
|---|
| 353 | |
|---|
| 354 | |
|---|
| 355 | /** Set whether the draw method should call renderer->prioritizeTexture.*/ |
|---|
| 356 | void setPrioritizeTextures(bool pt) { _prioritizeTextures = pt; } |
|---|
| 357 | |
|---|
| 358 | /** Get whether the draw method should call renderer->prioritizeTexture.*/ |
|---|
| 359 | bool getPrioritizeTextures() const { return _prioritizeTextures; } |
|---|
| 360 | |
|---|
| 361 | /** Callback for overidding the default method for compute the offset projection and view matrices.*/ |
|---|
| 362 | struct ComputeStereoMatricesCallback : public osg::Referenced |
|---|
| 363 | { |
|---|
| 364 | virtual osg::Matrixd computeLeftEyeProjection(const osg::Matrixd& projection) const = 0; |
|---|
| 365 | virtual osg::Matrixd computeLeftEyeView(const osg::Matrixd& view) const = 0; |
|---|
| 366 | |
|---|
| 367 | virtual osg::Matrixd computeRightEyeProjection(const osg::Matrixd& projection) const = 0; |
|---|
| 368 | virtual osg::Matrixd computeRightEyeView(const osg::Matrixd& view) const = 0; |
|---|
| 369 | }; |
|---|
| 370 | |
|---|
| 371 | void setComputeStereoMatricesCallback(ComputeStereoMatricesCallback* callback) { _computeStereoMatricesCallback=callback; } |
|---|
| 372 | ComputeStereoMatricesCallback* getComputeStereoMatricesCallback() { return _computeStereoMatricesCallback.get(); } |
|---|
| 373 | const ComputeStereoMatricesCallback* getComputeStereoMatricesCallback() const { return _computeStereoMatricesCallback.get(); } |
|---|
| 374 | |
|---|
| 375 | /** Calculate the object coordinates of a point in window coordinates. |
|---|
| 376 | Note, current implementation requires that SceneView::draw() has been previously called |
|---|
| 377 | for projectWindowIntoObject to produce valid values. Consistent with OpenGL, |
|---|
| 378 | window coordinates are calculated relative to the bottom left of the window. |
|---|
| 379 | Returns true on successful projection. |
|---|
| 380 | */ |
|---|
| 381 | bool projectWindowIntoObject(const osg::Vec3& window,osg::Vec3& object) const; |
|---|
| 382 | |
|---|
| 383 | /** Calculate the object coordinates of a window x,y when projected onto the near and far planes. |
|---|
| 384 | Note, current implementation requires that SceneView::draw() has been previously called |
|---|
| 385 | for projectWindowIntoObject to produce valid values. Consistent with OpenGL, |
|---|
| 386 | window coordinates are calculated relative to the bottom left of the window. |
|---|
| 387 | Returns true on successful projection. |
|---|
| 388 | */ |
|---|
| 389 | bool projectWindowXYIntoObject(int x,int y,osg::Vec3& near_point,osg::Vec3& far_point) const; |
|---|
| 390 | |
|---|
| 391 | /** Calculate the window coordinates of a point in object coordinates. |
|---|
| 392 | Note, current implementation requires that SceneView::draw() has been previously called |
|---|
| 393 | for projectWindowIntoObject to produce valid values. Consistent with OpenGL, |
|---|
| 394 | window coordinates are calculated relative to the bottom left of the window, |
|---|
| 395 | whereas window API's normally have the top left as the origin, |
|---|
| 396 | so you may need to pass in (mouseX,window_height-mouseY,...). |
|---|
| 397 | Returns true on successful projection. |
|---|
| 398 | */ |
|---|
| 399 | bool projectObjectIntoWindow(const osg::Vec3& object,osg::Vec3& window) const; |
|---|
| 400 | |
|---|
| 401 | |
|---|
| 402 | /** Set the frame stamp for the current frame.*/ |
|---|
| 403 | inline void setFrameStamp(osg::FrameStamp* fs) { _frameStamp = fs; } |
|---|
| 404 | |
|---|
| 405 | /** Get the frame stamp for the current frame.*/ |
|---|
| 406 | inline const osg::FrameStamp* getFrameStamp() const { return _frameStamp.get(); } |
|---|
| 407 | |
|---|
| 408 | |
|---|
| 409 | |
|---|
| 410 | |
|---|
| 411 | inline osg::Matrixd computeLeftEyeProjection(const osg::Matrixd& projection) const |
|---|
| 412 | { |
|---|
| 413 | if (_computeStereoMatricesCallback.valid()) return _computeStereoMatricesCallback->computeLeftEyeProjection(projection); |
|---|
| 414 | else return computeLeftEyeProjectionImplementation(projection); |
|---|
| 415 | } |
|---|
| 416 | |
|---|
| 417 | inline osg::Matrixd computeLeftEyeView(const osg::Matrixd& view) const |
|---|
| 418 | { |
|---|
| 419 | if (_computeStereoMatricesCallback.valid()) return _computeStereoMatricesCallback->computeLeftEyeView(view); |
|---|
| 420 | else return computeLeftEyeViewImplementation(view); |
|---|
| 421 | } |
|---|
| 422 | |
|---|
| 423 | inline osg::Matrixd computeRightEyeProjection(const osg::Matrixd& projection) const |
|---|
| 424 | { |
|---|
| 425 | if (_computeStereoMatricesCallback.valid()) return _computeStereoMatricesCallback->computeRightEyeProjection(projection); |
|---|
| 426 | else return computeRightEyeProjectionImplementation(projection); |
|---|
| 427 | } |
|---|
| 428 | |
|---|
| 429 | inline osg::Matrixd computeRightEyeView(const osg::Matrixd& view) const |
|---|
| 430 | { |
|---|
| 431 | if (_computeStereoMatricesCallback.valid()) return _computeStereoMatricesCallback->computeRightEyeView(view); |
|---|
| 432 | else return computeRightEyeViewImplementation(view); |
|---|
| 433 | } |
|---|
| 434 | |
|---|
| 435 | virtual osg::Matrixd computeLeftEyeProjectionImplementation(const osg::Matrixd& projection) const; |
|---|
| 436 | virtual osg::Matrixd computeLeftEyeViewImplementation(const osg::Matrixd& view) const; |
|---|
| 437 | |
|---|
| 438 | virtual osg::Matrixd computeRightEyeProjectionImplementation(const osg::Matrixd& projection) const; |
|---|
| 439 | virtual osg::Matrixd computeRightEyeViewImplementation(const osg::Matrixd& view) const; |
|---|
| 440 | |
|---|
| 441 | /** Inherit the local cull settings variable from specified CullSettings object, according to the inheritance mask.*/ |
|---|
| 442 | virtual void inheritCullSettings(const osg::CullSettings& settings) { inheritCullSettings(settings, _inheritanceMask); } |
|---|
| 443 | |
|---|
| 444 | /** Inherit the local cull settings variable from specified CullSettings object, according to the inheritance mask.*/ |
|---|
| 445 | virtual void inheritCullSettings(const osg::CullSettings& settings, unsigned int inheritanceMask); |
|---|
| 446 | |
|---|
| 447 | |
|---|
| 448 | /** Do init traversal of attached scene graph using Init NodeVisitor. |
|---|
| 449 | * The init traversal is called once for each SceneView, and should |
|---|
| 450 | * be used to compile display lists, texture objects and intialize data |
|---|
| 451 | * not otherwise intialized during scene graph loading. Note, is |
|---|
| 452 | * called automatically by update & cull if it hasn't already been called |
|---|
| 453 | * elsewhere. Also init() should only ever be called within a valid |
|---|
| 454 | * graphics context.*/ |
|---|
| 455 | virtual void init(); |
|---|
| 456 | |
|---|
| 457 | /** Do app traversal of attached scene graph using App NodeVisitor.*/ |
|---|
| 458 | virtual void update(); |
|---|
| 459 | |
|---|
| 460 | /** Do cull traversal of attached scene graph using Cull NodeVisitor.*/ |
|---|
| 461 | virtual void cull(); |
|---|
| 462 | |
|---|
| 463 | /** Do draw traversal of draw bins generated by cull traversal.*/ |
|---|
| 464 | virtual void draw(); |
|---|
| 465 | |
|---|
| 466 | /** Compute the number of dynamic objects that will be held in the rendering backend */ |
|---|
| 467 | unsigned int getDynamicObjectCount() const { return _dynamicObjectCount; } |
|---|
| 468 | |
|---|
| 469 | /** Release all OpenGL objects from the scene graph, such as texture objects, display lists, etc. |
|---|
| 470 | * These released scene graphs are placed in the respective delete GLObjects cache, and |
|---|
| 471 | * then need to be deleted in OpenGL by SceneView::flushAllDeleteGLObjects(). */ |
|---|
| 472 | virtual void releaseAllGLObjects(); |
|---|
| 473 | |
|---|
| 474 | /** Flush all deleted OpenGL objects, such as texture objects, display lists, etc.*/ |
|---|
| 475 | virtual void flushAllDeletedGLObjects(); |
|---|
| 476 | |
|---|
| 477 | /** Flush deleted OpenGL objects, such as texture objects, display lists, etc., within the specified available time.*/ |
|---|
| 478 | virtual void flushDeletedGLObjects(double& availableTime); |
|---|
| 479 | |
|---|
| 480 | /** Extract stats for current draw list. */ |
|---|
| 481 | bool getStats(Statistics& primStats); |
|---|
| 482 | |
|---|
| 483 | /** Set whether the SceneView should automatically call flushDeletedObjects() on each new frame.*/ |
|---|
| 484 | void setAutomaticFlush(bool automaticFlush) { _automaticFlush = automaticFlush; } |
|---|
| 485 | bool getAutomaticFlush() const { return _automaticFlush; } |
|---|
| 486 | |
|---|
| 487 | protected: |
|---|
| 488 | |
|---|
| 489 | virtual ~SceneView(); |
|---|
| 490 | |
|---|
| 491 | /** Do cull traversal of attached scene graph using Cull NodeVisitor. Return true if computeNearFar has been done during the cull traversal.*/ |
|---|
| 492 | virtual bool cullStage(const osg::Matrixd& projection,const osg::Matrixd& modelview,osgUtil::CullVisitor* cullVisitor, osgUtil::StateGraph* rendergraph, osgUtil::RenderStage* renderStage, osg::Viewport *viewport); |
|---|
| 493 | |
|---|
| 494 | void computeLeftEyeViewport(const osg::Viewport *viewport); |
|---|
| 495 | void computeRightEyeViewport(const osg::Viewport *viewport); |
|---|
| 496 | |
|---|
| 497 | const osg::Matrix computeMVPW() const; |
|---|
| 498 | |
|---|
| 499 | void clearArea(int x,int y,int width,int height,const osg::Vec4& color); |
|---|
| 500 | |
|---|
| 501 | osg::ref_ptr<osg::StateSet> _localStateSet; |
|---|
| 502 | osg::RenderInfo _renderInfo; |
|---|
| 503 | |
|---|
| 504 | bool _initCalled; |
|---|
| 505 | osg::ref_ptr<osg::NodeVisitor> _initVisitor; |
|---|
| 506 | osg::ref_ptr<osg::NodeVisitor> _updateVisitor; |
|---|
| 507 | osg::ref_ptr<osgUtil::CullVisitor> _cullVisitor; |
|---|
| 508 | osg::ref_ptr<osgUtil::StateGraph> _stateGraph; |
|---|
| 509 | osg::ref_ptr<osgUtil::RenderStage> _renderStage; |
|---|
| 510 | |
|---|
| 511 | osg::ref_ptr<ComputeStereoMatricesCallback> _computeStereoMatricesCallback; |
|---|
| 512 | |
|---|
| 513 | osg::ref_ptr<osgUtil::CullVisitor> _cullVisitorLeft; |
|---|
| 514 | osg::ref_ptr<osgUtil::StateGraph> _stateGraphLeft; |
|---|
| 515 | osg::ref_ptr<osgUtil::RenderStage> _renderStageLeft; |
|---|
| 516 | osg::ref_ptr<osg::Viewport> _viewportLeft; |
|---|
| 517 | |
|---|
| 518 | osg::ref_ptr<osgUtil::CullVisitor> _cullVisitorRight; |
|---|
| 519 | osg::ref_ptr<osgUtil::StateGraph> _stateGraphRight; |
|---|
| 520 | osg::ref_ptr<osgUtil::RenderStage> _renderStageRight; |
|---|
| 521 | osg::ref_ptr<osg::Viewport> _viewportRight; |
|---|
| 522 | |
|---|
| 523 | osg::ref_ptr<osg::CollectOccludersVisitor> _collectOccludersVisitor; |
|---|
| 524 | |
|---|
| 525 | osg::ref_ptr<osg::FrameStamp> _frameStamp; |
|---|
| 526 | |
|---|
| 527 | osg::observer_ptr<osg::Camera> _camera; |
|---|
| 528 | osg::ref_ptr<osg::Camera> _cameraWithOwnership; |
|---|
| 529 | |
|---|
| 530 | osg::ref_ptr<osg::StateSet> _globalStateSet; |
|---|
| 531 | osg::ref_ptr<osg::Light> _light; |
|---|
| 532 | osg::ref_ptr<osg::DisplaySettings> _displaySettings; |
|---|
| 533 | |
|---|
| 534 | osg::ref_ptr<osg::StateSet> _secondaryStateSet; |
|---|
| 535 | |
|---|
| 536 | FusionDistanceMode _fusionDistanceMode; |
|---|
| 537 | float _fusionDistanceValue; |
|---|
| 538 | |
|---|
| 539 | LightingMode _lightingMode; |
|---|
| 540 | |
|---|
| 541 | bool _prioritizeTextures; |
|---|
| 542 | |
|---|
| 543 | bool _automaticFlush; |
|---|
| 544 | bool _requiresFlush; |
|---|
| 545 | |
|---|
| 546 | int _activeUniforms; |
|---|
| 547 | double _previousFrameTime; |
|---|
| 548 | double _previousSimulationTime; |
|---|
| 549 | |
|---|
| 550 | bool _redrawInterlacedStereoStencilMask; |
|---|
| 551 | int _interlacedStereoStencilWidth; |
|---|
| 552 | int _interlacedStereoStencilHeight; |
|---|
| 553 | |
|---|
| 554 | unsigned int _dynamicObjectCount; |
|---|
| 555 | }; |
|---|
| 556 | |
|---|
| 557 | } |
|---|
| 558 | |
|---|
| 559 | #endif |
|---|
| 560 | |
|---|