void ShaderGenerator::apply(osg::Group& group) { if ( !_active ) return; traverse(group); #if 0 std::set<VirtualProgram*> childVPs; unsigned childrenWithVP = 0; for(unsigned i=0; i<group.getNumChildren(); ++i) { osg::StateSet* stateset = group.getChild(i)->getStateSet(); if ( !stateset ) break; VirtualProgram* vp = dynamic_cast<VirtualProgram*>(stateset->getAttribute(VirtualProgram::SA_TYPE)); if ( vp ) { childVPs.insert( vp ); childrenWithVP++; } } if ( childrenWithVP == group.getNumChildren() && childVPs.size() == 1 ) { group.getOrCreateStateSet()->setAttributeAndModes( *childVPs.begin(), 1 ); for(unsigned i=0; i<group.getNumChildren(); ++i) { group.getChild(i)->getStateSet()->removeAttribute(VirtualProgram::SA_TYPE); } } #endif }
void TileMapper::apply(osg::Group& node) { if (node.getName()=="TileContent") { _containsGeode = true; return; } if (isCulled(node)) return; // push the culling mode. pushCurrentMask(); TileIdentifier* tid = dynamic_cast<TileIdentifier*>(node.getUserData()); if (tid) { _tileStack.push_back(TileStack::value_type(*tid,&node)); _containsGeode = false; } traverse(node); if (tid) { if (_containsGeode) { insertTile(*tid); _containsGeode = false; #if 0 std::cout<<"found Group="<<tid->lod <<" X="<<tid->x <<" Y="<<tid->y <<" ptr="<<&node<<std::endl; std::cout<<" inheritance list "<<_tileStack.size()<<std::endl; for(TileStack::iterator itr=_tileStack.begin(); itr!=_tileStack.end(); ++itr) { std::cout<<" LOD="<<itr->first.lod <<" X="<<itr->first.x <<" Y="<<itr->first.y <<" className="<<itr->second->className() <<" ptr="<<itr->second<<std::endl; } osg::StateSet* stateset = node.getOrCreateStateSet(); osg::Material* material = new osg::Material; material->setColorMode(osg::Material::OFF); stateset->setAttribute(material); switch(tid->lod) { case(0): material->setEmission(osg::Material::FRONT_AND_BACK,osg::Vec4(1.0f,1.0f,1.0f,1.0f)); break; case(1): material->setEmission(osg::Material::FRONT_AND_BACK,osg::Vec4(1.0f,0.0f,0.0f,1.0f)); break; case(2): material->setEmission(osg::Material::FRONT_AND_BACK,osg::Vec4(0.0f,1.0f,0.0f,1.0f)); break; case(3): material->setEmission(osg::Material::FRONT_AND_BACK,osg::Vec4(0.0f,0.0f,1.0f,1.0f)); break; case(4): material->setEmission(osg::Material::FRONT_AND_BACK,osg::Vec4(1.0f,0.0f,1.0f,1.0f)); break; } #endif } _tileStack.pop_back(); } // pop the culling mode. popCurrentMask(); }