Show
Ignore:
Timestamp:
06/09/07 21:18:24 (8 years ago)
Author:
robert
Message:

Added default file in case no file arguments are provided. Changed to use
standard ThreadingHandler? by default.

Files:
1 modified

Legend:

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

    r6275 r6926  
    44#include <osgDB/WriteFile> 
    55#include <osgViewer/Viewer> 
     6#include <osgViewer/ViewerEventHandlers> 
    67#include <osgGA/TrackballManipulator> 
    78#include <osgGA/FlightManipulator> 
    89#include <osgGA/AnimationPathManipulator> 
    910#include <iostream> 
    10  
    11 class ThreadingHandler : public osgGA::GUIEventHandler  
    12 { 
    13 public:  
    14  
    15     ThreadingHandler() {} 
    16          
    17     bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa) 
    18     { 
    19         osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>(&aa); 
    20         if (!viewer) return false; 
    21      
    22         switch(ea.getEventType()) 
    23         { 
    24             case(osgGA::GUIEventAdapter::KEYUP): 
    25             { 
    26                 if (ea.getKey()=='m') 
    27                 { 
    28                     switch(viewer->getThreadingModel()) 
    29                     { 
    30                         case(osgViewer::Viewer::SingleThreaded): 
    31                             viewer->setThreadingModel(osgViewer::Viewer::CullDrawThreadPerContext); 
    32                             osg::notify(osg::NOTICE)<<"Threading model 'CullDrawThreadPerContext' selected."<<std::endl; 
    33                             break; 
    34                         case(osgViewer::Viewer::CullDrawThreadPerContext): 
    35                             viewer->setThreadingModel(osgViewer::Viewer::DrawThreadPerContext); 
    36                             osg::notify(osg::NOTICE)<<"Threading model 'DrawThreadPerContext' selected."<<std::endl; 
    37                             break; 
    38                         case(osgViewer::Viewer::DrawThreadPerContext): 
    39                             viewer->setThreadingModel(osgViewer::Viewer::CullThreadPerCameraDrawThreadPerContext); 
    40                             osg::notify(osg::NOTICE)<<"Threading model 'CullThreadPerCameraDrawThreadPerContext' selected."<<std::endl; 
    41                             break; 
    42                         case(osgViewer::Viewer::CullThreadPerCameraDrawThreadPerContext): 
    43                             viewer->setThreadingModel(osgViewer::Viewer::SingleThreaded); 
    44                             osg::notify(osg::NOTICE)<<"Threading model 'SingleThreaded' selected."<<std::endl; 
    45                             break; 
    46                         case(osgViewer::Viewer::AutomaticSelection): 
    47                             viewer->setThreadingModel(viewer->suggestBestThreadingModel()); 
    48                             osg::notify(osg::NOTICE)<<"Threading model 'AutomaticSelection' selected."<<std::endl; 
    49                             break; 
    50                     } 
    51                     return true; 
    52                 } 
    53                 if (ea.getKey()=='e') 
    54                 { 
    55                     switch(viewer->getEndBarrierPosition()) 
    56                     { 
    57                         case(osgViewer::Viewer::BeforeSwapBuffers): 
    58                             viewer->setEndBarrierPosition(osgViewer::Viewer::AfterSwapBuffers); 
    59                             osg::notify(osg::NOTICE)<<"Threading model 'AfterSwapBuffers' selected."<<std::endl; 
    60                             break; 
    61                         case(osgViewer::Viewer::AfterSwapBuffers): 
    62                             viewer->setEndBarrierPosition(osgViewer::Viewer::BeforeSwapBuffers); 
    63                             osg::notify(osg::NOTICE)<<"Threading model 'BeforeSwapBuffers' selected."<<std::endl; 
    64                             break; 
    65                     } 
    66                     return true; 
    67                 } 
    68             } 
    69             default: break; 
    70         } 
    71          
    72         return false; 
    73     } 
    74      
    75     bool _done; 
    76 }; 
    77  
    7811 
    7912class ModelHandler : public osgGA::GUIEventHandler  
     
    176109} 
    177110 
    178 void multipleWindowMultipleCameras(osgViewer::Viewer& viewer) 
     111void multipleWindowMultipleCameras(osgViewer::Viewer& viewer, bool multipleScreens) 
    179112{ 
    180113    osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); 
     
    195128    { 
    196129        osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits; 
    197         traits->screenNum = i / 3; 
     130        traits->screenNum = multipleScreens ? i / 3 : 0; 
    198131        traits->x = (i*width)/numCameras; 
    199132        traits->y = 0; 
     
    248181    } 
    249182 
    250     osgViewer::Viewer viewer; 
     183    osgViewer::Viewer viewer(arguments); 
    251184     
    252185    while (arguments.read("-s")) { viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded); } 
     
    261194    // alternative viewer window setups. 
    262195    while (arguments.read("-1")) { singleWindowMultipleCameras(viewer); } 
    263     while (arguments.read("-2")) { multipleWindowMultipleCameras(viewer); } 
     196    while (arguments.read("-2")) { multipleWindowMultipleCameras(viewer, false); } 
     197    while (arguments.read("-3")) { multipleWindowMultipleCameras(viewer, true); } 
    264198 
    265199    if (apm.valid()) viewer.setCameraManipulator(apm.get()); 
    266200    else viewer.setCameraManipulator( new osgGA::TrackballManipulator() ); 
     201     
     202    viewer.addEventHandler(new osgViewer::StatsHandler); 
     203    viewer.addEventHandler(new osgViewer::ThreadingHandler); 
    267204 
    268205    std::string configfile; 
     
    300237    // load the scene. 
    301238    osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments); 
     239 
     240    if (!loadedModel) loadedModel = osgDB::readNodeFile("cow.osg"); 
     241 
    302242    if (!loadedModel)  
    303243    {