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

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