void ShaderGenerator::apply( osg::Geode& geode ) { if ( !_active ) return; osg::ref_ptr<osg::StateSet> ss = geode.getStateSet(); if ( ss.valid() ) { _state->pushStateSet( ss.get() ); osg::ref_ptr<osg::StateSet> replacement; if ( processGeometry(ss.get(), replacement) ) { _state->popStateSet(); // optimize state set sharing if ( _stateSetCache.valid() ) _stateSetCache->share(replacement, replacement); geode.setStateSet( replacement.get() ); _state->pushStateSet( replacement.get() ); } } for( unsigned d = 0; d < geode.getNumDrawables(); ++d ) { apply( geode.getDrawable(d) ); } if ( ss.valid() ) { _state->popStateSet(); } }
void ShaderGenerator::apply( osg::Geode& geode ) { osg::ref_ptr<osg::StateSet> ss = geode.getStateSet(); if ( ss.valid() ) { _state->pushStateSet( ss.get() ); osg::ref_ptr<osg::StateSet> replacement; if ( processGeometry(ss.get(), replacement) ) { _state->popStateSet(); geode.setStateSet( replacement.get() ); _state->pushStateSet( replacement.get() ); } } for( unsigned d = 0; d < geode.getNumDrawables(); ++d ) { apply( geode.getDrawable(d) ); } if ( ss.valid() ) { _state->popStateSet(); } }
virtual void apply(osg::Geode& node) { if (node.getStateSet()) { node.setStateSet(0); ++_numStateSetRemoved; } traverse(node); }
virtual void apply(osg::Geode& node) { if (node.getStateSet()) { node.setStateSet(0); ++_numStateSetRemoved; } for(unsigned int i=0;i<node.getNumDrawables();++i) { osg::Drawable* drawable = node.getDrawable(i); if (drawable && drawable->getStateSet()) { drawable->setStateSet(0); ++_numStateSetRemoved; } } traverse(node); }
void CountStateSets::apply( osg::Geode& node ) { if( !processStateSet( node.getStateSet() ) && _removeEmptyStateSets ) { node.setStateSet( NULL ); _removedStateSets++; } unsigned int idx; for( idx=0; idx<node.getNumDrawables(); idx++ ) { osg::Drawable* draw = node.getDrawable( idx ); if( !processStateSet( draw->getStateSet() ) && _removeEmptyStateSets ) { draw->setStateSet( NULL ); _removedStateSets++; } } traverse( node ); }
void ShaderGenerator::apply( osg::Geode& node ) { if ( !_active ) return; if ( ignore(&node) ) return; if ( _duplicateSharedSubgraphs ) duplicateSharedNode(node); osg::ref_ptr<osg::StateSet> stateset = node.getStateSet(); if ( stateset.valid() ) { _state->pushStateSet( stateset.get() ); } unsigned numDrawables = node.getNumDrawables(); bool traverseDrawables = true; #ifdef PROMOTE_EQUIVALENT_DRAWABLE_VP_TO_GEODE // This block checks whether all the geode's drawables are equivalent, // i.e., they are the same type (geometry or text) and none of them // have their own state sets. IF that's the case, we can create a // single shader program for the entire geode. This is an optimization. if ( stateset.valid() ) { unsigned d; unsigned numInheritingText = 0, numInheritingGeometry = 0; for( d = 0; d < numDrawables; ++d ) { osg::Drawable* drawable = node.getDrawable(d); if ( drawable->getStateSet() == 0L ) { if ( drawable->asGeometry() ) numInheritingGeometry++; else if ( dynamic_cast<osgText::Text*>(drawable) ) numInheritingText++; } } if (numInheritingGeometry == numDrawables ) { osg::ref_ptr<osg::StateSet> replacement; if ( processGeometry(stateset.get(), replacement) ) { node.setStateSet(replacement.get() ); traverseDrawables = false; } } else if (numInheritingText == numDrawables ) { osg::ref_ptr<osg::StateSet> replacement; if ( processText(stateset.get(), replacement) ) { node.setStateSet(replacement.get() ); traverseDrawables = false; } } } #endif // Drawables have state sets, so let's traverse them. if ( traverseDrawables ) { for( unsigned d = 0; d < node.getNumDrawables(); ++d ) { apply( node.getDrawable(d) ); } } if ( stateset.valid() ) { _state->popStateSet(); } }