|
| 1 | + |
| 2 | +/// This program test robustness of VAS path |
| 3 | +/// it collects geometries given in arg then add and remove them at runtime |
| 4 | +/// stressing osg vas policy as well as driver vao policy |
| 5 | + |
| 6 | +#include <osgUtil/MeshOptimizers> |
| 7 | +#include <osgGA/TrackballManipulator> |
| 8 | +#include <osgGA/FirstPersonManipulator> |
| 9 | + |
| 10 | +#include <osgViewer/Viewer> |
| 11 | +#include <osgViewer/ViewerEventHandlers> |
| 12 | + |
| 13 | +#include <osgDB/ReadFile> |
| 14 | + |
| 15 | +class GeomLoaderCB : public osg::NodeCallback |
| 16 | +{ |
| 17 | + int _thresremoval; int _nbaddedatatime; |
| 18 | + std::list<osg::ref_ptr<osg::Geometry> > _geoms; |
| 19 | +public: |
| 20 | + GeomLoaderCB(int thresremoval=1, int nbaddedatatime=1):_nbaddedatatime(nbaddedatatime), _thresremoval(thresremoval) {} |
| 21 | + |
| 22 | + void setGeometryList(const osgUtil::GeometryCollector::GeometryList& geomlist) { |
| 23 | + for(auto geom : geomlist) _geoms.push_back(geom); |
| 24 | + } |
| 25 | + |
| 26 | + virtual void operator()(osg::Node* node, osg::NodeVisitor* nv) { |
| 27 | + osg::Group* gr = node->asGroup(); |
| 28 | + if(!gr || _geoms.empty() ) return; |
| 29 | + |
| 30 | + if(gr->getNumChildren()>_thresremoval) |
| 31 | + { |
| 32 | + osg::Geometry* removedgeom = gr->getChild(0)->asGeometry(); |
| 33 | + if(removedgeom) { |
| 34 | + OSG_WARN<<"removing "<< removedgeom <<std::endl; |
| 35 | + gr->removeChildren(0,1); |
| 36 | + } |
| 37 | + return; |
| 38 | + } |
| 39 | + |
| 40 | + std::list<osg::ref_ptr<osg::Geometry> > ::iterator it= _geoms.begin(); |
| 41 | + int cpt=0; |
| 42 | + while(it!=_geoms.end() && cpt++<_nbaddedatatime ) { |
| 43 | + osg::Geometry *addedgeom = static_cast<osg::Geometry*>((*it)->clone(osg::CopyOp::DEEP_COPY_ALL)); |
| 44 | + addedgeom->setUseDisplayList(false); |
| 45 | + addedgeom->setUseVertexBufferObjects(true); |
| 46 | + addedgeom->setUseVertexArrayObject(true); |
| 47 | + gr->addChild(addedgeom); |
| 48 | + OSG_WARN<<"add "<< addedgeom <<std::endl; |
| 49 | + it=_geoms.erase(it); |
| 50 | + } |
| 51 | + return; |
| 52 | + } |
| 53 | + |
| 54 | +}; |
| 55 | + |
| 56 | + |
| 57 | +int main(int argc, char **argv) |
| 58 | +{ |
| 59 | + osg::ArgumentParser args(&argc,argv); |
| 60 | + unsigned int geomcountaddedatatime=1, geomcountabovewichweremove=2; |
| 61 | + while(args.read("--add",geomcountaddedatatime) ) { } |
| 62 | + while(args.read("--remove",geomcountabovewichweremove) ) { } |
| 63 | + osgUtil::GeometryCollector geomcollector(0,osgUtil::Optimizer::ALL_OPTIMIZATIONS); |
| 64 | + |
| 65 | + osg::ref_ptr<osg::Node > loaded = osgDB::readNodeFiles(args); |
| 66 | + if(!loaded.valid()) loaded = osgDB::readNodeFile("testdata/BIGCITY.ive"); |
| 67 | + if(loaded.valid()) |
| 68 | + { |
| 69 | + loaded->accept(geomcollector); |
| 70 | + |
| 71 | + osg::Group * root=new osg::Group; |
| 72 | + root->setDataVariance(osg::Object::DYNAMIC); |
| 73 | + GeomLoaderCB * loader=new GeomLoaderCB(geomcountabovewichweremove,geomcountaddedatatime); |
| 74 | + loader->setGeometryList( geomcollector.getGeometryList() ); |
| 75 | + loaded=0; |
| 76 | + root->setUpdateCallback(loader); |
| 77 | + |
| 78 | + osgViewer::Viewer viewer; |
| 79 | + viewer.setThreadingModel(osgViewer::ViewerBase::SingleThreaded); |
| 80 | + viewer.addEventHandler(new osgViewer::StatsHandler); |
| 81 | + viewer.addEventHandler(new osgViewer::WindowSizeHandler); |
| 82 | + viewer.addEventHandler(new osgViewer::ThreadingHandler); |
| 83 | + viewer.setRunFrameScheme(osgViewer::ViewerBase::CONTINUOUS); |
| 84 | + |
| 85 | + viewer.setSceneData(root); |
| 86 | + |
| 87 | + viewer.realize(); |
| 88 | + viewer.run(); |
| 89 | + } |
| 90 | + |
| 91 | +} |
0 commit comments