Show
Ignore:
Timestamp:
11/25/09 17:20:25 (5 years ago)
Author:
robert
Message:

Added support for repeating viewer construction

Files:
1 modified

Legend:

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

    r6941 r10830  
    1717*/ 
    1818 
    19 #if 1 
    20  
    2119#include <osgDB/ReadFile> 
    2220#include <osgDB/WriteFile> 
     
    187185    } 
    188186 
     187    unsigned int numRepeats = 2; 
     188    if (arguments.read("--repeat",numRepeats) || arguments.read("-r",numRepeats) || arguments.read("--repeat") || arguments.read("-r")) 
     189    { 
     190        bool sharedModel = arguments.read("--shared"); 
     191        osg::ref_ptr<osg::Node> model; 
     192        if (sharedModel) model = osgDB::readNodeFiles(arguments); 
     193 
     194        osgViewer::Viewer::ThreadingModel threadingModel = osgViewer::Viewer::AutomaticSelection; 
     195        while (arguments.read("-s")) { threadingModel = osgViewer::Viewer::SingleThreaded; } 
     196        while (arguments.read("-g")) { threadingModel = osgViewer::Viewer::CullDrawThreadPerContext; } 
     197        while (arguments.read("-d")) { threadingModel = osgViewer::Viewer::DrawThreadPerContext; } 
     198        while (arguments.read("-c")) { threadingModel = osgViewer::Viewer::CullThreadPerCameraDrawThreadPerContext; } 
     199 
     200        for(unsigned int i=0; i<numRepeats; ++i) 
     201        { 
     202            osg::notify(osg::NOTICE)<<"+++++++++++++ New viewer ++++++++++++"<<std::endl; 
     203 
     204            osgViewer::Viewer viewer; 
     205 
     206            viewer.setThreadingModel(threadingModel); 
     207 
     208            if (sharedModel) viewer.setSceneData(model.get()); 
     209            else viewer.setSceneData(osgDB::readNodeFiles(arguments)); 
     210 
     211            viewer.run(); 
     212 
     213            osg::notify(osg::NOTICE)<<"------------ Viewer ended ----------"<<std::endl<<std::endl; 
     214        } 
     215        return 0; 
     216    } 
     217 
    189218 
    190219    std::string pathfile; 
     
    278307    return 0; 
    279308} 
    280 #else 
    281  
    282 #include <osgViewer/Viewer> 
    283 #include <osgDB/ReadFile> 
    284 #include <osgDB/WriteFile> 
    285  
    286 int main( int, char **) 
    287 { 
    288     osg::ref_ptr<osg::Node> model = osgDB::readNodeFile("cow.osg"); 
    289  
    290     for(unsigned int i=0; i<5; ++i) 
    291     { 
    292         osg::notify(osg::NOTICE)<<"New frame *******************************"<<std::endl; 
    293  
    294         osgViewer::Viewer viewer; 
    295         viewer.setSceneData(model.get()); 
    296         viewer.run(); 
    297         osg::notify(osg::NOTICE)<<std::endl<<std::endl; 
    298     } 
    299     return 0; 
    300 } 
    301  
    302 #endif