From a13b66135f826688acb860fc7f0f0c911435645d Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 3 Feb 2017 17:33:58 +0100 Subject: [PATCH 01/11] Fix handling of in-scenegraph drawables in osgUtil::Simplifier --- include/osgUtil/Simplifier | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/include/osgUtil/Simplifier b/include/osgUtil/Simplifier index 4b19ec81a..27d719ba8 100644 --- a/include/osgUtil/Simplifier +++ b/include/osgUtil/Simplifier @@ -97,16 +97,9 @@ class OSGUTIL_EXPORT Simplifier : public osg::NodeVisitor return getSampleRatio()<1.0; } - virtual void apply(osg::Geode& geode) + virtual void apply(osg::Geometry& geom) { - for(unsigned int i=0;iasGeometry(); - if (geometry) - { - simplify(*geometry); - } - } + simplify(geom); } /** simply the geometry.*/ From 09ca1321029071e3699833172ea8427367e83fde Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 3 Feb 2017 17:34:17 +0100 Subject: [PATCH 02/11] Remove redundant handling of Geode in SharedStateManager --- include/osgDB/SharedStateManager | 1 - src/osgDB/SharedStateManager.cpp | 14 -------------- 2 files changed, 15 deletions(-) diff --git a/include/osgDB/SharedStateManager b/include/osgDB/SharedStateManager index 08c30df81..73cc2117d 100644 --- a/include/osgDB/SharedStateManager +++ b/include/osgDB/SharedStateManager @@ -61,7 +61,6 @@ namespace osgDB { void share(osg::Node *node, OpenThreads::Mutex *mt=0); void apply(osg::Node& node); - void apply(osg::Geode& geode); // Answers the question "Will this state set be eliminated by // the SharedStateManager because an equivalent one has been diff --git a/src/osgDB/SharedStateManager.cpp b/src/osgDB/SharedStateManager.cpp index b95cbd0f7..61cd9458e 100644 --- a/src/osgDB/SharedStateManager.cpp +++ b/src/osgDB/SharedStateManager.cpp @@ -93,20 +93,6 @@ void SharedStateManager::apply(osg::Node& node) if(ss) process(ss, &node); traverse(node); } -void SharedStateManager::apply(osg::Geode& geode) -{ - osg::StateSet* ss = geode.getStateSet(); - if(ss) process(ss, &geode); - for(unsigned int i=0;igetStateSet(); - if(ss) process(ss, drawable); - } - } -} bool SharedStateManager::isShared(osg::StateSet* ss) { From a858b2a2cd3ac0a50f5fea598b4596fc8ed4402a Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 3 Feb 2017 17:39:56 +0100 Subject: [PATCH 03/11] Add a comment explaining some confusing code in UpdateVisitor and EventVisitor --- include/osgGA/EventVisitor | 4 ++-- include/osgUtil/UpdateVisitor | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/osgGA/EventVisitor b/include/osgGA/EventVisitor index 2eb15a633..ff3deece5 100644 --- a/include/osgGA/EventVisitor +++ b/include/osgGA/EventVisitor @@ -106,11 +106,11 @@ class OSGGA_EXPORT EventVisitor : public osg::NodeVisitor handle_callbacks(drawable.getStateSet()); } + // The following overrides are technically redundant as the default implementation would eventually trickle down to + // apply(osg::Node&); - however defining these explicitely should save a couple of virtual function calls virtual void apply(osg::Geode& node) { handle_callbacks_and_traverse(node); } virtual void apply(osg::Billboard& node) { handle_callbacks_and_traverse(node); } - virtual void apply(osg::LightSource& node) { handle_callbacks_and_traverse(node); } - virtual void apply(osg::Group& node) { handle_callbacks_and_traverse(node); } virtual void apply(osg::Transform& node) { handle_callbacks_and_traverse(node); } virtual void apply(osg::Projection& node) { handle_callbacks_and_traverse(node); } diff --git a/include/osgUtil/UpdateVisitor b/include/osgUtil/UpdateVisitor index 011d0022e..1e16a2b1f 100644 --- a/include/osgUtil/UpdateVisitor +++ b/include/osgUtil/UpdateVisitor @@ -73,11 +73,11 @@ class OSGUTIL_EXPORT UpdateVisitor : public osg::NodeVisitor handle_callbacks(drawable.getStateSet()); } + // The following overrides are technically redundant as the default implementation would eventually trickle down to + // apply(osg::Node&); - however defining these explicitely should save a couple of virtual function calls virtual void apply(osg::Geode& node) { handle_callbacks_and_traverse(node); } virtual void apply(osg::Billboard& node) { handle_callbacks_and_traverse(node); } - virtual void apply(osg::LightSource& node) { handle_callbacks_and_traverse(node); } - virtual void apply(osg::Group& node) { handle_callbacks_and_traverse(node); } virtual void apply(osg::Transform& node) { handle_callbacks_and_traverse(node); } virtual void apply(osg::Projection& node) { handle_callbacks_and_traverse(node); } From 853418db9493a3c3a68277aadaa49f0f078a3e3b Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 3 Feb 2017 17:42:21 +0100 Subject: [PATCH 04/11] Remove redundant handling of Geode in DisplayRequirementsVisitor --- include/osgUtil/DisplayRequirementsVisitor | 2 -- src/osgUtil/DisplayRequirementsVisitor.cpp | 12 ------------ 2 files changed, 14 deletions(-) diff --git a/include/osgUtil/DisplayRequirementsVisitor b/include/osgUtil/DisplayRequirementsVisitor index f29d277d7..0c397f931 100644 --- a/include/osgUtil/DisplayRequirementsVisitor +++ b/include/osgUtil/DisplayRequirementsVisitor @@ -48,8 +48,6 @@ class OSGUTIL_EXPORT DisplayRequirementsVisitor : public osg::NodeVisitor virtual void apply(osg::Node& node); - virtual void apply(osg::Geode& geode); - protected: osg::ref_ptr _ds; diff --git a/src/osgUtil/DisplayRequirementsVisitor.cpp b/src/osgUtil/DisplayRequirementsVisitor.cpp index 2d6dfc094..44e9b73e1 100644 --- a/src/osgUtil/DisplayRequirementsVisitor.cpp +++ b/src/osgUtil/DisplayRequirementsVisitor.cpp @@ -71,15 +71,3 @@ void DisplayRequirementsVisitor::apply(Node& node) traverse(node); } - -void DisplayRequirementsVisitor::apply(Geode& geode) -{ - osg::StateSet* geode_stateset = geode.getStateSet(); - if (geode_stateset) applyStateSet(*geode_stateset); - - for(unsigned int i = 0; i < geode.getNumDrawables(); i++ ) - { - osg::StateSet* stateset = geode.getDrawable(i)->getStateSet(); - if (stateset) applyStateSet(*stateset); - } -} From c901694290e86d1cce5f02afb559306ac5113077 Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 3 Feb 2017 17:43:42 +0100 Subject: [PATCH 05/11] Fix handling of in-scenegraph Drawables in DrawElementTypeSimplifier --- include/osgUtil/DrawElementTypeSimplifier | 2 +- src/osgUtil/DrawElementTypeSimplifier.cpp | 12 ++---------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/include/osgUtil/DrawElementTypeSimplifier b/include/osgUtil/DrawElementTypeSimplifier index 0af5b5db4..d090eb3d7 100644 --- a/include/osgUtil/DrawElementTypeSimplifier +++ b/include/osgUtil/DrawElementTypeSimplifier @@ -34,7 +34,7 @@ class OSGUTIL_EXPORT DrawElementTypeSimplifierVisitor : public osg::NodeVisitor META_NodeVisitor(osgUtil, DrawElementTypeSimplifierVisitor); - void apply(osg::Geode& node); + void apply(osg::Geometry& geom); }; } diff --git a/src/osgUtil/DrawElementTypeSimplifier.cpp b/src/osgUtil/DrawElementTypeSimplifier.cpp index 0102bc2a5..6397f8e06 100644 --- a/src/osgUtil/DrawElementTypeSimplifier.cpp +++ b/src/osgUtil/DrawElementTypeSimplifier.cpp @@ -66,18 +66,10 @@ void DrawElementTypeSimplifier::simplify(osg::Geometry & geometry) const } } -void DrawElementTypeSimplifierVisitor::apply(osg::Geode& node) +void DrawElementTypeSimplifierVisitor::apply(osg::Geometry& geom) { DrawElementTypeSimplifier dets; - - unsigned int numDrawables = node.getNumDrawables(); - for (unsigned int i = 0; i != numDrawables; ++i) - { - osg::Geometry * geom = dynamic_cast(node.getDrawable(i)); - if (geom) dets.simplify(*geom); - } - - osg::NodeVisitor::apply((osg::Node&)node); + dets.simplify(geom); } } From 9403a4c9490d8c61e8d4dc139a7788c112153d75 Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 3 Feb 2017 17:45:22 +0100 Subject: [PATCH 06/11] Fix unused parameter warning --- src/osgPlugins/sdl/ReaderWriterSDL.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/osgPlugins/sdl/ReaderWriterSDL.cpp b/src/osgPlugins/sdl/ReaderWriterSDL.cpp index 6e8c263c9..cae0ceec5 100644 --- a/src/osgPlugins/sdl/ReaderWriterSDL.cpp +++ b/src/osgPlugins/sdl/ReaderWriterSDL.cpp @@ -22,7 +22,7 @@ class ReaderWriterSDL : public osgDB::ReaderWriter virtual const char* className() const { return "SDL Device Integration plugin"; } - virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options* options =NULL) const + virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options* =NULL) const { if (file=="joystick.sdl") { From e48aa118b64868042d0b8dd0932502b0c1258043 Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 3 Feb 2017 17:48:18 +0100 Subject: [PATCH 07/11] Fix handling of in-scenegraph Drawables in MeshOptimizers --- include/osgUtil/MeshOptimizers | 4 ++-- src/osgUtil/MeshOptimizers.cpp | 17 ++++------------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/include/osgUtil/MeshOptimizers b/include/osgUtil/MeshOptimizers index e0ddd1e57..1de8eefe4 100644 --- a/include/osgUtil/MeshOptimizers +++ b/include/osgUtil/MeshOptimizers @@ -33,7 +33,7 @@ public: Optimizer::OptimizationOptions options) : BaseOptimizerVisitor(optimizer, options) {} void reset(); - void apply(osg::Geode& geode); + void apply(osg::Geometry& geom); typedef std::set GeometryList; GeometryList& getGeometryList() { return _geometryList; }; protected: @@ -77,7 +77,7 @@ class OSGUTIL_EXPORT VertexCacheMissVisitor : public osg::NodeVisitor public: VertexCacheMissVisitor(unsigned cacheSize = 16); void reset(); - virtual void apply(osg::Geode& geode); + virtual void apply(osg::Geometry& geom); void doGeometry(osg::Geometry& geom); unsigned misses; unsigned triangles; diff --git a/src/osgUtil/MeshOptimizers.cpp b/src/osgUtil/MeshOptimizers.cpp index 7de7753b2..52ff810b7 100644 --- a/src/osgUtil/MeshOptimizers.cpp +++ b/src/osgUtil/MeshOptimizers.cpp @@ -38,13 +38,9 @@ void GeometryCollector::reset() _geometryList.clear(); } -void GeometryCollector::apply(Geode& geode) +void GeometryCollector::apply(Geometry& geom) { - for(unsigned int i = 0; i < geode.getNumDrawables(); ++i ) - { - osg::Geometry* geom = dynamic_cast(geode.getDrawable(i)); - if (geom) _geometryList.insert(geom); - } + _geometryList.insert(&geom); } namespace @@ -890,14 +886,9 @@ void VertexCacheMissVisitor::reset() triangles = 0; } -void VertexCacheMissVisitor::apply(Geode& geode) +void VertexCacheMissVisitor::apply(Geometry& geom) { - for(unsigned int i = 0; i < geode.getNumDrawables(); ++i ) - { - osg::Geometry* geom = dynamic_cast(geode.getDrawable(i)); - if (geom) - doGeometry(*geom); - } + doGeometry(geom); } namespace From 4e1a2d3246f836757367cf897d5ffa005418a689 Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 3 Feb 2017 17:51:03 +0100 Subject: [PATCH 08/11] Fix handling of in-scenegraph Drawables in ShaderGenVisitor --- include/osgUtil/ShaderGen | 2 +- src/osgUtil/ShaderGen.cpp | 17 +++-------------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/include/osgUtil/ShaderGen b/include/osgUtil/ShaderGen index 9beb717c3..f30a9cd78 100644 --- a/include/osgUtil/ShaderGen +++ b/include/osgUtil/ShaderGen @@ -67,7 +67,7 @@ public: osg::StateSet *getRootStateSet() const { return _rootStateSet.get(); } void apply(osg::Node &node); - void apply(osg::Geode &geode); + void apply(osg::Drawable &drawable); void reset(); diff --git a/src/osgUtil/ShaderGen.cpp b/src/osgUtil/ShaderGen.cpp index dbcc19eeb..41f90e462 100644 --- a/src/osgUtil/ShaderGen.cpp +++ b/src/osgUtil/ShaderGen.cpp @@ -322,24 +322,13 @@ void ShaderGenVisitor::apply(osg::Node &node) _state->popStateSet(); } -void ShaderGenVisitor::apply(osg::Geode &geode) +void ShaderGenVisitor::apply(osg::Drawable &drawable) { - osg::StateSet *stateSet = geode.getStateSet(); + osg::StateSet *stateSet = drawable.getStateSet(); if (stateSet) _state->pushStateSet(stateSet); - for (unsigned int i=0; igetStateSet(); - if (ss) - _state->pushStateSet(ss); - - update(drawable); - - if (ss) - _state->popStateSet(); - } + update(&drawable); if (stateSet) _state->popStateSet(); From e38c3d0303cdfb229820f40246afe943f0304de1 Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 3 Feb 2017 17:55:32 +0100 Subject: [PATCH 09/11] Fix handling of in-scenegraph Drawables in SmoothingVisitor, TriStripVisitor and GraphicsCostEstimator --- include/osgUtil/SmoothingVisitor | 4 ++-- include/osgUtil/TriStripVisitor | 2 +- src/osg/GraphicsCostEstimator.cpp | 22 ++++++---------------- src/osgUtil/SmoothingVisitor.cpp | 8 ++------ src/osgUtil/TriStripVisitor.cpp | 8 ++------ 5 files changed, 13 insertions(+), 31 deletions(-) diff --git a/include/osgUtil/SmoothingVisitor b/include/osgUtil/SmoothingVisitor index 7afeda8ca..cccbb10d0 100644 --- a/include/osgUtil/SmoothingVisitor +++ b/include/osgUtil/SmoothingVisitor @@ -36,8 +36,8 @@ class OSGUTIL_EXPORT SmoothingVisitor : public osg::NodeVisitor /// smooth geoset by creating per vertex normals. static void smooth(osg::Geometry& geoset, double creaseAngle=osg::PI); - /// apply smoothing method to all geode geosets. - virtual void apply(osg::Geode& geode); + /// apply smoothing method to all geometries. + virtual void apply(osg::Geometry& geom); /// set the maximum angle, in radians, at which angle between adjacent triangles that normals are smoothed /// for edges that greater the shared vertices are duplicated diff --git a/include/osgUtil/TriStripVisitor b/include/osgUtil/TriStripVisitor index b73c60bdf..76ceccf0b 100644 --- a/include/osgUtil/TriStripVisitor +++ b/include/osgUtil/TriStripVisitor @@ -53,7 +53,7 @@ class OSGUTIL_EXPORT TriStripVisitor : public BaseOptimizerVisitor void stripify(); /// Accumulate the Geometry drawables to make into strips. - virtual void apply(osg::Geode& geode); + virtual void apply(osg::Geometry& geom); inline void setCacheSize( unsigned int size ) { diff --git a/src/osg/GraphicsCostEstimator.cpp b/src/osg/GraphicsCostEstimator.cpp index 36fec361e..b5b9895d8 100644 --- a/src/osg/GraphicsCostEstimator.cpp +++ b/src/osg/GraphicsCostEstimator.cpp @@ -205,15 +205,10 @@ public: traverse(node); } - virtual void apply(osg::Geode& geode) + virtual void apply(osg::Geometry& geom) { - apply(geode.getStateSet()); - for(unsigned int i=0; igetStateSet()); - osg::Geometry* geometry = geode.getDrawable(i)->asGeometry(); - if (geometry) apply(geometry); - } + apply(geom.getStateSet()); + apply(&geom); } void apply(osg::StateSet* stateset) @@ -282,15 +277,10 @@ public: traverse(node); } - virtual void apply(osg::Geode& geode) + virtual void apply(osg::Geometry& geom) { - apply(geode.getStateSet()); - for(unsigned int i=0; igetStateSet()); - osg::Geometry* geometry = geode.getDrawable(i)->asGeometry(); - if (geometry) apply(geometry); - } + apply(geom.getStateSet()); + apply(&geom); } void apply(osg::StateSet* stateset) diff --git a/src/osgUtil/SmoothingVisitor.cpp b/src/osgUtil/SmoothingVisitor.cpp index 2112fda6c..89eeb45b5 100644 --- a/src/osgUtil/SmoothingVisitor.cpp +++ b/src/osgUtil/SmoothingVisitor.cpp @@ -702,11 +702,7 @@ void SmoothingVisitor::smooth(osg::Geometry& geom, double creaseAngle) } -void SmoothingVisitor::apply(osg::Geode& geode) +void SmoothingVisitor::apply(osg::Geometry& geom) { - for(unsigned int i = 0; i < geode.getNumDrawables(); i++ ) - { - osg::Geometry* geom = dynamic_cast(geode.getDrawable(i)); - if (geom) smooth(*geom, _creaseAngle); - } + smooth(geom, _creaseAngle); } diff --git a/src/osgUtil/TriStripVisitor.cpp b/src/osgUtil/TriStripVisitor.cpp index 24ae1ea00..074bfb890 100644 --- a/src/osgUtil/TriStripVisitor.cpp +++ b/src/osgUtil/TriStripVisitor.cpp @@ -629,11 +629,7 @@ void TriStripVisitor::stripify() } } -void TriStripVisitor::apply(Geode& geode) +void TriStripVisitor::apply(Geometry& geom) { - for(unsigned int i = 0; i < geode.getNumDrawables(); ++i ) - { - osg::Geometry* geom = dynamic_cast(geode.getDrawable(i)); - if (geom) _geometryList.insert(geom); - } + _geometryList.insert(&geom); } From fdf6d55b9da38e7a77b8557c4562767e89b8e33b Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 3 Feb 2017 18:01:08 +0100 Subject: [PATCH 10/11] Fix handling of in-scenegraph Drawables in osgShadow --- src/osgShadow/OccluderGeometry.cpp | 17 ++++------------- src/osgShadow/ViewDependentShadowMap.cpp | 12 +++--------- 2 files changed, 7 insertions(+), 22 deletions(-) diff --git a/src/osgShadow/OccluderGeometry.cpp b/src/osgShadow/OccluderGeometry.cpp index 178e17041..4189f0f12 100644 --- a/src/osgShadow/OccluderGeometry.cpp +++ b/src/osgShadow/OccluderGeometry.cpp @@ -77,22 +77,13 @@ public: if (transform.getStateSet()) popState(); } - void apply(osg::Geode& geode) + void apply(osg::Drawable& drawable) { - if (geode.getStateSet()) pushState(geode.getStateSet()); + if (drawable.getStateSet()) pushState(drawable.getStateSet()); - for(unsigned int i=0; igetStateSet()) pushState(drawable->getStateSet()); - - apply(geode.getDrawable(i)); - - if (drawable->getStateSet()) popState(); - } - - if (geode.getStateSet()) popState(); + if (drawable.getStateSet()) popState(); } void pushState(osg::StateSet* stateset) diff --git a/src/osgShadow/ViewDependentShadowMap.cpp b/src/osgShadow/ViewDependentShadowMap.cpp index 6336662aa..f72f2ce15 100644 --- a/src/osgShadow/ViewDependentShadowMap.cpp +++ b/src/osgShadow/ViewDependentShadowMap.cpp @@ -274,20 +274,14 @@ public: popCurrentMask(); } - void apply(osg::Geode& node) + void apply(osg::Drawable& drawable) { - if (isCulled(node)) return; + if (isCulled(drawable)) return; // push the culling mode. pushCurrentMask(); - for(unsigned int i=0; igetBoundingBox()); - } - } + updateBound(drawable.getBoundingBox()); // pop the culling mode. popCurrentMask(); From 6deefe0646c6aa426371042a4951ba58d30e0f98 Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 3 Feb 2017 18:10:37 +0100 Subject: [PATCH 11/11] Remove seemingly redundant handling of Geode in GLObjectsVisitor --- include/osgUtil/GLObjectsVisitor | 5 ----- src/osgUtil/GLObjectsVisitor.cpp | 22 ---------------------- 2 files changed, 27 deletions(-) diff --git a/include/osgUtil/GLObjectsVisitor b/include/osgUtil/GLObjectsVisitor index e2a075145..b9a130f3e 100644 --- a/include/osgUtil/GLObjectsVisitor +++ b/include/osgUtil/GLObjectsVisitor @@ -94,11 +94,6 @@ class OSGUTIL_EXPORT GLObjectsVisitor : public osg::NodeVisitor /** Simply traverse using standard NodeVisitor traverse method.*/ virtual void apply(osg::Node& node); - /** For each Geode visited set the display list usage according to the - * _displayListMode. - */ - virtual void apply(osg::Geode& node); - void apply(osg::Drawable& drawable); void apply(osg::StateSet& stateset); diff --git a/src/osgUtil/GLObjectsVisitor.cpp b/src/osgUtil/GLObjectsVisitor.cpp index 3731cfd34..b194b7990 100644 --- a/src/osgUtil/GLObjectsVisitor.cpp +++ b/src/osgUtil/GLObjectsVisitor.cpp @@ -53,28 +53,6 @@ void GLObjectsVisitor::apply(osg::Node& node) } } -void GLObjectsVisitor::apply(osg::Geode& node) -{ - bool programSetBefore = _lastCompiledProgram.valid(); - - if (node.getStateSet()) - { - apply(*(node.getStateSet())); - } - - traverse(node); - - bool programSetAfter = _lastCompiledProgram.valid(); - if (!programSetBefore && programSetAfter) - { - osg::State* state = _renderInfo.getState(); - osg::GLExtensions* extensions = state->get(); - extensions->glUseProgram(0); - state->setLastAppliedProgramObject(0); - _lastCompiledProgram = 0; - } -} - void GLObjectsVisitor::apply(osg::Drawable& drawable) { if (_drawablesAppliedSet.count(&drawable)!=0) return;