Show
Ignore:
Timestamp:
11/11/08 17:59:58 (6 years ago)
Author:
robert
Message:

Added command line argument docs and support for -h/--help command line options

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/examples/osgmemorytest/osgmemorytest.cpp

    r9144 r9146  
    2727 
    2828#include <stdio.h> 
     29#include <iostream> 
    2930 
    3031class MemoryTest : public osg::Referenced 
     
    313314    osg::ArgumentParser arguments(&argc,argv); 
    314315     
    315     typedef std::list< osg::ref_ptr<MemoryTest> > Tests; 
    316     Tests tests; 
     316    arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName()); 
     317    arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" tests OpenGL and Windowing memory scalability.."); 
     318    arguments.getApplicationUsage()->addCommandLineOption("-h or --help","List command line options."); 
     319    arguments.getApplicationUsage()->addCommandLineOption("--pbuffer <width> <height>","Create a pixel buffer of specified dimensions."); 
     320    arguments.getApplicationUsage()->addCommandLineOption("--pbuffer","Create a 512x512 pixel buffer."); 
     321    arguments.getApplicationUsage()->addCommandLineOption("--window <width> <height>","Create a graphics window of specified dimensions."); 
     322    arguments.getApplicationUsage()->addCommandLineOption("--window","Create a 512x512 graphics window."); 
     323    arguments.getApplicationUsage()->addCommandLineOption("--delay <micoseconds>","Set a delay in microseconds before all OpenGL object operations."); 
     324    arguments.getApplicationUsage()->addCommandLineOption("--texture <width> <height> <depth>","Allocate a 3D texture of specified dimensions."); 
     325    arguments.getApplicationUsage()->addCommandLineOption("--texture <width> <height>","Allocate a 2D texture of specified dimensions."); 
     326    arguments.getApplicationUsage()->addCommandLineOption("--texture <width>","Allocate a 1D texture of specified dimensions."); 
     327    arguments.getApplicationUsage()->addCommandLineOption("--geometry <width> <height>","Allocate a osg::Geometry representing a grid of specified size, using OpenGL Dislay Lists."); 
     328    arguments.getApplicationUsage()->addCommandLineOption("--geometry-va <width> <height>","Allocate a osg::Geometry representing a grid of specified size, using Vertex Arrays."); 
     329    arguments.getApplicationUsage()->addCommandLineOption("--geometry-vbo <width> <height>","Allocate a osg::Geometry representing a grid of specified size, using Vertex Buffer Objects."); 
     330    arguments.getApplicationUsage()->addCommandLineOption("--fbo <width> <height>","Allocate a FrameBufferObject of specified dimensions."); 
     331    arguments.getApplicationUsage()->addCommandLineOption("-c <num>","Set the number of contexts to create of each type specified."); 
     332    arguments.getApplicationUsage()->addCommandLineOption("-g <num>","Set the number of GL objects to create of each type specified."); 
     333 
     334    if (arguments.read("-h") || arguments.read("--help")) 
     335    { 
     336        arguments.getApplicationUsage()->write(std::cout, osg::ApplicationUsage::COMMAND_LINE_OPTION); 
     337        return 1; 
     338    } 
     339     
     340    // report any errors if they have occurred when parsing the program arguments. 
     341    if (arguments.errors()) 
     342    { 
     343        arguments.writeErrorMessages(std::cout); 
     344        return 1; 
     345    } 
     346     
     347    if (arguments.argc()<=1) 
     348    { 
     349        arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION); 
     350        return 1; 
     351    } 
     352 
     353 
     354    typedef std::list< osg::ref_ptr<GLMemoryTest> > GLMemoryTests; 
     355    typedef std::list< osg::ref_ptr<ContextTest> > ContextTests; 
     356 
     357    ContextTests contextTests; 
     358    GLMemoryTests glMemoryTests; 
    317359     
    318360    int width, height, depth; 
    319     while(arguments.read("--pbuffer",width,height)) { tests.push_back(new ContextTest(width, height, true)); } 
    320     while(arguments.read("--pbuffer")) { tests.push_back(new ContextTest(512, 512, true)); } 
    321  
    322     while(arguments.read("--window",width,height)) { tests.push_back(new ContextTest(width, height, false)); } 
    323     while(arguments.read("--window")) { tests.push_back(new ContextTest(512,512, false)); } 
    324  
    325     while(arguments.read("--texture",width,height,depth)) { tests.push_back(new TextureTest(width,height,depth)); } 
    326     while(arguments.read("--texture",width,height)) { tests.push_back(new TextureTest(width,height,1)); } 
    327     while(arguments.read("--texture",width)) { tests.push_back(new TextureTest(width,1,1)); } 
    328  
    329     while(arguments.read("--fbo",width,height,depth)) { tests.push_back(new FboTest(width,height,depth)); } 
    330     while(arguments.read("--fbo",width,height)) { tests.push_back(new FboTest(width,height,2)); } 
    331     while(arguments.read("--fbo")) { tests.push_back(new FboTest(1024,1024,2)); } 
    332  
    333     while(arguments.read("--geometry",width,height)) { tests.push_back(new GeometryTest(GeometryTest::DISPLAY_LIST,width,height)); } 
    334     while(arguments.read("--geometry")) { tests.push_back(new GeometryTest(GeometryTest::DISPLAY_LIST,64,64)); } 
    335  
    336     while(arguments.read("--geometry-vbo",width,height)) { tests.push_back(new GeometryTest(GeometryTest::VERTEX_BUFFER_OBJECT,width,height)); } 
    337     while(arguments.read("--geometry-vbo")) { tests.push_back(new GeometryTest(GeometryTest::VERTEX_BUFFER_OBJECT,64,64)); } 
    338  
    339     while(arguments.read("--geometry-va",width,height)) { tests.push_back(new GeometryTest(GeometryTest::VERTEX_ARRAY,width,height)); } 
    340     while(arguments.read("--geometry-va")) { tests.push_back(new GeometryTest(GeometryTest::VERTEX_ARRAY,64,64)); } 
     361    while(arguments.read("--pbuffer",width,height)) { contextTests.push_back(new ContextTest(width, height, true)); } 
     362    while(arguments.read("--pbuffer")) { contextTests.push_back(new ContextTest(512, 512, true)); } 
     363 
     364    while(arguments.read("--window",width,height)) { contextTests.push_back(new ContextTest(width, height, false)); } 
     365    while(arguments.read("--window")) { contextTests.push_back(new ContextTest(512,512, false)); } 
     366 
     367    while(arguments.read("--texture",width,height,depth)) { glMemoryTests.push_back(new TextureTest(width,height,depth)); } 
     368    while(arguments.read("--texture",width,height)) { glMemoryTests.push_back(new TextureTest(width,height,1)); } 
     369    while(arguments.read("--texture",width)) { glMemoryTests.push_back(new TextureTest(width,1,1)); } 
     370 
     371    while(arguments.read("--fbo",width,height,depth)) { glMemoryTests.push_back(new FboTest(width,height,depth)); } 
     372    while(arguments.read("--fbo",width,height)) { glMemoryTests.push_back(new FboTest(width,height,2)); } 
     373    while(arguments.read("--fbo")) { glMemoryTests.push_back(new FboTest(1024,1024,2)); } 
     374 
     375    while(arguments.read("--geometry",width,height)) { glMemoryTests.push_back(new GeometryTest(GeometryTest::DISPLAY_LIST,width,height)); } 
     376    while(arguments.read("--geometry")) { glMemoryTests.push_back(new GeometryTest(GeometryTest::DISPLAY_LIST,64,64)); } 
     377 
     378    while(arguments.read("--geometry-vbo",width,height)) { glMemoryTests.push_back(new GeometryTest(GeometryTest::VERTEX_BUFFER_OBJECT,width,height)); } 
     379    while(arguments.read("--geometry-vbo")) { glMemoryTests.push_back(new GeometryTest(GeometryTest::VERTEX_BUFFER_OBJECT,64,64)); } 
     380 
     381    while(arguments.read("--geometry-va",width,height)) { glMemoryTests.push_back(new GeometryTest(GeometryTest::VERTEX_ARRAY,width,height)); } 
     382    while(arguments.read("--geometry-va")) { glMemoryTests.push_back(new GeometryTest(GeometryTest::VERTEX_ARRAY,64,64)); } 
    341383 
    342384    unsigned int sleepTime = 0; 
     
    349391    while(arguments.read("-g",maxNumGLIterations)) {} 
    350392 
    351     typedef std::list< osg::ref_ptr<GLMemoryTest> > GLMemoryTests; 
    352     typedef std::list< osg::ref_ptr<ContextTest> > ContextTests; 
    353  
    354      
    355     ContextTests contextTests; 
    356     GLMemoryTests glMemoryTests; 
    357      
    358     for(Tests::iterator itr = tests.begin(); 
    359         itr != tests.end(); 
    360         ++itr) 
    361     { 
    362         MemoryTest* test = itr->get(); 
    363         if (dynamic_cast<GLMemoryTest*>(test)!=0) 
    364         { 
    365             glMemoryTests.push_back(dynamic_cast<GLMemoryTest*>(test)); 
    366         } 
    367         else if (dynamic_cast<ContextTest*>(test)!=0) 
    368         { 
    369             contextTests.push_back(dynamic_cast<ContextTest*>(test)); 
    370         } 
    371     } 
    372  
     393 
     394    // any option left unread are converted into errors to write out later. 
     395    arguments.reportRemainingOptionsAsUnrecognized(); 
     396 
     397    // report any errors if they have occurred when parsing the program arguments. 
     398    if (arguments.errors()) 
     399    { 
     400        arguments.writeErrorMessages(std::cout); 
     401        return 1; 
     402    } 
     403     
    373404    typedef std::list< osg::ref_ptr<osg::GraphicsContext> > Contexts; 
    374405    typedef std::list< osg::ref_ptr<GLObject> > GLObjects;