diff --git a/examples/osgmemorytest/osgmemorytest.cpp b/examples/osgmemorytest/osgmemorytest.cpp index e48c314b4..e03357169 100644 --- a/examples/osgmemorytest/osgmemorytest.cpp +++ b/examples/osgmemorytest/osgmemorytest.cpp @@ -26,6 +26,7 @@ #include #include +#include class MemoryTest : public osg::Referenced { @@ -312,32 +313,73 @@ int main( int argc, char **argv ) { osg::ArgumentParser arguments(&argc,argv); - typedef std::list< osg::ref_ptr > Tests; - Tests tests; + arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName()); + arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" tests OpenGL and Windowing memory scalability.."); + arguments.getApplicationUsage()->addCommandLineOption("-h or --help","List command line options."); + arguments.getApplicationUsage()->addCommandLineOption("--pbuffer ","Create a pixel buffer of specified dimensions."); + arguments.getApplicationUsage()->addCommandLineOption("--pbuffer","Create a 512x512 pixel buffer."); + arguments.getApplicationUsage()->addCommandLineOption("--window ","Create a graphics window of specified dimensions."); + arguments.getApplicationUsage()->addCommandLineOption("--window","Create a 512x512 graphics window."); + arguments.getApplicationUsage()->addCommandLineOption("--delay ","Set a delay in microseconds before all OpenGL object operations."); + arguments.getApplicationUsage()->addCommandLineOption("--texture ","Allocate a 3D texture of specified dimensions."); + arguments.getApplicationUsage()->addCommandLineOption("--texture ","Allocate a 2D texture of specified dimensions."); + arguments.getApplicationUsage()->addCommandLineOption("--texture ","Allocate a 1D texture of specified dimensions."); + arguments.getApplicationUsage()->addCommandLineOption("--geometry ","Allocate a osg::Geometry representing a grid of specified size, using OpenGL Dislay Lists."); + arguments.getApplicationUsage()->addCommandLineOption("--geometry-va ","Allocate a osg::Geometry representing a grid of specified size, using Vertex Arrays."); + arguments.getApplicationUsage()->addCommandLineOption("--geometry-vbo ","Allocate a osg::Geometry representing a grid of specified size, using Vertex Buffer Objects."); + arguments.getApplicationUsage()->addCommandLineOption("--fbo ","Allocate a FrameBufferObject of specified dimensions."); + arguments.getApplicationUsage()->addCommandLineOption("-c ","Set the number of contexts to create of each type specified."); + arguments.getApplicationUsage()->addCommandLineOption("-g ","Set the number of GL objects to create of each type specified."); + + if (arguments.read("-h") || arguments.read("--help")) + { + arguments.getApplicationUsage()->write(std::cout, osg::ApplicationUsage::COMMAND_LINE_OPTION); + return 1; + } + + // report any errors if they have occurred when parsing the program arguments. + if (arguments.errors()) + { + arguments.writeErrorMessages(std::cout); + return 1; + } + + if (arguments.argc()<=1) + { + arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION); + return 1; + } + + + typedef std::list< osg::ref_ptr > GLMemoryTests; + typedef std::list< osg::ref_ptr > ContextTests; + + ContextTests contextTests; + GLMemoryTests glMemoryTests; int width, height, depth; - while(arguments.read("--pbuffer",width,height)) { tests.push_back(new ContextTest(width, height, true)); } - while(arguments.read("--pbuffer")) { tests.push_back(new ContextTest(512, 512, true)); } + while(arguments.read("--pbuffer",width,height)) { contextTests.push_back(new ContextTest(width, height, true)); } + while(arguments.read("--pbuffer")) { contextTests.push_back(new ContextTest(512, 512, true)); } - while(arguments.read("--window",width,height)) { tests.push_back(new ContextTest(width, height, false)); } - while(arguments.read("--window")) { tests.push_back(new ContextTest(512,512, false)); } + while(arguments.read("--window",width,height)) { contextTests.push_back(new ContextTest(width, height, false)); } + while(arguments.read("--window")) { contextTests.push_back(new ContextTest(512,512, false)); } - while(arguments.read("--texture",width,height,depth)) { tests.push_back(new TextureTest(width,height,depth)); } - while(arguments.read("--texture",width,height)) { tests.push_back(new TextureTest(width,height,1)); } - while(arguments.read("--texture",width)) { tests.push_back(new TextureTest(width,1,1)); } + while(arguments.read("--texture",width,height,depth)) { glMemoryTests.push_back(new TextureTest(width,height,depth)); } + while(arguments.read("--texture",width,height)) { glMemoryTests.push_back(new TextureTest(width,height,1)); } + while(arguments.read("--texture",width)) { glMemoryTests.push_back(new TextureTest(width,1,1)); } - while(arguments.read("--fbo",width,height,depth)) { tests.push_back(new FboTest(width,height,depth)); } - while(arguments.read("--fbo",width,height)) { tests.push_back(new FboTest(width,height,2)); } - while(arguments.read("--fbo")) { tests.push_back(new FboTest(1024,1024,2)); } + while(arguments.read("--fbo",width,height,depth)) { glMemoryTests.push_back(new FboTest(width,height,depth)); } + while(arguments.read("--fbo",width,height)) { glMemoryTests.push_back(new FboTest(width,height,2)); } + while(arguments.read("--fbo")) { glMemoryTests.push_back(new FboTest(1024,1024,2)); } - while(arguments.read("--geometry",width,height)) { tests.push_back(new GeometryTest(GeometryTest::DISPLAY_LIST,width,height)); } - while(arguments.read("--geometry")) { tests.push_back(new GeometryTest(GeometryTest::DISPLAY_LIST,64,64)); } + while(arguments.read("--geometry",width,height)) { glMemoryTests.push_back(new GeometryTest(GeometryTest::DISPLAY_LIST,width,height)); } + while(arguments.read("--geometry")) { glMemoryTests.push_back(new GeometryTest(GeometryTest::DISPLAY_LIST,64,64)); } - while(arguments.read("--geometry-vbo",width,height)) { tests.push_back(new GeometryTest(GeometryTest::VERTEX_BUFFER_OBJECT,width,height)); } - while(arguments.read("--geometry-vbo")) { tests.push_back(new GeometryTest(GeometryTest::VERTEX_BUFFER_OBJECT,64,64)); } + while(arguments.read("--geometry-vbo",width,height)) { glMemoryTests.push_back(new GeometryTest(GeometryTest::VERTEX_BUFFER_OBJECT,width,height)); } + while(arguments.read("--geometry-vbo")) { glMemoryTests.push_back(new GeometryTest(GeometryTest::VERTEX_BUFFER_OBJECT,64,64)); } - while(arguments.read("--geometry-va",width,height)) { tests.push_back(new GeometryTest(GeometryTest::VERTEX_ARRAY,width,height)); } - while(arguments.read("--geometry-va")) { tests.push_back(new GeometryTest(GeometryTest::VERTEX_ARRAY,64,64)); } + while(arguments.read("--geometry-va",width,height)) { glMemoryTests.push_back(new GeometryTest(GeometryTest::VERTEX_ARRAY,width,height)); } + while(arguments.read("--geometry-va")) { glMemoryTests.push_back(new GeometryTest(GeometryTest::VERTEX_ARRAY,64,64)); } unsigned int sleepTime = 0; while(arguments.read("--delay",sleepTime)) {} @@ -348,28 +390,17 @@ int main( int argc, char **argv ) int maxNumGLIterations = 1000; while(arguments.read("-g",maxNumGLIterations)) {} - typedef std::list< osg::ref_ptr > GLMemoryTests; - typedef std::list< osg::ref_ptr > ContextTests; - - ContextTests contextTests; - GLMemoryTests glMemoryTests; - - for(Tests::iterator itr = tests.begin(); - itr != tests.end(); - ++itr) + // any option left unread are converted into errors to write out later. + arguments.reportRemainingOptionsAsUnrecognized(); + + // report any errors if they have occurred when parsing the program arguments. + if (arguments.errors()) { - MemoryTest* test = itr->get(); - if (dynamic_cast(test)!=0) - { - glMemoryTests.push_back(dynamic_cast(test)); - } - else if (dynamic_cast(test)!=0) - { - contextTests.push_back(dynamic_cast(test)); - } + arguments.writeErrorMessages(std::cout); + return 1; } - + typedef std::list< osg::ref_ptr > Contexts; typedef std::list< osg::ref_ptr > GLObjects; Contexts allocatedContexts;