2012-03-22 01:36:20 +08:00
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2003-01-22 00:45:36 +08:00
*
2012-03-22 01:36:20 +08:00
* 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
2003-01-22 00:45:36 +08:00
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
2012-03-22 01:36:20 +08:00
*
2003-01-22 00:45:36 +08:00
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
2012-03-22 01:36:20 +08:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2003-01-22 00:45:36 +08:00
* OpenSceneGraph Public License for more details.
*/
2001-10-04 23:12:57 +08:00
2001-01-11 00:32:10 +08:00
#ifndef OSGUTIL_SCENEVIEW
#define OSGUTIL_SCENEVIEW 1
#include <osg/Node>
2001-09-20 05:08:56 +08:00
#include <osg/StateSet>
2001-01-11 00:32:10 +08:00
#include <osg/Light>
2001-09-22 10:42:08 +08:00
#include <osg/FrameStamp>
2001-12-22 06:48:19 +08:00
#include <osg/DisplaySettings>
2003-12-12 00:46:45 +08:00
#include <osg/CollectOccludersVisitor>
2004-04-30 23:35:31 +08:00
#include <osg/CullSettings>
2006-11-27 22:52:07 +08:00
#include <osg/Camera>
2002-04-01 00:40:44 +08:00
2002-04-11 16:24:55 +08:00
#include <osgUtil/CullVisitor>
2001-01-11 00:32:10 +08:00
namespace osgUtil {
/**
2008-05-08 17:16:24 +08:00
* SceneView is deprecated, and is now just kept for backwards compatibility.
* It is recommend that you use osgViewer::Viewer/Composite in combination
* with osgViewer::GraphicsWindowEmbedded for embedded rendering support as
* this provides a greater range of functionality and consistency of API.
2001-01-11 00:32:10 +08:00
*/
2006-12-20 00:00:51 +08:00
class OSGUTIL_EXPORT SceneView : public osg::Object, public osg::CullSettings
2001-01-11 00:32:10 +08:00
{
public:
2001-09-28 20:36:40 +08:00
/** Construct a default scene view.*/
2001-12-22 06:48:19 +08:00
SceneView(osg::DisplaySettings* ds=NULL);
2001-01-11 00:32:10 +08:00
2006-12-20 00:00:51 +08:00
SceneView(const SceneView& sceneview, const osg::CopyOp& copyop = osg::CopyOp());
META_Object(osgUtil, SceneView);
2004-07-20 18:17:22 +08:00
enum Options
{
NO_SCENEVIEW_LIGHT = 0x0,
HEADLIGHT = 0x1,
SKY_LIGHT = 0x2,
COMPILE_GLOBJECTS_AT_INIT = 0x4,
2013-07-02 17:27:14 +08:00
APPLY_GLOBAL_DEFAULTS = 0x8,
2013-09-10 21:29:28 +08:00
CLEAR_GLOBAL_STATESET = 0x10,
2004-07-20 18:17:22 +08:00
STANDARD_SETTINGS = HEADLIGHT |
2013-07-02 17:27:14 +08:00
COMPILE_GLOBJECTS_AT_INIT |
APPLY_GLOBAL_DEFAULTS |
CLEAR_GLOBAL_STATESET
2004-07-20 18:17:22 +08:00
};
2007-05-26 23:49:35 +08:00
/* Set defaults. */
virtual void setDefaults() { setDefaults(STANDARD_SETTINGS); }
2001-09-22 10:42:08 +08:00
/** Set scene view to use default global state, light, camera
* and render visitor.
2004-09-27 02:39:34 +08:00
*/
2007-05-26 23:49:35 +08:00
virtual void setDefaults(unsigned int options);
2001-09-22 10:42:08 +08:00
2005-10-28 21:11:56 +08:00
/** Set the camera used to represent the camera view of this SceneView.*/
2007-07-28 18:28:40 +08:00
void setCamera(osg::Camera* camera, bool assumeOwnershipOfCamera = true);
2005-10-28 21:11:56 +08:00
/** Get the camera used to represent the camera view of this SceneView.*/
2006-11-27 22:52:07 +08:00
osg::Camera* getCamera() { return _camera.get(); }
2005-10-28 21:11:56 +08:00
/** Get the const camera used to represent the camera view of this SceneView.*/
2006-11-27 22:52:07 +08:00
const osg::Camera* getCamera() const { return _camera.get(); }
2005-10-28 21:11:56 +08:00
2004-09-27 02:39:34 +08:00
/** Set the data to view. The data will typically be
2001-01-11 00:32:10 +08:00
* an osg::Scene but can be any osg::Node type.
*/
2005-10-28 21:11:56 +08:00
void setSceneData(osg::Node* node);
2012-03-22 01:36:20 +08:00
2004-09-27 02:39:34 +08:00
/** Get the scene data to view. The data will typically be
2001-01-11 00:32:10 +08:00
* an osg::Scene but can be any osg::Node type.
*/
2005-10-28 21:11:56 +08:00
osg::Node* getSceneData(unsigned int childNo=0) { return (_camera->getNumChildren()>childNo) ? _camera->getChild(childNo) : 0; }
2001-01-11 00:32:10 +08:00
2001-09-20 05:08:56 +08:00
/** Get the const scene data which to view. The data will typically be
* an osg::Scene but can be any osg::Node type.
*/
2005-10-28 21:11:56 +08:00
const osg::Node* getSceneData(unsigned int childNo=0) const { return (_camera->getNumChildren()>childNo) ? _camera->getChild(childNo) : 0; }
2012-03-22 01:36:20 +08:00
2005-10-28 21:11:56 +08:00
/** Get the number of scene data subgraphs added to the SceneView's camera.*/
unsigned int getNumSceneData() const { return _camera->getNumChildren(); }
2001-09-20 05:08:56 +08:00
2004-09-27 02:39:34 +08:00
/** Set the viewport of the scene view to use specified osg::Viewport. */
2005-10-28 21:11:56 +08:00
void setViewport(osg::Viewport* viewport) { _camera->setViewport(viewport); }
2001-09-22 10:42:08 +08:00
/** Set the viewport of the scene view to specified dimensions. */
2005-10-28 21:11:56 +08:00
void setViewport(int x,int y,int width,int height) { _camera->setViewport(x,y,width,height); }
2001-09-22 10:42:08 +08:00
/** Get the viewport. */
2005-10-28 21:11:56 +08:00
osg::Viewport* getViewport() { return (_camera->getViewport()!=0) ? _camera->getViewport() : 0; }
2001-09-22 10:42:08 +08:00
2005-10-28 21:11:56 +08:00
/** Get the const viewport. */
const osg::Viewport* getViewport() const { return (_camera->getViewport()!=0) ? _camera->getViewport() : 0; }
2012-03-22 01:36:20 +08:00
2001-12-22 06:48:19 +08:00
/** Set the DisplaySettings. */
inline void setDisplaySettings(osg::DisplaySettings* vs) { _displaySettings = vs; }
2012-03-22 01:36:20 +08:00
2002-03-28 00:31:25 +08:00
/** Get the const DisplaySettings */
2001-12-22 06:48:19 +08:00
inline const osg::DisplaySettings* getDisplaySettings() const { return _displaySettings.get(); }
2002-03-28 00:31:25 +08:00
/** Get the DisplaySettings */
inline osg::DisplaySettings* getDisplaySettings() { return _displaySettings.get(); }
2001-09-22 10:42:08 +08:00
2001-01-11 00:32:10 +08:00
2004-04-28 03:09:58 +08:00
/** Set the color used in glClearColor().
Defaults to an off blue color.*/
2005-10-28 21:11:56 +08:00
void setClearColor(const osg::Vec4& color) { _camera->setClearColor(color); }
2008-03-31 19:44:31 +08:00
2004-09-27 02:39:34 +08:00
/** Get the color used in glClearColor.*/
2005-10-28 21:11:56 +08:00
const osg::Vec4& getClearColor() const { return _camera->getClearColor(); }
2012-03-22 01:36:20 +08:00
/** Manually set the redraw interlaced stereo stencil mask request flag to control whether to redraw the stencil buffer on the next frame.*/
2005-10-25 23:43:04 +08:00
void setRedrawInterlacedStereoStencilMask(bool flag) { _redrawInterlacedStereoStencilMask = flag; }
2012-03-22 01:36:20 +08:00
/** Get the redraw interlaced stereo stencil mask request flag.*/
2005-10-25 23:43:04 +08:00
bool getRedrawInterlacedStereoStencilMask() const { return _redrawInterlacedStereoStencilMask; }
2004-04-28 03:09:58 +08:00
2003-01-30 01:16:26 +08:00
void setGlobalStateSet(osg::StateSet* state) { _globalStateSet = state; }
osg::StateSet* getGlobalStateSet() { return _globalStateSet.get(); }
const osg::StateSet* getGlobalStateSet() const { return _globalStateSet.get(); }
2010-01-21 18:24:48 +08:00
void setSecondaryStateSet(osg::StateSet* state) { _secondaryStateSet = state; }
osg::StateSet* getSecondaryStateSet() { return _secondaryStateSet.get(); }
const osg::StateSet* getSecondaryStateSet() const { return _secondaryStateSet.get(); }
2003-01-30 01:16:26 +08:00
void setLocalStateSet(osg::StateSet* state) { _localStateSet = state; }
osg::StateSet* getLocalStateSet() { return _localStateSet.get(); }
const osg::StateSet* getLocalStateSet() const { return _localStateSet.get(); }
2012-03-22 01:36:20 +08:00
2005-05-05 20:30:54 +08:00
enum ActiveUniforms
{
2007-01-25 20:02:51 +08:00
FRAME_NUMBER_UNIFORM = 1,
FRAME_TIME_UNIFORM = 2,
DELTA_FRAME_TIME_UNIFORM = 4,
SIMULATION_TIME_UNIFORM = 8,
DELTA_SIMULATION_TIME_UNIFORM = 16,
VIEW_MATRIX_UNIFORM = 32,
VIEW_MATRIX_INVERSE_UNIFORM = 64,
2005-05-05 20:30:54 +08:00
DEFAULT_UNIFORMS = FRAME_NUMBER_UNIFORM |
FRAME_TIME_UNIFORM |
2005-05-06 18:32:31 +08:00
DELTA_FRAME_TIME_UNIFORM |
2007-01-25 20:02:51 +08:00
SIMULATION_TIME_UNIFORM |
DELTA_SIMULATION_TIME_UNIFORM |
2005-05-05 20:30:54 +08:00
VIEW_MATRIX_UNIFORM |
2005-10-25 17:23:21 +08:00
VIEW_MATRIX_INVERSE_UNIFORM,
2008-12-19 18:20:23 +08:00
ALL_UNIFORMS = 0x7FFFFFFF
2005-05-05 20:30:54 +08:00
};
2012-03-22 01:36:20 +08:00
/** Set the uniforms that SceneView should set set up on each frame.*/
2005-05-05 20:30:54 +08:00
void setActiveUniforms(int activeUniforms) { _activeUniforms = activeUniforms; }
2006-09-19 04:54:48 +08:00
/** Get the uniforms that SceneView should set set up on each frame.*/
2005-05-20 05:42:38 +08:00
int getActiveUniforms() const { return _activeUniforms; }
2005-05-05 20:30:54 +08:00
void updateUniforms();
2012-03-22 01:36:20 +08:00
2001-01-11 00:32:10 +08:00
2004-07-20 18:17:22 +08:00
typedef Options LightingMode;
2004-08-02 20:19:50 +08:00
2009-01-28 17:23:26 +08:00
void setLightingMode(LightingMode mode);
2001-01-11 00:32:10 +08:00
LightingMode getLightingMode() const { return _lightingMode; }
void setLight(osg::Light* light) { _light = light; }
2001-09-20 05:08:56 +08:00
osg::Light* getLight() { return _light.get(); }
const osg::Light* getLight() const { return _light.get(); }
2012-03-22 01:36:20 +08:00
2006-09-19 04:54:48 +08:00
void setState(osg::State* state) { _renderInfo.setState(state); }
osg::State* getState() { return _renderInfo.getState(); }
const osg::State* getState() const { return _renderInfo.getState(); }
2012-03-22 01:36:20 +08:00
2007-01-02 02:20:10 +08:00
void setView(osg::View* view) { _camera->setView(view); }
osg::View* getView() { return _camera->getView(); }
const osg::View* getView() const { return _camera->getView(); }
2001-12-03 06:20:46 +08:00
2006-09-19 04:54:48 +08:00
void setRenderInfo(osg::RenderInfo& renderInfo) { _renderInfo = renderInfo; }
osg::RenderInfo& getRenderInfo() { return _renderInfo; }
const osg::RenderInfo& getRenderInfo() const { return _renderInfo; }
2012-03-22 01:36:20 +08:00
2002-04-13 02:06:13 +08:00
2003-07-17 06:15:28 +08:00
2003-07-15 19:49:56 +08:00
/** Set the projection matrix. Can be thought of as setting the lens of a camera. */
2005-10-28 21:11:56 +08:00
inline void setProjectionMatrix(const osg::Matrixf& matrix) { _camera->setProjectionMatrix(matrix); }
2003-10-01 23:56:52 +08:00
/** Set the projection matrix. Can be thought of as setting the lens of a camera. */
2005-10-28 21:11:56 +08:00
inline void setProjectionMatrix(const osg::Matrixd& matrix) { _camera->setProjectionMatrix(matrix); }
2003-07-17 06:15:28 +08:00
2011-09-12 20:14:17 +08:00
/** Set to an orthographic projection. See OpenGL glOrtho documentation for further details.*/
2003-07-17 06:15:28 +08:00
void setProjectionMatrixAsOrtho(double left, double right,
double bottom, double top,
double zNear, double zFar);
/** Set to a 2D orthographic projection. See OpenGL glOrtho2D documentation for further details.*/
void setProjectionMatrixAsOrtho2D(double left, double right,
double bottom, double top);
/** Set to a perspective projection. See OpenGL glFrustum documentation for further details.*/
void setProjectionMatrixAsFrustum(double left, double right,
double bottom, double top,
double zNear, double zFar);
/** Create a symmetrical perspective projection, See OpenGL gluPerspective documentation for further details.
* Aspect ratio is defined as width/height.*/
void setProjectionMatrixAsPerspective(double fovy,double aspectRatio,
double zNear, double zFar);
2002-04-10 05:46:34 +08:00
2003-07-15 19:49:56 +08:00
/** Get the projection matrix.*/
2005-10-28 21:11:56 +08:00
osg::Matrixd& getProjectionMatrix() { return _camera->getProjectionMatrix(); }
2003-07-15 19:49:56 +08:00
/** Get the const projection matrix.*/
2005-10-28 21:11:56 +08:00
const osg::Matrixd& getProjectionMatrix() const { return _camera->getProjectionMatrix(); }
2003-07-15 19:49:56 +08:00
2012-03-22 01:36:20 +08:00
/** Get the orthographic settings of the orthographic projection matrix.
2003-09-29 21:14:34 +08:00
* Returns false if matrix is not an orthographic matrix, where parameter values are undefined.*/
bool getProjectionMatrixAsOrtho(double& left, double& right,
2003-07-17 06:15:28 +08:00
double& bottom, double& top,
2005-08-22 21:58:23 +08:00
double& zNear, double& zFar) const;
2003-07-17 06:15:28 +08:00
/** Get the frustum setting of a perspective projection matrix.
2003-09-29 21:14:34 +08:00
* Returns false if matrix is not a perspective matrix, where parameter values are undefined.*/
bool getProjectionMatrixAsFrustum(double& left, double& right,
2003-07-17 06:15:28 +08:00
double& bottom, double& top,
2005-08-22 21:58:23 +08:00
double& zNear, double& zFar) const;
2003-07-17 06:15:28 +08:00
2004-09-27 02:39:34 +08:00
/** Get the frustum setting of a symmetric perspective projection matrix.
2012-03-22 01:36:20 +08:00
* Returns false if matrix is not a perspective matrix, where parameter values are undefined.
2004-09-27 02:39:34 +08:00
* Note, if matrix is not a symmetric perspective matrix then the shear will be lost.
* Asymmetric matrices occur when stereo, power walls, caves and reality center display are used.
* In these configurations one should use the 'getProjectionMatrixAsFrustum' method instead.*/
2003-09-29 21:14:34 +08:00
bool getProjectionMatrixAsPerspective(double& fovy,double& aspectRatio,
2005-08-22 21:58:23 +08:00
double& zNear, double& zFar) const;
2003-09-29 21:14:34 +08:00
2003-07-15 19:49:56 +08:00
/** Set the view matrix. Can be thought of as setting the position of the world relative to the camera in camera coordinates. */
2005-10-28 21:11:56 +08:00
inline void setViewMatrix(const osg::Matrixf& matrix) { _camera->setViewMatrix(matrix); }
2012-03-22 01:36:20 +08:00
2003-10-01 23:56:52 +08:00
/** Set the view matrix. Can be thought of as setting the position of the world relative to the camera in camera coordinates. */
2005-10-28 21:11:56 +08:00
inline void setViewMatrix(const osg::Matrixd& matrix) { _camera->setViewMatrix(matrix); }
2003-07-17 06:15:28 +08:00
2012-03-29 23:08:15 +08:00
/** Set the position and orientation components of the view matrix, using the same convention as gluLookAt. */
2003-07-17 06:15:28 +08:00
void setViewMatrixAsLookAt(const osg::Vec3& eye,const osg::Vec3& center,const osg::Vec3& up);
2003-11-25 18:55:37 +08:00
/** Get the view matrix. */
2005-10-28 21:11:56 +08:00
osg::Matrixd& getViewMatrix() { return _camera->getViewMatrix(); }
2003-11-25 18:55:37 +08:00
/** Get the const view matrix. */
2005-10-28 21:11:56 +08:00
const osg::Matrixd& getViewMatrix() const { return _camera->getViewMatrix(); }
2003-11-25 18:55:37 +08:00
2012-03-29 23:08:15 +08:00
/** Get the position and orientation components of a modelview matrix, using the same convention as gluLookAt. */
2005-08-22 21:58:23 +08:00
void getViewMatrixAsLookAt(osg::Vec3& eye,osg::Vec3& center,osg::Vec3& up,float lookDistance=1.0f) const;
2003-11-25 18:55:37 +08:00
2003-07-15 19:49:56 +08:00
2012-03-22 01:36:20 +08:00
2001-10-21 04:26:36 +08:00
void setInitVisitor(osg::NodeVisitor* av) { _initVisitor = av; }
osg::NodeVisitor* getInitVisitor() { return _initVisitor.get(); }
const osg::NodeVisitor* getInitVisitor() const { return _initVisitor.get(); }
2003-08-30 07:04:42 +08:00
2002-12-19 23:55:40 +08:00
void setUpdateVisitor(osg::NodeVisitor* av) { _updateVisitor = av; }
osg::NodeVisitor* getUpdateVisitor() { return _updateVisitor.get(); }
const osg::NodeVisitor* getUpdateVisitor() const { return _updateVisitor.get(); }
2001-09-20 05:08:56 +08:00
2003-08-30 07:04:42 +08:00
2001-09-20 05:08:56 +08:00
void setCullVisitor(osgUtil::CullVisitor* cv) { _cullVisitor = cv; }
osgUtil::CullVisitor* getCullVisitor() { return _cullVisitor.get(); }
const osgUtil::CullVisitor* getCullVisitor() const { return _cullVisitor.get(); }
2003-08-30 07:04:42 +08:00
void setCullVisitorLeft(osgUtil::CullVisitor* cv) { _cullVisitorLeft = cv; }
osgUtil::CullVisitor* getCullVisitorLeft() { return _cullVisitorLeft.get(); }
const osgUtil::CullVisitor* getCullVisitorLeft() const { return _cullVisitorLeft.get(); }
void setCullVisitorRight(osgUtil::CullVisitor* cv) { _cullVisitorRight = cv; }
osgUtil::CullVisitor* getCullVisitorRight() { return _cullVisitorRight.get(); }
const osgUtil::CullVisitor* getCullVisitorRight() const { return _cullVisitorRight.get(); }
2012-03-22 01:36:20 +08:00
2007-07-11 23:51:17 +08:00
void setCollectOccludersVisitor(osg::CollectOccludersVisitor* cov) { _collectOccludersVisitor = cov; }
osg::CollectOccludersVisitor* getCollectOccludersVisitor() { return _collectOccludersVisitor.get(); }
const osg::CollectOccludersVisitor* getCollectOccludersVisitor() const { return _collectOccludersVisitor.get(); }
2003-08-30 07:04:42 +08:00
2008-06-06 21:21:57 +08:00
void setStateGraph(osgUtil::StateGraph* rg) { _stateGraph = rg; }
osgUtil::StateGraph* getStateGraph() { return _stateGraph.get(); }
const osgUtil::StateGraph* getStateGraph() const { return _stateGraph.get(); }
2001-09-20 05:08:56 +08:00
2008-06-06 21:21:57 +08:00
void setStateGraphLeft(osgUtil::StateGraph* rg) { _stateGraphLeft = rg; }
osgUtil::StateGraph* getStateGraphLeft() { return _stateGraphLeft.get(); }
const osgUtil::StateGraph* getStateGraphLeft() const { return _stateGraphLeft.get(); }
2003-08-30 07:04:42 +08:00
2008-06-06 21:21:57 +08:00
void setStateGraphRight(osgUtil::StateGraph* rg) { _stateGraphRight = rg; }
osgUtil::StateGraph* getStateGraphRight() { return _stateGraphRight.get(); }
const osgUtil::StateGraph* getStateGraphRight() const { return _stateGraphRight.get(); }
2003-08-30 07:04:42 +08:00
2001-09-20 05:08:56 +08:00
void setRenderStage(osgUtil::RenderStage* rs) { _renderStage = rs; }
osgUtil::RenderStage* getRenderStage() { return _renderStage.get(); }
const osgUtil::RenderStage* getRenderStage() const { return _renderStage.get(); }
2001-01-11 00:32:10 +08:00
2003-08-30 07:04:42 +08:00
void setRenderStageLeft(osgUtil::RenderStage* rs) { _renderStageLeft = rs; }
osgUtil::RenderStage* getRenderStageLeft() { return _renderStageLeft.get(); }
const osgUtil::RenderStage* getRenderStageLeft() const { return _renderStageLeft.get(); }
void setRenderStageRight(osgUtil::RenderStage* rs) { _renderStageRight = rs; }
osgUtil::RenderStage* getRenderStageRight() { return _renderStageRight.get(); }
const osgUtil::RenderStage* getRenderStageRight() const { return _renderStageRight.get(); }
2011-09-12 20:14:17 +08:00
/** 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.*/
2009-06-06 03:05:37 +08:00
void collateReferencesToDependentCameras();
2018-04-21 00:18:22 +08:00
/** clear the reference to any any dependent cameras.*/
2009-06-06 03:05:37 +08:00
void clearReferencesToDependentCameras();
2002-03-04 06:31:46 +08:00
2004-04-30 23:35:31 +08:00
/** Set the draw buffer value used at the start of each frame draw. Note, overridden in quad buffer stereo mode */
2007-01-02 02:20:10 +08:00
void setDrawBufferValue( GLenum drawBufferValue ) { _camera->setDrawBuffer(drawBufferValue); }
2002-07-03 03:53:18 +08:00
2004-04-30 23:35:31 +08:00
/** Get the draw buffer value used at the start of each frame draw. */
2007-01-02 02:20:10 +08:00
GLenum getDrawBufferValue() const { return _camera->getDrawBuffer(); }
2002-07-03 03:53:18 +08:00
2002-09-04 18:49:17 +08:00
/** FusionDistanceMode is used only when working in stereo.*/
enum FusionDistanceMode
{
/** Use fusion distance from the value set on the SceneView.*/
USE_FUSION_DISTANCE_VALUE,
2004-09-27 02:39:34 +08:00
/** Compute the fusion distance by multiplying the screen distance by the fusion distance value.*/
2002-09-04 18:49:17 +08:00
PROPORTIONAL_TO_SCREEN_DISTANCE
};
/** Set the FusionDistanceMode and Value. Note, is used only when working in stereo.*/
2002-09-12 22:29:59 +08:00
void setFusionDistance(FusionDistanceMode mode,float value=1.0f)
2003-10-17 18:25:59 +08:00
{
_fusionDistanceMode = mode;
_fusionDistanceValue = value;
}
2002-09-04 18:49:17 +08:00
/** Get the FusionDistanceMode.*/
FusionDistanceMode getFusionDistanceMode() const { return _fusionDistanceMode; }
/** Get the FusionDistanceValue. Note, only used for USE_FUSION_DISTANCE_VALUE & PROPORTIONAL_TO_SCREEN_DISTANCE modes.*/
float getFusionDistanceValue() const { return _fusionDistanceValue; }
2002-03-04 06:31:46 +08:00
2001-09-20 05:08:56 +08:00
2004-09-27 02:39:34 +08:00
/** Set whether the draw method should call renderer->prioritizeTexture.*/
2001-09-20 05:08:56 +08:00
void setPrioritizeTextures(bool pt) { _prioritizeTextures = pt; }
2012-03-22 01:36:20 +08:00
2004-09-27 02:39:34 +08:00
/** Get whether the draw method should call renderer->prioritizeTexture.*/
2001-09-20 05:08:56 +08:00
bool getPrioritizeTextures() const { return _prioritizeTextures; }
2004-09-27 02:39:34 +08:00
/** Callback for overidding the default method for compute the offset projection and view matrices.*/
2004-04-30 23:35:31 +08:00
struct ComputeStereoMatricesCallback : public osg::Referenced
{
virtual osg::Matrixd computeLeftEyeProjection(const osg::Matrixd& projection) const = 0;
virtual osg::Matrixd computeLeftEyeView(const osg::Matrixd& view) const = 0;
virtual osg::Matrixd computeRightEyeProjection(const osg::Matrixd& projection) const = 0;
virtual osg::Matrixd computeRightEyeView(const osg::Matrixd& view) const = 0;
};
2012-03-22 01:36:20 +08:00
2004-04-30 23:35:31 +08:00
void setComputeStereoMatricesCallback(ComputeStereoMatricesCallback* callback) { _computeStereoMatricesCallback=callback; }
ComputeStereoMatricesCallback* getComputeStereoMatricesCallback() { return _computeStereoMatricesCallback.get(); }
const ComputeStereoMatricesCallback* getComputeStereoMatricesCallback() const { return _computeStereoMatricesCallback.get(); }
2001-01-11 00:32:10 +08:00
2006-10-25 00:24:24 +08:00
/** Calculate the object coordinates of a point in window coordinates.
2001-01-11 00:32:10 +08:00
Note, current implementation requires that SceneView::draw() has been previously called
2011-09-12 20:14:17 +08:00
for projectWindowIntoObject to produce valid values. Consistent with OpenGL,
window coordinates are calculated relative to the bottom left of the window.
2001-01-11 00:32:10 +08:00
Returns true on successful projection.
*/
bool projectWindowIntoObject(const osg::Vec3& window,osg::Vec3& object) const;
2006-10-25 00:24:24 +08:00
/** Calculate the object coordinates of a window x,y when projected onto the near and far planes.
2001-01-11 00:32:10 +08:00
Note, current implementation requires that SceneView::draw() has been previously called
2011-09-12 20:14:17 +08:00
for projectWindowIntoObject to produce valid values. Consistent with OpenGL,
window coordinates are calculated relative to the bottom left of the window.
2001-01-11 00:32:10 +08:00
Returns true on successful projection.
*/
bool projectWindowXYIntoObject(int x,int y,osg::Vec3& near_point,osg::Vec3& far_point) const;
2006-10-25 00:24:24 +08:00
/** Calculate the window coordinates of a point in object coordinates.
2001-01-11 00:32:10 +08:00
Note, current implementation requires that SceneView::draw() has been previously called
2011-09-12 20:14:17 +08:00
for projectWindowIntoObject to produce valid values. Consistent with OpenGL,
window coordinates are calculated relative to the bottom left of the window,
2004-09-27 02:39:34 +08:00
whereas window API's normally have the top left as the origin,
2001-01-11 00:32:10 +08:00
so you may need to pass in (mouseX,window_height-mouseY,...).
Returns true on successful projection.
*/
bool projectObjectIntoWindow(const osg::Vec3& object,osg::Vec3& window) const;
2001-09-22 10:42:08 +08:00
/** Set the frame stamp for the current frame.*/
inline void setFrameStamp(osg::FrameStamp* fs) { _frameStamp = fs; }
2004-09-27 02:39:34 +08:00
/** Get the frame stamp for the current frame.*/
2015-09-25 18:09:27 +08:00
inline osg::FrameStamp* getFrameStamp() { return _frameStamp.get(); }
/** Get the const frame stamp for the current frame.*/
2001-09-22 10:42:08 +08:00
inline const osg::FrameStamp* getFrameStamp() const { return _frameStamp.get(); }
2003-10-01 23:56:52 +08:00
inline osg::Matrixd computeLeftEyeProjection(const osg::Matrixd& projection) const
{
if (_computeStereoMatricesCallback.valid()) return _computeStereoMatricesCallback->computeLeftEyeProjection(projection);
else return computeLeftEyeProjectionImplementation(projection);
}
inline osg::Matrixd computeLeftEyeView(const osg::Matrixd& view) const
{
if (_computeStereoMatricesCallback.valid()) return _computeStereoMatricesCallback->computeLeftEyeView(view);
else return computeLeftEyeViewImplementation(view);
}
2012-03-22 01:36:20 +08:00
2003-10-01 23:56:52 +08:00
inline osg::Matrixd computeRightEyeProjection(const osg::Matrixd& projection) const
{
if (_computeStereoMatricesCallback.valid()) return _computeStereoMatricesCallback->computeRightEyeProjection(projection);
else return computeRightEyeProjectionImplementation(projection);
}
inline osg::Matrixd computeRightEyeView(const osg::Matrixd& view) const
{
if (_computeStereoMatricesCallback.valid()) return _computeStereoMatricesCallback->computeRightEyeView(view);
else return computeRightEyeViewImplementation(view);
}
2013-04-15 22:21:32 +08:00
/** helper function for computing the left eye projection matrix.*/
2003-10-01 23:56:52 +08:00
virtual osg::Matrixd computeLeftEyeProjectionImplementation(const osg::Matrixd& projection) const;
2013-04-15 22:21:32 +08:00
/** helper function for computing the left eye view matrix.*/
2003-10-01 23:56:52 +08:00
virtual osg::Matrixd computeLeftEyeViewImplementation(const osg::Matrixd& view) const;
2013-04-15 22:21:32 +08:00
/** helper function for computing the right eye view matrix.*/
2003-10-01 23:56:52 +08:00
virtual osg::Matrixd computeRightEyeProjectionImplementation(const osg::Matrixd& projection) const;
2013-04-15 22:21:32 +08:00
/** helper function for computing the right eye view matrix.*/
2003-10-01 23:56:52 +08:00
virtual osg::Matrixd computeRightEyeViewImplementation(const osg::Matrixd& view) const;
2013-04-15 22:21:32 +08:00
2012-03-29 23:08:15 +08:00
/** Inherit the local cull settings variable from a specified CullSettings object, according to the inheritance mask.*/
2007-06-15 16:36:35 +08:00
virtual void inheritCullSettings(const osg::CullSettings& settings) { inheritCullSettings(settings, _inheritanceMask); }
2007-05-08 06:07:23 +08:00
2012-03-29 23:08:15 +08:00
/** Inherit the local cull settings variable from a specified CullSettings object, according to the inheritance mask.*/
2007-05-08 06:07:23 +08:00
virtual void inheritCullSettings(const osg::CullSettings& settings, unsigned int inheritanceMask);
2003-10-01 23:56:52 +08:00
2012-03-29 23:08:15 +08:00
/** Do init traversal of the attached scene graph using Init NodeVisitor.
2001-10-21 04:26:36 +08:00
* The init traversal is called once for each SceneView, and should
2017-08-16 00:23:49 +08:00
* be used to compile display lists, texture objects and initialize data
* not otherwise initialized during scene graph loading. Note, is
2004-09-27 02:39:34 +08:00
* called automatically by update & cull if it hasn't already been called
2001-10-21 04:26:36 +08:00
* elsewhere. Also init() should only ever be called within a valid
* graphics context.*/
virtual void init();
2001-09-22 10:42:08 +08:00
2012-03-29 23:08:15 +08:00
/** Do app traversal of the attached scene graph using App NodeVisitor.*/
2002-12-19 23:55:40 +08:00
virtual void update();
2001-09-20 05:08:56 +08:00
2012-03-29 23:08:15 +08:00
/** Do cull traversal of the attached scene graph using Cull NodeVisitor.*/
2001-01-11 00:32:10 +08:00
virtual void cull();
2001-09-20 05:08:56 +08:00
2001-10-21 04:26:36 +08:00
/** Do draw traversal of draw bins generated by cull traversal.*/
2001-01-11 00:32:10 +08:00
virtual void draw();
2012-03-22 01:36:20 +08:00
2007-02-01 06:24:20 +08:00
/** Compute the number of dynamic objects that will be held in the rendering backend */
unsigned int getDynamicObjectCount() const { return _dynamicObjectCount; }
2012-03-22 01:36:20 +08:00
2011-09-12 20:14:17 +08:00
/** Release all OpenGL objects from the scene graph, such as texture objects, display lists, etc.
* These released scene graphs are placed in the respective delete GLObjects cache, and
2004-09-24 04:01:40 +08:00
* then need to be deleted in OpenGL by SceneView::flushAllDeleteGLObjects(). */
virtual void releaseAllGLObjects();
2019-01-09 03:32:50 +08:00
virtual void resizeGLObjectBuffers(unsigned int maxSize);
virtual void releaseGLObjects(osg::State* = 0) const;
2011-09-12 20:14:17 +08:00
/** Flush all deleted OpenGL objects, such as texture objects, display lists, etc.*/
2004-09-22 05:33:52 +08:00
virtual void flushAllDeletedGLObjects();
2011-09-12 20:14:17 +08:00
/** Flush deleted OpenGL objects, such as texture objects, display lists, etc., within the specified available time.*/
2004-01-05 21:40:36 +08:00
virtual void flushDeletedGLObjects(double& availableTime);
2012-03-22 01:36:20 +08:00
2005-11-12 01:00:36 +08:00
/** Extract stats for current draw list. */
2010-12-10 23:27:19 +08:00
bool getStats(Statistics& primStats);
2011-09-12 20:14:17 +08:00
/** Set whether the SceneView should automatically call flushDeletedObjects() on each new frame.*/
2010-12-10 23:27:19 +08:00
void setAutomaticFlush(bool automaticFlush) { _automaticFlush = automaticFlush; }
bool getAutomaticFlush() const { return _automaticFlush; }
2005-11-12 01:00:36 +08:00
2013-04-18 17:47:28 +08:00
void setResetColorMaskToAllOn(bool enable) { _resetColorMaskToAllEnabled = enable; }
2013-09-05 18:23:05 +08:00
bool getResetColorMaskToAllOn() const { return _resetColorMaskToAllEnabled; }
2013-04-18 17:47:28 +08:00
2001-01-11 00:32:10 +08:00
protected:
virtual ~SceneView();
2007-07-02 21:17:47 +08:00
/** Do cull traversal of attached scene graph using Cull NodeVisitor. Return true if computeNearFar has been done during the cull traversal.*/
2008-06-19 22:29:38 +08:00
virtual bool cullStage(const osg::Matrixd& projection,const osg::Matrixd& modelview,osgUtil::CullVisitor* cullVisitor, osgUtil::StateGraph* rendergraph, osgUtil::RenderStage* renderStage, osg::Viewport *viewport);
2012-03-22 01:36:20 +08:00
2008-06-19 22:29:38 +08:00
void computeLeftEyeViewport(const osg::Viewport *viewport);
void computeRightEyeViewport(const osg::Viewport *viewport);
2002-02-14 21:26:37 +08:00
2002-04-16 19:41:32 +08:00
const osg::Matrix computeMVPW() const;
2002-04-16 23:31:46 +08:00
void clearArea(int x,int y,int width,int height,const osg::Vec4& color);
2003-01-30 01:16:26 +08:00
osg::ref_ptr<osg::StateSet> _localStateSet;
2006-09-19 04:54:48 +08:00
osg::RenderInfo _renderInfo;
2012-03-22 01:36:20 +08:00
2001-10-21 04:26:36 +08:00
bool _initCalled;
osg::ref_ptr<osg::NodeVisitor> _initVisitor;
2002-12-19 23:55:40 +08:00
osg::ref_ptr<osg::NodeVisitor> _updateVisitor;
2001-09-20 05:08:56 +08:00
osg::ref_ptr<osgUtil::CullVisitor> _cullVisitor;
2008-06-06 21:21:57 +08:00
osg::ref_ptr<osgUtil::StateGraph> _stateGraph;
2001-09-20 05:08:56 +08:00
osg::ref_ptr<osgUtil::RenderStage> _renderStage;
2002-02-14 21:26:37 +08:00
2003-10-01 23:56:52 +08:00
osg::ref_ptr<ComputeStereoMatricesCallback> _computeStereoMatricesCallback;
2002-02-19 07:01:09 +08:00
osg::ref_ptr<osgUtil::CullVisitor> _cullVisitorLeft;
2008-06-06 21:21:57 +08:00
osg::ref_ptr<osgUtil::StateGraph> _stateGraphLeft;
2002-02-14 21:26:37 +08:00
osg::ref_ptr<osgUtil::RenderStage> _renderStageLeft;
2008-06-19 22:29:38 +08:00
osg::ref_ptr<osg::Viewport> _viewportLeft;
2002-02-19 07:01:09 +08:00
osg::ref_ptr<osgUtil::CullVisitor> _cullVisitorRight;
2008-06-06 21:21:57 +08:00
osg::ref_ptr<osgUtil::StateGraph> _stateGraphRight;
2002-02-14 21:26:37 +08:00
osg::ref_ptr<osgUtil::RenderStage> _renderStageRight;
2008-06-19 22:29:38 +08:00
osg::ref_ptr<osg::Viewport> _viewportRight;
2002-02-14 21:26:37 +08:00
2007-07-11 23:51:17 +08:00
osg::ref_ptr<osg::CollectOccludersVisitor> _collectOccludersVisitor;
2012-03-22 01:36:20 +08:00
2002-09-04 18:49:17 +08:00
osg::ref_ptr<osg::FrameStamp> _frameStamp;
2012-03-22 01:36:20 +08:00
2007-07-28 18:28:40 +08:00
osg::observer_ptr<osg::Camera> _camera;
osg::ref_ptr<osg::Camera> _cameraWithOwnership;
2012-03-22 01:36:20 +08:00
2004-04-30 23:35:31 +08:00
osg::ref_ptr<osg::StateSet> _globalStateSet;
osg::ref_ptr<osg::Light> _light;
osg::ref_ptr<osg::DisplaySettings> _displaySettings;
2012-03-22 01:36:20 +08:00
2010-01-21 18:24:48 +08:00
osg::ref_ptr<osg::StateSet> _secondaryStateSet;
2002-09-04 18:49:17 +08:00
FusionDistanceMode _fusionDistanceMode;
float _fusionDistanceValue;
2001-01-11 00:32:10 +08:00
2002-09-04 18:49:17 +08:00
LightingMode _lightingMode;
2012-03-22 01:36:20 +08:00
2002-09-04 18:49:17 +08:00
bool _prioritizeTextures;
2012-03-22 01:36:20 +08:00
2010-12-10 23:27:19 +08:00
bool _automaticFlush;
2004-01-05 21:40:36 +08:00
bool _requiresFlush;
2012-03-22 01:36:20 +08:00
int _activeUniforms;
2005-05-06 18:32:31 +08:00
double _previousFrameTime;
2007-01-25 20:02:51 +08:00
double _previousSimulationTime;
2012-03-22 01:36:20 +08:00
2005-10-25 23:43:04 +08:00
bool _redrawInterlacedStereoStencilMask;
int _interlacedStereoStencilWidth;
int _interlacedStereoStencilHeight;
2012-03-22 01:36:20 +08:00
unsigned int _dynamicObjectCount;
2013-04-18 17:47:28 +08:00
bool _resetColorMaskToAllEnabled;
2001-01-11 00:32:10 +08:00
};
2002-02-03 20:33:41 +08:00
}
2001-01-11 00:32:10 +08:00
#endif