From e5b76975a9c23ca1bc495c75fcf6875d82452b08 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 25 Nov 2009 16:31:14 +0000 Subject: [PATCH] For testing purposes added code path and options for testing viewer creation in series, including with enabling of VBO's. Options are: osgcamera -r 5 --vbo cow.osg Which repeats construction of the viewer 5 times in a row, and enables VBO, and on each repeat a new model is loaded. osgcamera -r 2 --vbo --shared cow.osg Which repeats construction of the viewer 2 times in a row, and enables VBO, and on each loads the model once and shares it between each instance of the viewer. --- examples/osgcamera/osgcamera.cpp | 46 ++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/examples/osgcamera/osgcamera.cpp b/examples/osgcamera/osgcamera.cpp index c2d61ec34..c7b5934d4 100644 --- a/examples/osgcamera/osgcamera.cpp +++ b/examples/osgcamera/osgcamera.cpp @@ -173,6 +173,23 @@ void multipleWindowMultipleCameras(osgViewer::Viewer& viewer, bool multipleScree } } +class EnableVBOVisitor : public osg::NodeVisitor +{ +public: + EnableVBOVisitor(): + osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {} + + void apply(osg::Geode& geode) + { + for(unsigned int i=0; iasGeometry(); + osg::notify(osg::NOTICE)<<"Enabling VBO"<setUseVertexBufferObjects(true); + } + } +}; + int main( int argc, char **argv ) { // use an ArgumentParser object to manage the program arguments. @@ -187,9 +204,22 @@ int main( int argc, char **argv ) unsigned int numRepeats = 2; if (arguments.read("--repeat",numRepeats) || arguments.read("-r",numRepeats) || arguments.read("--repeat") || arguments.read("-r")) { + bool sharedModel = arguments.read("--shared"); + bool enableVBO = arguments.read("--vbo"); + osg::ref_ptr model; - if (sharedModel) model = osgDB::readNodeFiles(arguments); + if (sharedModel) + { + model = osgDB::readNodeFiles(arguments); + if (!model) return 0; + + if (enableVBO) + { + EnableVBOVisitor enableVBOs; + model->accept(enableVBOs); + } + } osgViewer::Viewer::ThreadingModel threadingModel = osgViewer::Viewer::AutomaticSelection; while (arguments.read("-s")) { threadingModel = osgViewer::Viewer::SingleThreaded; } @@ -206,7 +236,19 @@ int main( int argc, char **argv ) viewer.setThreadingModel(threadingModel); if (sharedModel) viewer.setSceneData(model.get()); - else viewer.setSceneData(osgDB::readNodeFiles(arguments)); + else + { + osg::ref_ptr node = osgDB::readNodeFiles(arguments); + if (!node) return 0; + + if (enableVBO) + { + EnableVBOVisitor enableVBOs; + node->accept(enableVBOs); + } + + viewer.setSceneData(node.get()); + } viewer.run();