| | 8 | |
| | 9 | class ThreadingHandler : public osgGA::GUIEventHandler |
| | 10 | { |
| | 11 | public: |
| | 12 | |
| | 13 | ThreadingHandler() {} |
| | 14 | |
| | 15 | bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa) |
| | 16 | { |
| | 17 | osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>(&aa); |
| | 18 | if (!viewer) return false; |
| | 19 | |
| | 20 | switch(ea.getEventType()) |
| | 21 | { |
| | 22 | case(osgGA::GUIEventAdapter::KEYUP): |
| | 23 | { |
| | 24 | if (ea.getKey()=='m') |
| | 25 | { |
| | 26 | switch(viewer->getThreadingModel()) |
| | 27 | { |
| | 28 | case(osgViewer::Viewer::SingleThreaded): |
| | 29 | viewer->setThreadingModel(osgViewer::Viewer::ThreadPerContext); |
| | 30 | osg::notify(osg::NOTICE)<<"Threading model 'ThreadPerContext' selected."<<std::endl; |
| | 31 | break; |
| | 32 | case(osgViewer::Viewer::ThreadPerContext): |
| | 33 | viewer->setThreadingModel(osgViewer::Viewer::ThreadPerCamera); |
| | 34 | osg::notify(osg::NOTICE)<<"Threading model 'ThreadPerCamera' selected."<<std::endl; |
| | 35 | break; |
| | 36 | case(osgViewer::Viewer::ThreadPerCamera): |
| | 37 | viewer->setThreadingModel(osgViewer::Viewer::SingleThreaded); |
| | 38 | osg::notify(osg::NOTICE)<<"Threading model 'SingleTheaded' selected."<<std::endl; |
| | 39 | break; |
| | 40 | } |
| | 41 | return true; |
| | 42 | } |
| | 43 | if (ea.getKey()=='e') |
| | 44 | { |
| | 45 | switch(viewer->getEndBarrierPosition()) |
| | 46 | { |
| | 47 | case(osgViewer::Viewer::BeforeSwapBuffers): |
| | 48 | viewer->setEndBarrierPosition(osgViewer::Viewer::AfterSwapBuffers); |
| | 49 | osg::notify(osg::NOTICE)<<"Threading model 'AfterSwapBuffers' selected."<<std::endl; |
| | 50 | break; |
| | 51 | case(osgViewer::Viewer::AfterSwapBuffers): |
| | 52 | viewer->setEndBarrierPosition(osgViewer::Viewer::BeforeSwapBuffers); |
| | 53 | osg::notify(osg::NOTICE)<<"Threading model 'BeforeSwapBuffers' selected."<<std::endl; |
| | 54 | break; |
| | 55 | } |
| | 56 | return true; |
| | 57 | } |
| | 58 | } |
| | 59 | default: break; |
| | 60 | } |
| | 61 | |
| | 62 | return false; |
| | 63 | } |
| | 64 | |
| | 65 | bool _done; |
| | 66 | }; |
| | 67 | |
| | 68 | |
| | 69 | class ModelHandler : public osgGA::GUIEventHandler |
| | 70 | { |
| | 71 | public: |
| | 72 | |
| | 73 | ModelHandler(): |
| | 74 | _position(0) {} |
| | 75 | |
| | 76 | typedef std::vector<std::string> Filenames; |
| | 77 | Filenames _filenames; |
| | 78 | unsigned int _position; |
| | 79 | |
| | 80 | void add(const std::string& filename) { _filenames.push_back(filename); } |
| | 81 | |
| | 82 | bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa) |
| | 83 | { |
| | 84 | osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>(&aa); |
| | 85 | if (!viewer) return false; |
| | 86 | |
| | 87 | if (_filenames.empty()) return false; |
| | 88 | |
| | 89 | switch(ea.getEventType()) |
| | 90 | { |
| | 91 | case(osgGA::GUIEventAdapter::KEYUP): |
| | 92 | { |
| | 93 | if (ea.getKey()=='l') |
| | 94 | { |
| | 95 | osg::ref_ptr<osg::Node> model = osgDB::readNodeFile( _filenames[_position] ); |
| | 96 | ++_position; |
| | 97 | if (_position>=_filenames.size()) _position = 0; |
| | 98 | |
| | 99 | if (model.valid()) |
| | 100 | { |
| | 101 | viewer->setSceneData(model.get()); |
| | 102 | } |
| | 103 | |
| | 104 | return true; |
| | 105 | } |
| | 106 | } |
| | 107 | default: break; |
| | 108 | } |
| | 109 | |
| | 110 | return false; |
| | 111 | } |
| | 112 | |
| | 113 | bool _done; |
| | 114 | }; |
| | 115 | |