diff --git a/include/osgUtil/CullVisitor b/include/osgUtil/CullVisitor index bdf3ef5d6..f08a031bb 100644 --- a/include/osgUtil/CullVisitor +++ b/include/osgUtil/CullVisitor @@ -43,6 +43,8 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor CullVisitor(); virtual ~CullVisitor(); + virtual CullVisitor* cloneType() const { return new CullVisitor(); } + virtual void reset(); virtual void apply(osg::Node&); diff --git a/include/osgUtil/RenderGraph b/include/osgUtil/RenderGraph index 26b63a772..6fd3a88e1 100644 --- a/include/osgUtil/RenderGraph +++ b/include/osgUtil/RenderGraph @@ -52,6 +52,8 @@ class OSGUTIL_EXPORT RenderGraph : public osg::Referenced ~RenderGraph() {} + RenderGraph* cloneType() const { return new RenderGraph; } + /** return true if all of drawables, lights and children are empty.*/ inline const bool empty() const diff --git a/include/osgUtil/SceneView b/include/osgUtil/SceneView index 45a84f429..9d5b065ff 100644 --- a/include/osgUtil/SceneView +++ b/include/osgUtil/SceneView @@ -215,7 +215,7 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced virtual ~SceneView(); /** Do cull traversal of attached scene graph using Cull NodeVisitor.*/ - virtual void cullStage(osg::Camera* camera,osgUtil::RenderStage* renderStage); + virtual void cullStage(osg::Camera* camera,osgUtil::CullVisitor* cullVisitor, osgUtil::RenderGraph* rendergraph, osgUtil::RenderStage* renderStage); virtual void drawStage(osgUtil::RenderStage* renderStage); osg::ref_ptr _sceneData; @@ -233,8 +233,13 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced osg::ref_ptr _renderStage; osg::ref_ptr _cameraLeft; - osg::ref_ptr _cameraRight; + osg::ref_ptr _cullVisitorLeft; + osg::ref_ptr _rendergraphLeft; osg::ref_ptr _renderStageLeft; + + osg::ref_ptr _cameraRight; + osg::ref_ptr _cullVisitorRight; + osg::ref_ptr _rendergraphRight; osg::ref_ptr _renderStageRight; diff --git a/src/osg/Camera.cpp b/src/osg/Camera.cpp index de5eab0a8..d968b34ec 100644 --- a/src/osg/Camera.cpp +++ b/src/osg/Camera.cpp @@ -94,7 +94,7 @@ void Camera::copy(const Camera& camera) // cached matrix and clipping volume derived from above settings. _dirty = false;// camera._dirty; _projectionMatrix = NULL; //camera._projectionMatrix; - _modelViewMatrix = NULL; camera._modelViewMatrix; + _modelViewMatrix = NULL; //camera._modelViewMatrix; // _clippingVolume = camera._clippingVolume; _mp = NULL; @@ -757,20 +757,20 @@ void Camera::calculateMatricesAndClippingVolume() const // note, _left,_right,_top and _bottom are already devided // by _zNear so no need to take into account for normal // calculations. - Vec3 leftNormal (1.0f,0.0f,_left); + Vec3 leftNormal (1.0f,0.0f,left); leftNormal.normalize(); _clippingVolume.add(Plane(leftNormal,0.0f)); - Vec3 rightNormal (-1.0f,0.0f,-_right); + Vec3 rightNormal (-1.0f,0.0f,-right); rightNormal.normalize(); _clippingVolume.add(Plane(rightNormal,0.0f)); - Vec3 bottomNormal(0.0f,1.0f,_bottom); + Vec3 bottomNormal(0.0f,1.0f,bottom); bottomNormal.normalize(); _clippingVolume.add(Plane(bottomNormal,0.0f)); - Vec3 topNormal(0.0f,-1.0f,-_top); + Vec3 topNormal(0.0f,-1.0f,-top); topNormal.normalize(); _clippingVolume.add(Plane(topNormal,0.0f)); diff --git a/src/osgPlugins/Makefile b/src/osgPlugins/Makefile index 80d229968..4286e12fe 100644 --- a/src/osgPlugins/Makefile +++ b/src/osgPlugins/Makefile @@ -8,7 +8,7 @@ DIRS = osg rgb lib3ds flt obj lwo txp dw bmp pic tga osgtgz tgz zip # comment in if you want Open DX support, currently not on by default # since we havn't yet checked compilation on all platforms yet. -# DIRS += dx +DIRS += dx # comment in if you have Quicktime installed, i.e under Mac OS. # if in this case then its likely you'll want to comment out the below diff --git a/src/osgPlugins/pfb/Makefile b/src/osgPlugins/pfb/Makefile index 588e55ab2..d8acecd34 100644 --- a/src/osgPlugins/pfb/Makefile +++ b/src/osgPlugins/pfb/Makefile @@ -9,7 +9,6 @@ C++FILES = \ ConvertToPerformer.cpp\ ReaderWriterPFB.cpp\ -LIB = ../../../lib/osgPlugins/osgdb_pfb.$(SO_EXT) LIBS = -losg -losgDB \ -lpf3ds\ @@ -45,6 +44,8 @@ LIBS = -losg -losgDB \ # (note: you may need to build libimage.so from libimage.a) # LIBS += -limage +TARGET_BASENAME = osgdb_pfb + LOADABLE = $(OSGHOME)/lib/osgPlugins/$(TARGET_BASENAME).$(DL_EXT) LIB= diff --git a/src/osgUtil/SceneView.cpp b/src/osgUtil/SceneView.cpp index 70bd4bd9d..a9a480538 100644 --- a/src/osgUtil/SceneView.cpp +++ b/src/osgUtil/SceneView.cpp @@ -144,6 +144,7 @@ void SceneView::app() void SceneView::cull() { + if (_displaySettings.valid() && _displaySettings->getStereo()) { @@ -157,46 +158,45 @@ void SceneView::cull() _cameraLeft->adjustEyeOffsetForStereo(osg::Vec3(-iod*0.5,0.0f,0.0f)); _cameraRight->adjustEyeOffsetForStereo(osg::Vec3(iod*0.5,0.0f,0.0f)); + if (!_cullVisitorLeft.valid()) _cullVisitorLeft = dynamic_cast(_cullVisitor->cloneType()); + if (!_rendergraphLeft.valid()) _rendergraphLeft = dynamic_cast(_rendergraph->cloneType()); if (!_renderStageLeft.valid()) _renderStageLeft = dynamic_cast(_renderStage->cloneType()); + + if (!_cullVisitorRight.valid()) _cullVisitorRight = dynamic_cast(_cullVisitor->cloneType()); + if (!_rendergraphRight.valid()) _rendergraphRight = dynamic_cast(_rendergraph->cloneType()); if (!_renderStageRight.valid()) _renderStageRight = dynamic_cast(_renderStage->cloneType()); - cullStage(_cameraLeft.get(),_renderStageLeft.get()); - cullStage(_cameraRight.get(),_renderStageRight.get()); + cullStage(_cameraLeft.get(),_cullVisitorLeft.get(),_rendergraphLeft.get(),_renderStageLeft.get()); + cullStage(_cameraRight.get(),_cullVisitorRight.get(),_rendergraphRight.get(),_renderStageRight.get()); } else { - cullStage(_camera.get(),_renderStage.get()); + cullStage(_camera.get(),_cullVisitor.get(),_rendergraph.get(),_renderStage.get()); } + } -void SceneView::cullStage(osg::Camera* camera,osgUtil::RenderStage* renderStage) +void SceneView::cullStage(osg::Camera* camera, osgUtil::CullVisitor* cullVisitor, osgUtil::RenderGraph* rendergraph, osgUtil::RenderStage* renderStage) { if (!_sceneData || !_viewport->valid()) return; if (!_initCalled) init(); - _camera->adjustAspectRatio(_viewport->aspectRatio()); + camera->adjustAspectRatio(_viewport->aspectRatio()); - // comment out reset of rendergraph since clean is more efficient. - // _rendergraph->reset(); - // use clean of the rendergraph rather than reset, as it is able to - // reuse the structure on the rendergraph in the next frame. This - // achieves a certain amount of frame cohereancy of memory allocation. - _rendergraph->clean(); + cullVisitor->reset(); - _cullVisitor->reset(); - - _cullVisitor->setFrameStamp(_frameStamp.get()); + cullVisitor->setFrameStamp(_frameStamp.get()); // use the frame number for the traversal number. if (_frameStamp.valid()) { - _cullVisitor->setTraversalNumber(_frameStamp->getFrameNumber()); + cullVisitor->setTraversalNumber(_frameStamp->getFrameNumber()); } // get the camera's modelview @@ -209,18 +209,29 @@ void SceneView::cullStage(osg::Camera* camera,osgUtil::RenderStage* renderStage) local_camera->attachTransform(osg::Camera::NO_ATTACHED_TRANSFORM); - _cullVisitor->setLODBias(_lodBias); - _cullVisitor->setCamera(*local_camera); - _cullVisitor->setViewport(_viewport.get()); - _cullVisitor->setEarthSky(NULL); // reset earth sky on each frame. + cullVisitor->setLODBias(_lodBias); + cullVisitor->setCamera(*local_camera); + cullVisitor->setViewport(_viewport.get()); + cullVisitor->setEarthSky(NULL); // reset earth sky on each frame. + + cullVisitor->setRenderGraph(rendergraph); + cullVisitor->setRenderStage(renderStage); // SandB //now make it compute "clipping directions" needed for detailed culling - if(_cullVisitor->getDetailedCulling()) - _cullVisitor->calcClippingDirections();//only once pre frame + if(cullVisitor->getDetailedCulling()) + cullVisitor->calcClippingDirections();//only once pre frame renderStage->reset(); + // comment out reset of rendergraph since clean is more efficient. + // rendergraph->reset(); + + // use clean of the rendergraph rather than reset, as it is able to + // reuse the structure on the rendergraph in the next frame. This + // achieves a certain amount of frame cohereancy of memory allocation. + rendergraph->clean(); + renderStage->setViewport(_viewport.get()); renderStage->setCamera(local_camera); renderStage->setClearColor(_backgroundColor); @@ -238,21 +249,21 @@ void SceneView::cullStage(osg::Camera* camera,osgUtil::RenderStage* renderStage) break; } - if (_globalState.valid()) _cullVisitor->pushStateSet(_globalState.get()); + if (_globalState.valid()) cullVisitor->pushStateSet(_globalState.get()); - _cullVisitor->pushCullViewState(modelview); + cullVisitor->pushCullViewState(modelview); // traverse the scene graph to generate the rendergraph. - _sceneData->accept(*_cullVisitor); + _sceneData->accept(*cullVisitor); - if (_globalState.valid()) _cullVisitor->popStateSet(); + if (_globalState.valid()) cullVisitor->popStateSet(); - _cullVisitor->popCullViewState(); + cullVisitor->popCullViewState(); - const osg::EarthSky* earthSky = _cullVisitor->getEarthSky(); + const osg::EarthSky* earthSky = cullVisitor->getEarthSky(); if (earthSky) { if (earthSky->getRequiresClear()) @@ -271,17 +282,11 @@ void SceneView::cullStage(osg::Camera* camera,osgUtil::RenderStage* renderStage) } } - // prune out any empty RenderGraph children. - // note, this would be not required if the _renderGraph had been - // reset at the start of each frame (see top of this method) but - // a clean has been used instead to try to minimize the amount of - // allocation and deleteing of the RenderGraph nodes. - _rendergraph->prune(); if (_calc_nearfar) { - _near_plane = _cullVisitor->getCalculatedNearPlane(); - _far_plane = _cullVisitor->getCalculatedFarPlane(); + _near_plane = cullVisitor->getCalculatedNearPlane(); + _far_plane = cullVisitor->getCalculatedFarPlane(); if (_near_plane<=_far_plane) { @@ -295,7 +300,7 @@ void SceneView::cullStage(osg::Camera* camera,osgUtil::RenderStage* renderStage) // if required clamp the near plane to prevent negative or near zero // near planes. - if(!_cullVisitor->getDetailedCulling()) + if(!cullVisitor->getDetailedCulling()) { float min_near_plane = _far_plane*0.0005f; if (_near_planesetNearFar(_near_plane,_far_plane); } + // prune out any empty RenderGraph children. + // note, this would be not required if the rendergraph had been + // reset at the start of each frame (see top of this method) but + // a clean has been used instead to try to minimize the amount of + // allocation and deleteing of the RenderGraph nodes. + rendergraph->prune(); }