Changeset 10588 for OpenSceneGraph/trunk/src/osgViewer/Viewer.cpp
- Timestamp:
- 09/22/09 20:45:24 (4 years ago)
- Files:
-
- 1 modified
-
OpenSceneGraph/trunk/src/osgViewer/Viewer.cpp (modified) (48 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgViewer/Viewer.cpp
r10520 r10588 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 2 2 * 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 5 5 * (at your option) any later version. The full license is in LICENSE file 6 6 * included with this distribution, and on the openscenegraph.org website. 7 * 7 * 8 8 * This library is distributed in the hope that it will be useful, 9 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 11 * OpenSceneGraph Public License for more details. 12 12 */ … … 66 66 //arguments.getApplicationUsage()->addCommandLineOption("--collar",""); 67 67 //arguments.getApplicationUsage()->addCommandLineOption("--im",""); 68 68 69 69 std::string filename; 70 70 bool readConfig = false; … … 140 140 while (arguments.read("--wow-M",wow_M)) {} 141 141 while (arguments.read("--wow-C",wow_C)) {} 142 142 143 143 if (screenNum<0) screenNum = 0; 144 144 145 145 setUpViewForWoWVxDisplay( screenNum, wow_content, wow_factor, wow_offset, wow_Zd, wow_vz, wow_M, wow_C ); 146 146 } … … 175 175 if (screenNum>=0) setUpViewInWindow(x, y, width, height, screenNum); 176 176 else setUpViewInWindow(x,y,width,height); 177 177 178 178 } 179 179 else if (screenNum>=0) … … 195 195 _eventVisitor->setActionAdapter(this); 196 196 _eventVisitor->setFrameStamp(_frameStamp.get()); 197 197 198 198 _updateVisitor = new osgUtil::UpdateVisitor; 199 199 _updateVisitor->setFrameStamp(_frameStamp.get()); … … 214 214 215 215 stopThreading(); 216 216 217 217 if (_scene.valid() && _scene->getDatabasePager()) 218 218 { … … 231 231 (*citr)->close(); 232 232 } 233 233 234 234 //osg::notify(osg::NOTICE)<<"finish Viewer::~Viewer()"<<std::endl; 235 235 236 236 getAllThreads(threads); 237 237 … … 243 243 { 244 244 osgViewer::View::take(rhs); 245 245 246 246 #if 1 247 247 osgViewer::Viewer* rhs_viewer = dynamic_cast<osgViewer::Viewer*>(&rhs); … … 278 278 rhs_viewer->_currentContext = 0; 279 279 } 280 #endif 280 #endif 281 281 } 282 282 … … 284 284 { 285 285 osg::notify(osg::INFO)<<"Viewer::readConfiguration("<<filename<<")"<<std::endl; 286 286 287 287 osg::ref_ptr<osg::Object> object = osgDB::readObjectFile(filename); 288 if (!object) 288 if (!object) 289 289 { 290 290 //osg::notify(osg::NOTICE)<<"Error: Unable to load configuration file \""<<filename<<"\""<<std::endl; 291 291 return false; 292 292 } 293 293 294 294 CompositeViewer* compositeViewer = dynamic_cast<CompositeViewer*>(object.get()); 295 295 if (compositeViewer) … … 298 298 return false; 299 299 } 300 300 301 301 View* view = dynamic_cast<osgViewer::View*>(object.get()); 302 302 if (view) … … 307 307 } 308 308 else 309 { 309 { 310 310 osg::notify(osg::NOTICE)<<"Error: Config file \""<<filename<<"\" does not contain a valid Viewer configuration."<<std::endl; 311 311 return false; … … 327 327 if ((*citr)->isRealized()) ++numRealizedWindows; 328 328 } 329 329 330 330 return numRealizedWindows > 0; 331 331 } … … 420 420 { 421 421 //osg::notify(osg::INFO)<<"Viewer::realize()"<<std::endl; 422 422 423 423 setCameraWithFocus(0); 424 424 425 425 Contexts contexts; 426 426 getContexts(contexts); 427 427 428 428 if (contexts.empty()) 429 429 { 430 430 osg::notify(osg::INFO)<<"Viewer::realize() - No valid contexts found, setting up view across all screens."<<std::endl; 431 432 // no windows are already set up so set up a default view 433 431 432 // no windows are already set up so set up a default view 433 434 434 const char* ptr = 0; 435 435 if ((ptr = getenv("OSG_CONFIG_FILE")) != 0) … … 467 467 } 468 468 } 469 469 470 470 getContexts(contexts); 471 471 } … … 477 477 return; 478 478 } 479 479 480 unsigned int maxTexturePoolSize = osg::DisplaySettings::instance()->getMaxTexturePoolSize(); 481 if (_camera->getDisplaySettings()) maxTexturePoolSize = std::max(maxTexturePoolSize, _camera->getDisplaySettings()->getMaxTexturePoolSize()); 482 if (_displaySettings.valid()) maxTexturePoolSize = std::max(maxTexturePoolSize, _displaySettings->getMaxTexturePoolSize()); 483 484 unsigned int maxVBOPoolSize = osg::DisplaySettings::instance()->getMaxVBOPoolSize(); 485 if (_displaySettings.valid()) maxVBOPoolSize = std::max(maxVBOPoolSize, _displaySettings->getMaxVBOPoolSize()); 486 if (_camera->getDisplaySettings()) maxVBOPoolSize = std::max(maxVBOPoolSize, _camera->getDisplaySettings()->getMaxVBOPoolSize()); 487 488 unsigned int maxFBOPoolSize = osg::DisplaySettings::instance()->getMaxFBOPoolSize(); 489 if (_displaySettings.valid()) maxFBOPoolSize = std::max(maxFBOPoolSize, _displaySettings->getMaxFBOPoolSize()); 490 if (_camera->getDisplaySettings()) maxFBOPoolSize = std::max(maxFBOPoolSize, _camera->getDisplaySettings()->getMaxFBOPoolSize()); 491 480 492 for(Contexts::iterator citr = contexts.begin(); 481 493 citr != contexts.end(); … … 483 495 { 484 496 osg::GraphicsContext* gc = *citr; 497 498 // set the pool sizes, 0 the default will result in no GL object pools. 499 gc->getState()->setMaxTexturePoolSize(maxTexturePoolSize); 500 gc->getState()->setMaxVBOPoolSize(maxVBOPoolSize); 501 gc->getState()->setMaxFBOPoolSize(maxFBOPoolSize); 502 485 503 gc->realize(); 486 504 487 505 if (_realizeOperation.valid() && gc->valid()) 488 506 { 489 507 gc->makeCurrent(); 490 508 491 509 (*_realizeOperation)(gc); 492 510 493 511 gc->releaseContext(); 494 512 } … … 508 526 if (gw) 509 527 { 510 gw->grabFocusIfPointerInWindow(); 511 } 512 } 513 } 514 528 gw->grabFocusIfPointerInWindow(); 529 } 530 } 531 } 532 515 533 // initialize the global timer to be relative to the current time. 516 534 osg::Timer::instance()->setStartTick(); … … 520 538 521 539 setUpThreading(); 522 540 523 541 if (osg::DisplaySettings::instance()->getCompileContextsHint()) 524 542 { … … 535 553 gc->getGraphicsThread()->setProcessorAffinity(processNum % numProcessors); 536 554 gc->getGraphicsThread()->startThread(); 537 555 538 556 ++processNum; 539 557 } 540 558 } 541 559 } 542 560 543 561 } 544 562 … … 564 582 _frameStamp->setSimulationTime(simulationTime); 565 583 } 566 584 567 585 if (getViewerStats() && getViewerStats()->collectStats("frame_rate")) 568 586 { … … 591 609 592 610 // osg::notify(osg::NOTICE)<<"Viewer::frameEventTraversal()."<<std::endl; 593 611 594 612 // need to copy events from the GraphicsWindow's into local EventQueue; 595 613 osgGA::EventQueue::Events events; … … 598 616 getContexts(contexts); 599 617 600 osgGA::GUIEventAdapter* eventState = getEventQueue()->getCurrentEventState(); 618 osgGA::GUIEventAdapter* eventState = getEventQueue()->getCurrentEventState(); 601 619 osg::Matrix masterCameraVPW = getCamera()->getViewMatrix() * getCamera()->getProjectionMatrix(); 602 if (getCamera()->getViewport()) 620 if (getCamera()->getViewport()) 603 621 { 604 622 osg::Viewport* viewport = getCamera()->getViewport(); … … 620 638 { 621 639 gw->checkEvents(); 622 640 623 641 osgGA::EventQueue::Events gw_events; 624 642 gw->getEventQueue()->takeEvents(gw_events); 625 643 626 644 osgGA::EventQueue::Events::iterator itr; 627 645 for(itr = gw_events.begin(); … … 630 648 { 631 649 osgGA::GUIEventAdapter* event = itr->get(); 632 650 633 651 bool pointerEvent = false; 634 652 635 653 float x = event->getX(); 636 654 float y = event->getY(); 637 655 638 656 bool invert_y = event->getMouseYOrientation()==osgGA::GUIEventAdapter::Y_INCREASING_DOWNWARDS; 639 657 if (invert_y && gw->getTraits()) y = gw->getTraits()->height - y; 640 658 641 659 switch(event->getEventType()) 642 660 { … … 647 665 { 648 666 pointerEvent = true; 649 667 650 668 if (event->getEventType()!=osgGA::GUIEventAdapter::DRAG || !getCameraWithFocus()) 651 669 { … … 656 674 { 657 675 osg::Camera* camera = *citr; 658 if (camera->getView()==this && 676 if (camera->getView()==this && 659 677 camera->getAllowEventFocus() && 660 678 camera->getRenderTargetImplementation()==osg::Camera::FRAME_BUFFER) 661 679 { 662 680 osg::Viewport* viewport = camera ? camera->getViewport() : 0; 663 if (viewport && 681 if (viewport && 664 682 x >= viewport->x() && y >= viewport->y() && 665 683 x <= (viewport->x()+viewport->width()) && y <= (viewport->y()+viewport->height()) ) … … 671 689 } 672 690 } 673 691 674 692 break; 675 693 } … … 677 695 break; 678 696 } 679 697 680 698 if (pointerEvent) 681 699 { … … 691 709 692 710 x = new_coord.x(); 693 y = new_coord.y(); 711 y = new_coord.y(); 694 712 695 713 // osg::notify(osg::NOTICE)<<"pointer event new_coord.x()="<<new_coord.x()<<" new_coord.y()="<<new_coord.y()<<std::endl; … … 712 730 event->setMouseYOrientation(osgGA::GUIEventAdapter::Y_INCREASING_UPWARDS); 713 731 } 714 715 // pass along the new pointer events details to the eventState of the viewer 732 733 // pass along the new pointer events details to the eventState of the viewer 716 734 eventState->setX(x); 717 735 eventState->setY(y); … … 743 761 bool wasThreading = areThreadsRunning(); 744 762 if (wasThreading) stopThreading(); 745 763 746 764 gw->close(); 747 _currentContext = NULL; 748 765 _currentContext = NULL; 766 749 767 if (wasThreading) startThreading(); 750 768 751 769 break; 752 770 } … … 760 778 } 761 779 } 762 780 763 781 764 782 // osg::notify(osg::NOTICE)<<"mouseEventState Xmin = "<<eventState->getXmin()<<" Ymin="<<eventState->getYmin()<<" xMax="<<eventState->getXmax()<<" Ymax="<<eventState->getYmax()<<std::endl; … … 816 834 817 835 // osg::notify(osg::NOTICE)<<"Events "<<events.size()<<std::endl; 818 836 819 837 if ((_keyEventSetsDone!=0) || _quitEventSetsDone) 820 838 { … … 829 847 if (_keyEventSetsDone && event->getKey()==_keyEventSetsDone) _done = true; 830 848 break; 831 849 832 850 case(osgGA::GUIEventAdapter::QUIT_APPLICATION): 833 851 if (_quitEventSetsDone) _done = true; 834 852 break; 835 853 836 854 default: 837 855 break; … … 839 857 } 840 858 } 841 859 842 860 if (_done) return; 843 861 … … 889 907 (*hitr)->handleWithCheckAgainstIgnoreHandledEventsMask( *event, *this, 0, 0); 890 908 } 891 909 892 910 } 893 911 … … 902 920 } 903 921 } 904 922 905 923 if (getViewerStats() && getViewerStats()->collectStats("event")) 906 924 { … … 1004 1022 OperationThreads operationThreads; 1005 1023 getOperationThreads(operationThreads); 1006 1024 1007 1025 for(OperationThreads::iterator itr = operationThreads.begin(); 1008 1026 itr != operationThreads.end(); … … 1011 1029 threads.push_back(*itr); 1012 1030 } 1013 1031 1014 1032 1015 1033 if (_scene.valid()) … … 1034 1052 { 1035 1053 threads.clear(); 1036 1054 1037 1055 Contexts contexts; 1038 1056 getContexts(contexts); … … 1042 1060 { 1043 1061 osg::GraphicsContext* gc = *gcitr; 1044 if (gc->getGraphicsThread() && 1062 if (gc->getGraphicsThread() && 1045 1063 (!onlyActive || gc->getGraphicsThread()->isRunning()) ) 1046 1064 { … … 1048 1066 } 1049 1067 } 1050 1068 1051 1069 Cameras cameras; 1052 1070 getCameras(cameras); … … 1056 1074 { 1057 1075 osg::Camera* camera = *citr; 1058 if (camera->getCameraThread() && 1076 if (camera->getCameraThread() && 1059 1077 (!onlyActive || camera->getCameraThread()->isRunning()) ) 1060 1078 { … … 1062 1080 } 1063 1081 } 1064 1082 1065 1083 } 1066 1084 … … 1072 1090 contexts.clear(); 1073 1091 1074 if (_camera.valid() && 1075 _camera->getGraphicsContext() && 1092 if (_camera.valid() && 1093 _camera->getGraphicsContext() && 1076 1094 (_camera->getGraphicsContext()->valid() || !onlyValid)) 1077 1095 { … … 1079 1097 contexts.push_back(_camera->getGraphicsContext()); 1080 1098 } 1081 1099 1082 1100 for(unsigned int i=0; i<getNumSlaves(); ++i) 1083 1101 { … … 1098 1116 { 1099 1117 cameras.clear(); 1100 1101 if (_camera.valid() && 1118 1119 if (_camera.valid() && 1102 1120 (!onlyActive || (_camera->getGraphicsContext() && _camera->getGraphicsContext()->valid())) ) cameras.push_back(_camera.get()); 1103 1121
