From 2014e852595bab8fdbfbcd2b9ca47487fee5c6ee Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 21 Oct 2010 16:28:23 +0000 Subject: [PATCH] Added new osganalysis example as a testbed for profiling peformance of various aspects of OSG/OpenGL and scene graphs. --- examples/CMakeLists.txt | 1 + examples/osganalysis/CMakeLists.txt | 4 + examples/osganalysis/osganalysis.cpp | 132 +++++++++++++++++++++++++++ 3 files changed, 137 insertions(+) create mode 100644 examples/osganalysis/CMakeLists.txt create mode 100644 examples/osganalysis/osganalysis.cpp diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 766534c4e..493c47f9c 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -18,6 +18,7 @@ SET(TARGET_COMMON_LIBRARIES IF(DYNAMIC_OPENSCENEGRAPH) ADD_SUBDIRECTORY(osg2cpp) + ADD_SUBDIRECTORY(osganalysis) ADD_SUBDIRECTORY(osganimate) ADD_SUBDIRECTORY(osgautocapture) ADD_SUBDIRECTORY(osgautotransform) diff --git a/examples/osganalysis/CMakeLists.txt b/examples/osganalysis/CMakeLists.txt new file mode 100644 index 000000000..085dff1cf --- /dev/null +++ b/examples/osganalysis/CMakeLists.txt @@ -0,0 +1,4 @@ +SET(TARGET_SRC osganalysis.cpp) + +#### end var setup ### +SETUP_EXAMPLE(osganalysis) diff --git a/examples/osganalysis/osganalysis.cpp b/examples/osganalysis/osganalysis.cpp new file mode 100644 index 000000000..785e590b7 --- /dev/null +++ b/examples/osganalysis/osganalysis.cpp @@ -0,0 +1,132 @@ +/* OpenSceneGraph example, osgterrain. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + + +#include +#include +#include +#include +#include + + +struct CustomCompileCompletedCallback : public osgUtil::IncrementalCompileOperation::CompileCompletedCallback +{ + CustomCompileCompletedCallback(): + completed(false) {} + + virtual bool compileCompleted(osgUtil::IncrementalCompileOperation::CompileSet* compileSet) + { + OSG_NOTICE<<"compileCompleted"< incrementalCompile = new osgUtil::IncrementalCompileOperation; + viewer.setIncrementalCompileOperation(incrementalCompile.get()); + + double timeBetweenMerges = 2.0; + while(arguments.read("--interval",timeBetweenMerges)) {} + + typedef std::vector< osg::ref_ptr > Models; + Models models; + + for(int pos=1;posgetName().empty()) node->setName( arguments[pos] ); + models.push_back(node); + } + } + } + + OSG_NOTICE<<"models.size()="< group = new osg::Group; + + unsigned int modelIndex = 0; + + group->addChild(models[modelIndex++].get()); + + viewer.setSceneData(group); + + viewer.realize(); + + double timeOfLastMerge = viewer.getFrameStamp()->getReferenceTime(); + + osg::ref_ptr compileCompletedCallback; + + while(!viewer.done()) + { + viewer.frame(); + + double currentTime = viewer.getFrameStamp()->getReferenceTime(); + + if (!compileCompletedCallback && + modelIndextimeBetweenMerges) + { + OSG_NOTICE<<"Compiling model "< compileSet = + new osgUtil::IncrementalCompileOperation::CompileSet(models[modelIndex].get()); + + compileCompletedCallback = new CustomCompileCompletedCallback; + + compileSet->_compileCompletedCallback = compileCompletedCallback; + + incrementalCompile->add(compileSet.get()); + } + + if (compileCompletedCallback.valid() && compileCompletedCallback->completed) + { + OSG_NOTICE<<"Merging model "<removeChildren(0,group->getNumChildren()); + + group->addChild(models[modelIndex++].get()); + + viewer.home(); + } + + } + + return 0; +}