Merge pull request #197 from scrawl/geodefix

More fixes for Geode/Drawable handling in visitors
This commit is contained in:
OpenSceneGraph git repository
2017-02-03 18:03:13 +00:00
committed by GitHub
23 changed files with 40 additions and 164 deletions

View File

@@ -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

View File

@@ -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); }

View File

@@ -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<osg::DisplaySettings> _ds;

View File

@@ -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);
};
}

View File

@@ -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);

View File

@@ -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<osg::Geometry*> 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;

View File

@@ -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();

View File

@@ -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;i<geode.getNumDrawables();++i)
{
osg::Geometry* geometry = geode.getDrawable(i)->asGeometry();
if (geometry)
{
simplify(*geometry);
}
}
simplify(geom);
}
/** simply the geometry.*/

View File

@@ -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

View File

@@ -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 )
{

View File

@@ -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); }

View File

@@ -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; i<geode.getNumDrawables(); ++i)
{
apply(geode.getDrawable(i)->getStateSet());
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; i<geode.getNumDrawables(); ++i)
{
apply(geode.getDrawable(i)->getStateSet());
osg::Geometry* geometry = geode.getDrawable(i)->asGeometry();
if (geometry) apply(geometry);
}
apply(geom.getStateSet());
apply(&geom);
}
void apply(osg::StateSet* stateset)

View File

@@ -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;i<geode.getNumDrawables();++i)
{
osg::Drawable* drawable = geode.getDrawable(i);
if(drawable)
{
ss = drawable->getStateSet();
if(ss) process(ss, drawable);
}
}
}
bool SharedStateManager::isShared(osg::StateSet* ss)
{

View File

@@ -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")
{

View File

@@ -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; i<geode.getNumDrawables(); ++i)
{
osg::Drawable* drawable = geode.getDrawable(i);
apply(&drawable);
if (drawable->getStateSet()) pushState(drawable->getStateSet());
apply(geode.getDrawable(i));
if (drawable->getStateSet()) popState();
}
if (geode.getStateSet()) popState();
if (drawable.getStateSet()) popState();
}
void pushState(osg::StateSet* stateset)

View File

@@ -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; i<node.getNumDrawables();++i)
{
if (node.getDrawable(i))
{
updateBound(node.getDrawable(i)->getBoundingBox());
}
}
updateBound(drawable.getBoundingBox());
// pop the culling mode.
popCurrentMask();

View File

@@ -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);
}
}

View File

@@ -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<osg::Geometry*>(node.getDrawable(i));
if (geom) dets.simplify(*geom);
}
osg::NodeVisitor::apply((osg::Node&)node);
dets.simplify(geom);
}
}

View File

@@ -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<osg::GLExtensions>();
extensions->glUseProgram(0);
state->setLastAppliedProgramObject(0);
_lastCompiledProgram = 0;
}
}
void GLObjectsVisitor::apply(osg::Drawable& drawable)
{
if (_drawablesAppliedSet.count(&drawable)!=0) return;

View File

@@ -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<osg::Geometry*>(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<osg::Geometry*>(geode.getDrawable(i));
if (geom)
doGeometry(*geom);
}
doGeometry(geom);
}
namespace

View File

@@ -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; i<geode.getNumDrawables(); ++i)
{
osg::Drawable *drawable = geode.getDrawable(i);
osg::StateSet *ss = drawable->getStateSet();
if (ss)
_state->pushStateSet(ss);
update(drawable);
if (ss)
_state->popStateSet();
}
update(&drawable);
if (stateSet)
_state->popStateSet();

View File

@@ -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<osg::Geometry*>(geode.getDrawable(i));
if (geom) smooth(*geom, _creaseAngle);
}
smooth(geom, _creaseAngle);
}

View File

@@ -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<osg::Geometry*>(geode.getDrawable(i));
if (geom) _geometryList.insert(geom);
}
_geometryList.insert(&geom);
}