diff --git a/examples/osgcamera/osgcamera.cpp b/examples/osgcamera/osgcamera.cpp index a767ef8e4..b32c66303 100644 --- a/examples/osgcamera/osgcamera.cpp +++ b/examples/osgcamera/osgcamera.cpp @@ -58,9 +58,8 @@ struct CompileOperation : public osg::GraphicsThread::Operation // Cull operation, that does a cull on the scene graph. struct CullOperation : public osg::GraphicsThread::Operation { - CullOperation(osg::CameraNode* camera, osgUtil::SceneView* sceneView): + CullOperation(osgUtil::SceneView* sceneView): osg::GraphicsThread::Operation("Cull",true), - _camera(camera), _sceneView(sceneView) { } @@ -68,14 +67,9 @@ struct CullOperation : public osg::GraphicsThread::Operation virtual void operator () (osg::GraphicsContext* context) { _sceneView->setState(context->getState()); - _sceneView->setProjectionMatrix(_camera->getProjectionMatrix()); - _sceneView->setViewMatrix(_camera->getViewMatrix()); - _sceneView->setViewport(_camera->getViewport()); - _sceneView->cull(); } - osg::CameraNode* _camera; osg::ref_ptr _sceneView; }; @@ -273,25 +267,22 @@ int main( int argc, char **argv ) ++citr) { osg::CameraNode* camera = citr->get(); + osg::GraphicsThread* graphicsThread = camera->getGraphicsContext()->getGraphicsThread(); // create a scene view to do the cull and draw osgUtil::SceneView* sceneView = new osgUtil::SceneView; sceneView->setDefaults(); sceneView->setFrameStamp(frameStamp.get()); - - if (camera->getNumChildren()>=1) - { - sceneView->setSceneData(camera->getChild(0)); - } + sceneView->setCamera(camera); // cull traversal operation - camera->getGraphicsContext()->getGraphicsThread()->add( new CullOperation(camera, sceneView), false); + graphicsThread->add( new CullOperation(sceneView), false); // optionally add glFinish barrier to ensure that all OpenGL commands are completed before we start dispatching a new frame - if (doFinishBeforeNewDraw) camera->getGraphicsContext()->getGraphicsThread()->add( glFinishBarrierOp.get(), false); + if (doFinishBeforeNewDraw) graphicsThread->add( glFinishBarrierOp.get(), false); // draw traversal operation. - camera->getGraphicsContext()->getGraphicsThread()->add( new DrawOperation(sceneView), false); + graphicsThread->add( new DrawOperation(sceneView), false); } // fourth add the frame end barrier, the pre swap barrier and finally the swap buffers to each graphics thread. diff --git a/include/osgUtil/SceneView b/include/osgUtil/SceneView index d8c0e39d0..0a53ae4a0 100644 --- a/include/osgUtil/SceneView +++ b/include/osgUtil/SceneView @@ -21,6 +21,7 @@ #include #include #include +#include #include @@ -54,48 +55,50 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced, public osg::CullSetting */ void setDefaults(unsigned int options = STANDARD_SETTINGS); + /** Set the camera used to represent the camera view of this SceneView.*/ + void setCamera(osg::CameraNode* camera); + + /** Get the camera used to represent the camera view of this SceneView.*/ + osg::CameraNode* getCamera() { return _camera.get(); } + + /** Get the const camera used to represent the camera view of this SceneView.*/ + const osg::CameraNode* getCamera() const { return _camera.get(); } + /** Set the data to view. The data will typically be * an osg::Scene but can be any osg::Node type. */ - void setSceneData(osg::Node* node) { _sceneData = node; } + void setSceneData(osg::Node* node); + /** Get the scene data to view. The data will typically be * an osg::Scene but can be any osg::Node type. */ - osg::Node* getSceneData() { return _sceneData.get(); } + osg::Node* getSceneData(unsigned int childNo=0) { return (_camera->getNumChildren()>childNo) ? _camera->getChild(childNo) : 0; } /** Get the const scene data which to view. The data will typically be * an osg::Scene but can be any osg::Node type. */ - const osg::Node* getSceneData() const { return _sceneData.get(); } + const osg::Node* getSceneData(unsigned int childNo=0) const { return (_camera->getNumChildren()>childNo) ? _camera->getChild(childNo) : 0; } + + /** Get the number of scene data subgraphs added to the SceneView's camera.*/ + unsigned int getNumSceneData() const { return _camera->getNumChildren(); } /** Set the viewport of the scene view to use specified osg::Viewport. */ - void setViewport(osg::Viewport* viewport) - { - if (viewport) _viewport = viewport; - else - { - // ensure that _viewport is always valid. - _viewport = new osg::Viewport; - } - } + void setViewport(osg::Viewport* viewport) { _camera->setViewport(viewport); } /** Set the viewport of the scene view to specified dimensions. */ - void setViewport(int x,int y,int width,int height) - { - _viewport->setViewport(x,y,width,height); - } - + void setViewport(int x,int y,int width,int height) { _camera->setViewport(x,y,width,height); } - /** Get the const viewport. */ - const osg::Viewport* getViewport() const { return _viewport.get(); } /** Get the viewport. */ - osg::Viewport* getViewport() { return _viewport.get(); } + osg::Viewport* getViewport() { return (_camera->getViewport()!=0) ? _camera->getViewport() : 0; } - /** Get the viewport of the scene view. */ + /** Get the const viewport. */ + const osg::Viewport* getViewport() const { return (_camera->getViewport()!=0) ? _camera->getViewport() : 0; } + + /** Get the viewport of the scene view. */ void getViewport(int& x,int& y,int& width,int& height) const { - _viewport->getViewport(x,y,width,height); + if (_camera->getViewport()!=0) _camera->getViewport()->getViewport(x,y,width,height); } /** Set the DisplaySettings. */ @@ -110,9 +113,9 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced, public osg::CullSetting /** Set the color used in glClearColor(). Defaults to an off blue color.*/ - void setClearColor(const osg::Vec4& color) { _clearColor=color; } + void setClearColor(const osg::Vec4& color) { _camera->setClearColor(color); } /** Get the color used in glClearColor.*/ - const osg::Vec4& getClearColor() const { return _clearColor; } + const osg::Vec4& getClearColor() const { return _camera->getClearColor(); } /** Mannually set the redraw interlaced stereo stencil mask request flag to control whether to redraw the stencil buffer on the next frame.*/ @@ -170,10 +173,10 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced, public osg::CullSetting /** Set the projection matrix. Can be thought of as setting the lens of a camera. */ - inline void setProjectionMatrix(const osg::Matrixf& matrix) { _projectionMatrix.set(matrix); } + inline void setProjectionMatrix(const osg::Matrixf& matrix) { _camera->setProjectionMatrix(matrix); } /** Set the projection matrix. Can be thought of as setting the lens of a camera. */ - inline void setProjectionMatrix(const osg::Matrixd& matrix) { _projectionMatrix.set(matrix); } + inline void setProjectionMatrix(const osg::Matrixd& matrix) { _camera->setProjectionMatrix(matrix); } /** Set to an orthographic projection. See OpenGL glOrtho for documentation further details.*/ void setProjectionMatrixAsOrtho(double left, double right, @@ -195,10 +198,10 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced, public osg::CullSetting double zNear, double zFar); /** Get the projection matrix.*/ - osg::Matrixd& getProjectionMatrix() { return _projectionMatrix; } + osg::Matrixd& getProjectionMatrix() { return _camera->getProjectionMatrix(); } /** Get the const projection matrix.*/ - const osg::Matrixd& getProjectionMatrix() const { return _projectionMatrix; } + const osg::Matrixd& getProjectionMatrix() const { return _camera->getProjectionMatrix(); } /** Get the othographic settings of the orthographic projection matrix. * Returns false if matrix is not an orthographic matrix, where parameter values are undefined.*/ @@ -222,19 +225,19 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced, public osg::CullSetting /** Set the view matrix. Can be thought of as setting the position of the world relative to the camera in camera coordinates. */ - inline void setViewMatrix(const osg::Matrixf& matrix) { _viewMatrix.set(matrix); } + inline void setViewMatrix(const osg::Matrixf& matrix) { _camera->setViewMatrix(matrix); } /** Set the view matrix. Can be thought of as setting the position of the world relative to the camera in camera coordinates. */ - inline void setViewMatrix(const osg::Matrixd& matrix) { _viewMatrix.set(matrix); } + inline void setViewMatrix(const osg::Matrixd& matrix) { _camera->setViewMatrix(matrix); } /** Set to the position and orientation of view matrix, using the same convention as gluLookAt. */ void setViewMatrixAsLookAt(const osg::Vec3& eye,const osg::Vec3& center,const osg::Vec3& up); /** Get the view matrix. */ - osg::Matrixd& getViewMatrix() { return _viewMatrix; } + osg::Matrixd& getViewMatrix() { return _camera->getViewMatrix(); } /** Get the const view matrix. */ - const osg::Matrixd& getViewMatrix() const { return _viewMatrix; } + const osg::Matrixd& getViewMatrix() const { return _camera->getViewMatrix(); } /** Get to the position and orientation of a modelview matrix, using the same convention as gluLookAt. */ void getViewMatrixAsLookAt(osg::Vec3& eye,osg::Vec3& center,osg::Vec3& up,float lookDistance=1.0f) const; @@ -462,44 +465,36 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced, public osg::CullSetting osg::ref_ptr _localStateSet; osg::ref_ptr _state; - osg::Matrixd _projectionMatrix; - osg::Matrixd _viewMatrix; - bool _initCalled; osg::ref_ptr _initVisitor; osg::ref_ptr _updateVisitor; osg::ref_ptr _cullVisitor; - osg::ref_ptr _rendergraph; + osg::ref_ptr _rendergraph; osg::ref_ptr _renderStage; osg::ref_ptr _computeStereoMatricesCallback; osg::ref_ptr _cullVisitorLeft; - osg::ref_ptr _rendergraphLeft; + osg::ref_ptr _rendergraphLeft; osg::ref_ptr _renderStageLeft; osg::ref_ptr _cullVisitorRight; - osg::ref_ptr _rendergraphRight; + osg::ref_ptr _rendergraphRight; osg::ref_ptr _renderStageRight; osg::ref_ptr _collectOccludersVisistor; osg::ref_ptr _frameStamp; - - osg::ref_ptr _sceneData; + osg::ref_ptr _camera; + osg::ref_ptr _globalStateSet; osg::ref_ptr _light; osg::ref_ptr _displaySettings; - osg::Vec4 _clearColor; - - FusionDistanceMode _fusionDistanceMode; float _fusionDistanceValue; - osg::ref_ptr _viewport; - LightingMode _lightingMode; bool _prioritizeTextures; diff --git a/src/osgUtil/SceneView.cpp b/src/osgUtil/SceneView.cpp index 7f5ddfa21..287475516 100644 --- a/src/osgUtil/SceneView.cpp +++ b/src/osgUtil/SceneView.cpp @@ -89,7 +89,6 @@ SceneView::SceneView(DisplaySettings* ds) { _displaySettings = ds; - _clearColor.set(0.2f, 0.2f, 0.4f, 1.0f); _fusionDistanceMode = PROPORTIONAL_TO_SCREEN_DISTANCE; @@ -99,7 +98,9 @@ SceneView::SceneView(DisplaySettings* ds) _prioritizeTextures = false; - _viewport = new Viewport; + _camera = new CameraNode; + _camera->setViewport(new Viewport); + _camera->setClearColor(osg::Vec4(0.2f, 0.2f, 0.4f, 1.0f)); _initCalled = false; @@ -125,8 +126,8 @@ SceneView::~SceneView() void SceneView::setDefaults(unsigned int options) { - _projectionMatrix.makePerspective(50.0f,1.4f,1.0f,10000.0f); - _viewMatrix.makeIdentity(); + _camera->getProjectionMatrix().makePerspective(50.0f,1.4f,1.0f,10000.0f); + _camera->getViewMatrix().makeIdentity(); _globalStateSet = new osg::StateSet; @@ -197,8 +198,32 @@ void SceneView::setDefaults(unsigned int options) texenv->setMode(osg::TexEnv::MODULATE); _globalStateSet->setTextureAttributeAndModes(0,texenv, osg::StateAttribute::ON); + _camera->setClearColor(osg::Vec4(0.2f, 0.2f, 0.4f, 1.0f)); +} - _clearColor.set(0.2f, 0.2f, 0.4f, 1.0f); +void SceneView::setCamera(osg::CameraNode* camera) +{ + if (camera) + { + _camera = camera; + } + else + { + osg::notify(osg::NOTICE)<<"Warning: attempt to assign a NULL camera to SceneView not permitted."< temporaryRefernce = node; + + // remove pre existing children + _camera->removeChild(0, _camera->getNumChildren()); + + // add the new one in. + _camera->addChild(node); } void SceneView::init() @@ -206,7 +231,7 @@ void SceneView::init() _initCalled = true; - if (_sceneData.valid() && _initVisitor.valid()) + if (_camera.valid() && _initVisitor.valid()) { _initVisitor->reset(); _initVisitor->setFrameStamp(_frameStamp.get()); @@ -219,14 +244,14 @@ void SceneView::init() _initVisitor->setTraversalNumber(_frameStamp->getFrameNumber()); } - _sceneData->accept(*_initVisitor.get()); + _camera->accept(*_initVisitor.get()); } } void SceneView::update() { - if (_sceneData.valid() && _updateVisitor.valid()) + if (_camera.valid() && _updateVisitor.valid()) { _updateVisitor->reset(); @@ -238,13 +263,13 @@ void SceneView::update() _updateVisitor->setTraversalNumber(_frameStamp->getFrameNumber()); } - _sceneData->accept(*_updateVisitor.get()); + _camera->accept(*_updateVisitor.get()); // now force a recompute of the bounding volume while we are still in // the read/write app phase, this should prevent the need to recompute // the bounding volumes from within the cull traversal which may be // multi-threaded. - _sceneData->getBound(); + _camera->getBound(); } } @@ -281,13 +306,13 @@ void SceneView::updateUniforms() if (_activeUniforms & VIEW_MATRIX_UNIFORM) { osg::Uniform* uniform = _localStateSet->getOrCreateUniform("osg_ViewMatrix",osg::Uniform::FLOAT_MAT4); - uniform->set(_viewMatrix); + uniform->set(getViewMatrix()); } if (_activeUniforms & VIEW_MATRIX_INVERSE_UNIFORM) { osg::Uniform* uniform = _localStateSet->getOrCreateUniform("osg_ViewMatrixInverse",osg::Uniform::FLOAT_MAT4); - uniform->set(osg::Matrix::inverse(_viewMatrix)); + uniform->set(osg::Matrix::inverse(getViewMatrix())); } } @@ -471,13 +496,13 @@ void SceneView::cull() { // set up the left eye. _cullVisitor->setTraversalMask(_cullMaskLeft); - cullStage(computeLeftEyeProjection(_projectionMatrix),computeLeftEyeView(_viewMatrix),_cullVisitor.get(),_rendergraph.get(),_renderStage.get()); + cullStage(computeLeftEyeProjection(getProjectionMatrix()),computeLeftEyeView(getViewMatrix()),_cullVisitor.get(),_rendergraph.get(),_renderStage.get()); if (_cullVisitor->getComputeNearFarMode()!=osgUtil::CullVisitor::DO_NOT_COMPUTE_NEAR_FAR) { CullVisitor::value_type zNear = _cullVisitor->getCalculatedNearPlane(); CullVisitor::value_type zFar = _cullVisitor->getCalculatedFarPlane(); - _cullVisitor->clampProjectionMatrix(_projectionMatrix,zNear,zFar); + _cullVisitor->clampProjectionMatrix(getProjectionMatrix(),zNear,zFar); } } @@ -485,13 +510,13 @@ void SceneView::cull() { // set up the right eye. _cullVisitor->setTraversalMask(_cullMaskRight); - cullStage(computeRightEyeProjection(_projectionMatrix),computeRightEyeView(_viewMatrix),_cullVisitor.get(),_rendergraph.get(),_renderStage.get()); + cullStage(computeRightEyeProjection(getProjectionMatrix()),computeRightEyeView(getViewMatrix()),_cullVisitor.get(),_rendergraph.get(),_renderStage.get()); if (_cullVisitor->getComputeNearFarMode()!=osgUtil::CullVisitor::DO_NOT_COMPUTE_NEAR_FAR) { CullVisitor::value_type zNear = _cullVisitor->getCalculatedNearPlane(); CullVisitor::value_type zFar = _cullVisitor->getCalculatedFarPlane(); - _cullVisitor->clampProjectionMatrix(_projectionMatrix,zNear,zFar); + _cullVisitor->clampProjectionMatrix(getProjectionMatrix(),zNear,zFar); } } @@ -509,21 +534,21 @@ void SceneView::cull() _cullVisitorLeft->setDatabaseRequestHandler(_cullVisitor->getDatabaseRequestHandler()); _cullVisitorLeft->setClampProjectionMatrixCallback(_cullVisitor->getClampProjectionMatrixCallback()); _cullVisitorLeft->setTraversalMask(_cullMaskLeft); - cullStage(computeLeftEyeProjection(_projectionMatrix),computeLeftEyeView(_viewMatrix),_cullVisitorLeft.get(),_rendergraphLeft.get(),_renderStageLeft.get()); + cullStage(computeLeftEyeProjection(getProjectionMatrix()),computeLeftEyeView(getViewMatrix()),_cullVisitorLeft.get(),_rendergraphLeft.get(),_renderStageLeft.get()); // set up the right eye. _cullVisitorRight->setDatabaseRequestHandler(_cullVisitor->getDatabaseRequestHandler()); _cullVisitorRight->setClampProjectionMatrixCallback(_cullVisitor->getClampProjectionMatrixCallback()); _cullVisitorRight->setTraversalMask(_cullMaskRight); - cullStage(computeRightEyeProjection(_projectionMatrix),computeRightEyeView(_viewMatrix),_cullVisitorRight.get(),_rendergraphRight.get(),_renderStageRight.get()); + cullStage(computeRightEyeProjection(getProjectionMatrix()),computeRightEyeView(getViewMatrix()),_cullVisitorRight.get(),_rendergraphRight.get(),_renderStageRight.get()); if (_cullVisitorLeft->getComputeNearFarMode()!=osgUtil::CullVisitor::DO_NOT_COMPUTE_NEAR_FAR && _cullVisitorRight->getComputeNearFarMode()!=osgUtil::CullVisitor::DO_NOT_COMPUTE_NEAR_FAR) { CullVisitor::value_type zNear = osg::minimum(_cullVisitorLeft->getCalculatedNearPlane(),_cullVisitorRight->getCalculatedNearPlane()); CullVisitor::value_type zFar = osg::maximum(_cullVisitorLeft->getCalculatedFarPlane(),_cullVisitorRight->getCalculatedFarPlane()); - _cullVisitor->clampProjectionMatrix(_projectionMatrix,zNear,zFar); + _cullVisitor->clampProjectionMatrix(getProjectionMatrix(),zNear,zFar); } } @@ -533,13 +558,13 @@ void SceneView::cull() { _cullVisitor->setTraversalMask(_cullMask); - cullStage(_projectionMatrix,_viewMatrix,_cullVisitor.get(),_rendergraph.get(),_renderStage.get()); + cullStage(getProjectionMatrix(),getViewMatrix(),_cullVisitor.get(),_rendergraph.get(),_renderStage.get()); if (_cullVisitor->getComputeNearFarMode()!=osgUtil::CullVisitor::DO_NOT_COMPUTE_NEAR_FAR) { CullVisitor::value_type zNear = _cullVisitor->getCalculatedNearPlane(); CullVisitor::value_type zFar = _cullVisitor->getCalculatedFarPlane(); - _cullVisitor->clampProjectionMatrix(_projectionMatrix,zNear,zFar); + _cullVisitor->clampProjectionMatrix(getProjectionMatrix(),zNear,zFar); } } @@ -549,7 +574,7 @@ void SceneView::cull() void SceneView::cullStage(const osg::Matrixd& projection,const osg::Matrixd& modelview,osgUtil::CullVisitor* cullVisitor, osgUtil::StateGraph* rendergraph, osgUtil::RenderStage* renderStage) { - if (!_sceneData || !_viewport->valid()) return; + if (!_camera || !getViewport()) return; if (!_initCalled) init(); @@ -558,7 +583,7 @@ void SceneView::cullStage(const osg::Matrixd& projection,const osg::Matrixd& mod osg::ref_ptr mv = new osg::RefMatrix(modelview); // collect any occluder in the view frustum. - if (_sceneData->containsOccluderNodes()) + if (_camera->containsOccluderNodes()) { //std::cout << "Scene graph contains occluder nodes, searching for them"<setTraversalNumber(_frameStamp->getFrameNumber()); } - _collectOccludersVisistor->pushViewport(_viewport.get()); + _collectOccludersVisistor->pushViewport(getViewport()); _collectOccludersVisistor->pushProjectionMatrix(proj.get()); _collectOccludersVisistor->pushModelViewMatrix(mv.get()); // traverse the scene graph to search for occluder in there new positions. - _sceneData->accept(*_collectOccludersVisistor); + _camera->accept(*_collectOccludersVisistor); _collectOccludersVisistor->popModelViewMatrix(); _collectOccludersVisistor->popProjectionMatrix(); @@ -629,8 +654,8 @@ void SceneView::cullStage(const osg::Matrixd& projection,const osg::Matrixd& mod // achieves a certain amount of frame cohereancy of memory allocation. rendergraph->clean(); - renderStage->setViewport(_viewport.get()); - renderStage->setClearColor(_clearColor); + renderStage->setViewport(getViewport()); + renderStage->setClearColor(getClearColor()); switch(_lightingMode) @@ -651,13 +676,18 @@ void SceneView::cullStage(const osg::Matrixd& projection,const osg::Matrixd& mod if (_localStateSet.valid()) cullVisitor->pushStateSet(_localStateSet.get()); - cullVisitor->pushViewport(_viewport.get()); + cullVisitor->pushViewport(getViewport()); cullVisitor->pushProjectionMatrix(proj.get()); cullVisitor->pushModelViewMatrix(mv.get()); // traverse the scene graph to generate the rendergraph. - _sceneData->accept(*cullVisitor); + for(unsigned int childNo=0; + childNo<_camera->getNumChildren(); + ++childNo) + { + _camera->getChild(childNo)->accept(*cullVisitor); + } cullVisitor->popModelViewMatrix(); cullVisitor->popProjectionMatrix(); @@ -695,9 +725,9 @@ void SceneView::cullStage(const osg::Matrixd& projection,const osg::Matrixd& mod void SceneView::releaseAllGLObjects() { - if (!_sceneData) return; + if (!_camera) return; - _sceneData->releaseGLObjects(_state.get()); + _camera->releaseGLObjects(_state.get()); } @@ -748,7 +778,7 @@ void SceneView::draw() // assume the the draw which is about to happen could generate GL objects that need flushing in the next frame. _requiresFlush = true; - _state->setInitialViewMatrix(new osg::RefMatrix(_viewMatrix)); + _state->setInitialViewMatrix(new osg::RefMatrix(getViewMatrix())); RenderLeaf* previous = NULL; if (_displaySettings.valid() && _displaySettings->getStereo()) @@ -759,7 +789,7 @@ void SceneView::draw() case(osg::DisplaySettings::QUAD_BUFFER): { - _localStateSet->setAttribute(_viewport.get()); + _localStateSet->setAttribute(getViewport()); // ensure that all color planes are active. osg::ColorMask* cmask = static_cast(_localStateSet->getAttribute(osg::StateAttribute::COLORMASK)); @@ -800,7 +830,7 @@ void SceneView::draw() _renderStageRight->setReadBuffer(_drawBufferValue); } - _localStateSet->setAttribute(_viewport.get()); + _localStateSet->setAttribute(getViewport()); _renderStageLeft->drawPreRenderStages(*_state,previous); @@ -880,18 +910,18 @@ void SceneView::draw() int separation = _displaySettings->getSplitStereoHorizontalSeparation(); - int left_half_width = (_viewport->width()-separation)/2; - int right_half_begin = (_viewport->width()+separation)/2; - int right_half_width = _viewport->width()-right_half_begin; + int left_half_width = (getViewport()->width()-separation)/2; + int right_half_begin = (getViewport()->width()+separation)/2; + int right_half_width = getViewport()->width()-right_half_begin; osg::ref_ptr viewportLeft = new osg::Viewport; - viewportLeft->setViewport(_viewport->x(),_viewport->y(),left_half_width,_viewport->height()); + viewportLeft->setViewport(getViewport()->x(),getViewport()->y(),left_half_width,getViewport()->height()); osg::ref_ptr viewportRight = new osg::Viewport; - viewportRight->setViewport(_viewport->x()+right_half_begin,_viewport->y(),right_half_width,_viewport->height()); + viewportRight->setViewport(getViewport()->x()+right_half_begin,getViewport()->y(),right_half_width,getViewport()->height()); - clearArea(_viewport->x()+left_half_width,_viewport->y(),separation,_viewport->height(),_renderStageLeft->getClearColor()); + clearArea(getViewport()->x()+left_half_width,getViewport()->y(),separation,getViewport()->height(),_renderStageLeft->getClearColor()); if (_displaySettings->getSplitStereoHorizontalEyeMapping()==osg::DisplaySettings::LEFT_EYE_LEFT_VIEWPORT) { @@ -946,17 +976,17 @@ void SceneView::draw() int separation = _displaySettings->getSplitStereoVerticalSeparation(); - int bottom_half_height = (_viewport->height()-separation)/2; - int top_half_begin = (_viewport->height()+separation)/2; - int top_half_height = _viewport->height()-top_half_begin; + int bottom_half_height = (getViewport()->height()-separation)/2; + int top_half_begin = (getViewport()->height()+separation)/2; + int top_half_height = getViewport()->height()-top_half_begin; osg::ref_ptr viewportTop = new osg::Viewport; - viewportTop->setViewport(_viewport->x(),_viewport->y()+top_half_begin,_viewport->width(),top_half_height); + viewportTop->setViewport(getViewport()->x(),getViewport()->y()+top_half_begin,getViewport()->width(),top_half_height); osg::ref_ptr viewportBottom = new osg::Viewport; - viewportBottom->setViewport(_viewport->x(),_viewport->y(),_viewport->width(),bottom_half_height); + viewportBottom->setViewport(getViewport()->x(),getViewport()->y(),getViewport()->width(),bottom_half_height); - clearArea(_viewport->x(),_viewport->y()+bottom_half_height,_viewport->width(),separation,_renderStageLeft->getClearColor()); + clearArea(getViewport()->x(),getViewport()->y()+bottom_half_height,getViewport()->width(),separation,_renderStageLeft->getClearColor()); if (_displaySettings->getSplitStereoVerticalEyeMapping()==osg::DisplaySettings::LEFT_EYE_TOP_VIEWPORT) { @@ -1003,14 +1033,14 @@ void SceneView::draw() _renderStage->setColorMask(cmask); _renderStage->setColorMask(cmask); - _localStateSet->setAttribute(_viewport.get()); + _localStateSet->setAttribute(getViewport()); _renderStage->drawPreRenderStages(*_state,previous); _renderStage->draw(*_state,previous); } break; case(osg::DisplaySettings::VERTICAL_INTERLACE): { - _localStateSet->setAttribute(_viewport.get()); + _localStateSet->setAttribute(getViewport()); // ensure that all color planes are active. osg::ColorMask* cmask = static_cast(_localStateSet->getAttribute(osg::StateAttribute::COLORMASK)); @@ -1032,13 +1062,13 @@ void SceneView::draw() glEnable(GL_STENCIL_TEST); if(_redrawInterlacedStereoStencilMask || - _interlacedStereoStencilWidth != _viewport->width() || - _interlacedStereoStencilHeight != _viewport->height() ) + _interlacedStereoStencilWidth != getViewport()->width() || + _interlacedStereoStencilHeight != getViewport()->height() ) { - _viewport->apply(*_state); + getViewport()->apply(*_state); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - glOrtho(_viewport->x(), _viewport->width(), _viewport->y(), _viewport->height(), -1.0, 1.0); + glOrtho(getViewport()->x(), getViewport()->width(), getViewport()->y(), getViewport()->height(), -1.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glDisable(GL_LIGHTING); @@ -1050,15 +1080,15 @@ void SceneView::draw() glPolygonStipple(patternVertEven); glEnable(GL_POLYGON_STIPPLE); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); - glRecti(_viewport->x(), _viewport->y(), _viewport->width(), _viewport->height()); + glRecti(getViewport()->x(), getViewport()->y(), getViewport()->width(), getViewport()->height()); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glDisable(GL_POLYGON_STIPPLE); glEnable(GL_LIGHTING); glEnable(GL_DEPTH_TEST); _redrawInterlacedStereoStencilMask = false; - _interlacedStereoStencilWidth = _viewport->width(); - _interlacedStereoStencilHeight = _viewport->height(); + _interlacedStereoStencilWidth = getViewport()->width(); + _interlacedStereoStencilHeight = getViewport()->height(); } _renderStageLeft->setClearMask(_renderStageLeft->getClearMask() & ~(GL_STENCIL_BUFFER_BIT)); @@ -1075,7 +1105,7 @@ void SceneView::draw() break; case(osg::DisplaySettings::HORIZONTAL_INTERLACE): { - _localStateSet->setAttribute(_viewport.get()); + _localStateSet->setAttribute(getViewport()); // ensure that all color planes are active. osg::ColorMask* cmask = static_cast(_localStateSet->getAttribute(osg::StateAttribute::COLORMASK)); @@ -1097,13 +1127,13 @@ void SceneView::draw() glEnable(GL_STENCIL_TEST); if(_redrawInterlacedStereoStencilMask || - _interlacedStereoStencilWidth != _viewport->width() || - _interlacedStereoStencilHeight != _viewport->height() ) + _interlacedStereoStencilWidth != getViewport()->width() || + _interlacedStereoStencilHeight != getViewport()->height() ) { - _viewport->apply(*_state); + getViewport()->apply(*_state); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - glOrtho(_viewport->x(), _viewport->width(), _viewport->y(), _viewport->height(), -1.0, 1.0); + glOrtho(getViewport()->x(), getViewport()->width(), getViewport()->y(), getViewport()->height(), -1.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glDisable(GL_LIGHTING); @@ -1115,15 +1145,15 @@ void SceneView::draw() glPolygonStipple(patternHorzEven); glEnable(GL_POLYGON_STIPPLE); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); - glRecti(_viewport->x(), _viewport->y(), _viewport->width(), _viewport->height()); + glRecti(getViewport()->x(), getViewport()->y(), getViewport()->width(), getViewport()->height()); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glDisable(GL_POLYGON_STIPPLE); glEnable(GL_LIGHTING); glEnable(GL_DEPTH_TEST); _redrawInterlacedStereoStencilMask = false; - _interlacedStereoStencilWidth = _viewport->width(); - _interlacedStereoStencilHeight = _viewport->height(); + _interlacedStereoStencilWidth = getViewport()->width(); + _interlacedStereoStencilHeight = getViewport()->height(); } _renderStageLeft->setClearMask(_renderStageLeft->getClearMask() & ~(GL_STENCIL_BUFFER_BIT)); @@ -1155,7 +1185,7 @@ void SceneView::draw() _renderStage->setReadBuffer(_drawBufferValue); } - _localStateSet->setAttribute(_viewport.get()); + _localStateSet->setAttribute(getViewport()); // ensure that all color planes are active. @@ -1237,10 +1267,10 @@ bool SceneView::projectObjectIntoWindow(const osg::Vec3& object,osg::Vec3& windo const osg::Matrix SceneView::computeMVPW() const { - osg::Matrix matrix( _viewMatrix * _projectionMatrix); + osg::Matrix matrix( getViewMatrix() * getProjectionMatrix()); - if (_viewport.valid()) - matrix.postMult(_viewport->computeWindowMatrix()); + if (getViewport()) + matrix.postMult(getViewport()->computeWindowMatrix()); else osg::notify(osg::WARN)<<"osg::Matrix SceneView::computeMVPW() - error no viewport attached to SceneView, coords will be computed inccorectly."<