Changeset 13041 for OpenSceneGraph/trunk/src/osg/GraphicsContext.cpp
- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
-
OpenSceneGraph/trunk/src/osg/GraphicsContext.cpp (modified) (35 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osg/GraphicsContext.cpp
r13038 r13041 41 41 // Use a static reference pointer to hold the window system interface. 42 42 // Wrap this within a function, in order to control the order in which 43 // the static pointer's constructor is executed. 43 // the static pointer's constructor is executed. 44 44 45 45 static ref_ptr<GraphicsContext::WindowingSystemInterface> &windowingSystemInterfaceRef() … … 73 73 // catch any undefined values. 74 74 if (traits) traits->setUndefinedScreenDetailsToDefaultScreen(); 75 75 76 76 return wsref->createGraphicsContext(traits); 77 77 } 78 78 else 79 return 0; 79 return 0; 80 80 } 81 81 … … 113 113 std::string::size_type colon = displayName.find_last_of(':'); 114 114 std::string::size_type point = displayName.find_last_of('.'); 115 116 if (point!=std::string::npos && 117 colon==std::string::npos && 115 116 if (point!=std::string::npos && 117 colon==std::string::npos && 118 118 point < colon) point = std::string::npos; 119 119 … … 126 126 hostName = displayName.substr(0,colon); 127 127 } 128 128 129 129 std::string::size_type startOfDisplayNum = (colon==std::string::npos) ? 0 : colon+1; 130 130 std::string::size_type endOfDisplayNum = (point==std::string::npos) ? displayName.size() : point; … … 148 148 } 149 149 150 #if 0 150 #if 0 151 151 OSG_NOTICE<<" hostName ["<<hostName<<"]"<<std::endl; 152 152 OSG_NOTICE<<" displayNum "<<displayNum<<std::endl; … … 209 209 } 210 210 } 211 211 212 212 glContextVersion = ds->getGLContextVersion(); 213 213 glContextFlags = ds->getGLContextFlags(); … … 238 238 239 239 unsigned int _numContexts; 240 240 241 241 void incrementUsageCount() { ++_numContexts; } 242 242 … … 250 250 { 251 251 OSG_INFO<<"resetting compileContext "<<_compileContext.get()<<" refCount "<<_compileContext->referenceCount()<<std::endl; 252 252 253 253 _compileContext = 0; 254 254 } 255 255 } 256 256 257 257 osg::ref_ptr<osg::GraphicsContext> _compileContext; 258 258 … … 268 268 { 269 269 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_contextIDMapMutex); 270 270 271 271 // first check to see if we can reuse contextID; 272 272 for(ContextIDMap::iterator itr = s_contextIDMap.begin(); … … 288 288 unsigned int contextID = s_contextIDMap.size(); 289 289 s_contextIDMap[contextID]._numContexts = 1; 290 290 291 291 OSG_INFO<<"GraphicsContext::createNewContextID() creating contextID="<<contextID<<std::endl; 292 292 OSG_INFO<<"Updating the MaxNumberOfGraphicsContexts to "<<contextID+1<<std::endl; 293 293 294 // update the the maximum number of graphics contexts, 294 // update the the maximum number of graphics contexts, 295 295 // to ensure that texture objects and display buffers are configured to the correct size. 296 296 osg::DisplaySettings::instance()->setMaxNumberOfGraphicsContexts( contextID + 1 ); 297 297 298 return contextID; 298 return contextID; 299 299 } 300 300 … … 316 316 { 317 317 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_contextIDMapMutex); 318 318 319 319 s_contextIDMap[contextID].incrementUsageCount(); 320 320 … … 334 334 { 335 335 OSG_NOTICE<<"Warning: decrementContextIDUsageCount("<<contextID<<") called on expired contextID."<<std::endl; 336 } 336 } 337 337 338 338 OSG_INFO<<"GraphicsContext::decrementContextIDUsageCount("<<contextID<<") to "<<s_contextIDMap[contextID]._numContexts<<std::endl; … … 388 388 389 389 OSG_INFO<<"GraphicsContext::getRegisteredGraphicsContexts "<<contextID<<" contexts.size()="<<contexts.size()<<std::endl; 390 390 391 391 return contexts; 392 392 } … … 396 396 OSG_NOTICE<<"GraphicsContext::createCompileContext."<<std::endl; 397 397 398 { 398 { 399 399 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_contextIDMapMutex); 400 400 if (s_contextIDMap[contextID]._compileContext.valid()) return s_contextIDMap[contextID]._compileContext.get(); 401 401 } 402 402 403 403 GraphicsContext::GraphicsContexts contexts = GraphicsContext::getRegisteredGraphicsContexts(contextID); 404 404 if (contexts.empty()) return 0; 405 405 406 406 GraphicsContext* src_gc = contexts.front(); 407 407 const osg::GraphicsContext::Traits* src_traits = src_gc->getTraits(); … … 423 423 osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits); 424 424 if (gc.valid() && gc->realize()) 425 { 425 { 426 426 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_contextIDMapMutex); 427 427 s_contextIDMap[contextID]._compileContext = gc; … … 433 433 return 0; 434 434 } 435 435 436 436 } 437 437 … … 510 510 } 511 511 else 512 { 512 { 513 513 return false; 514 514 } … … 521 521 // switch off the graphics thread... 522 522 setGraphicsThread(0); 523 524 523 524 525 525 bool sharedContextExists = false; 526 526 527 527 if (_state.valid()) 528 528 { … … 531 531 } 532 532 533 // release all the OpenGL objects in the scene graphs associated with this 533 // release all the OpenGL objects in the scene graphs associated with this 534 534 for(Cameras::iterator itr = _cameras.begin(); 535 535 itr != _cameras.end(); … … 576 576 } 577 577 } 578 578 579 579 if (callCloseImplementation) closeImplementation(); 580 580 581 581 582 // now discard any deleted deleted OpenGL objects that the are still hanging around - such as due to 582 // now discard any deleted deleted OpenGL objects that the are still hanging around - such as due to 583 583 // the the flushDelete*() methods not being invoked, such as when using GraphicContextEmbedded where makeCurrent 584 584 // does not work. … … 593 593 { 594 594 decrementContextIDUsageCount(_state->getContextID()); 595 595 596 596 _state = 0; 597 597 } … … 604 604 605 605 bool result = makeCurrentImplementation(); 606 606 607 607 if (result) 608 608 { 609 609 // initialize extension process, not only initializes on first 610 // call, will be a non-op on subsequent calls. 610 // call, will be a non-op on subsequent calls. 611 611 getState()->initializeExtensionProcs(); 612 612 } 613 613 614 614 return result; 615 615 } … … 624 624 625 625 // initialize extension process, not only initializes on first 626 // call, will be a non-op on subsequent calls. 626 // call, will be a non-op on subsequent calls. 627 627 getState()->initializeExtensionProcs(); 628 628 } 629 629 630 630 return result; 631 631 } … … 634 634 { 635 635 bool result = releaseContextImplementation(); 636 636 637 637 _threadOfLastMakeCurrent = (OpenThreads::Thread*)(-1); 638 638 639 639 return result; 640 640 } … … 647 647 clear(); 648 648 } 649 else if (_graphicsThread.valid() && 649 else if (_graphicsThread.valid() && 650 650 _threadOfLastMakeCurrent == _graphicsThread.get()) 651 651 { … … 670 670 void GraphicsContext::setGraphicsThread(GraphicsThread* gt) 671 671 { 672 if (_graphicsThread==gt) return; 673 674 if (_graphicsThread.valid()) 672 if (_graphicsThread==gt) return; 673 674 if (_graphicsThread.valid()) 675 675 { 676 676 // need to kill the thread in some way... … … 680 680 681 681 _graphicsThread = gt; 682 683 if (_graphicsThread.valid()) 682 683 if (_graphicsThread.valid()) 684 684 { 685 685 _graphicsThread->setParent(this); … … 723 723 { 724 724 OSG_INFO<<"Doing remove named operation"<<std::endl; 725 725 726 726 // acquire the lock on the operations queue to prevent anyone else for modifying it at the same time 727 727 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_operationsMutex); … … 769 769 std::copy(_cameras.begin(), _cameras.end(), std::back_inserter(camerasCopy)); 770 770 std::sort(camerasCopy.begin(), camerasCopy.end(), CameraRenderOrderSortOp()); 771 771 772 772 for(CameraVector::iterator itr = camerasCopy.begin(); 773 773 itr != camerasCopy.end(); … … 800 800 } 801 801 } 802 802 803 803 if (_currentOperation.valid()) 804 804 { … … 808 808 (*_currentOperation)(this); 809 809 810 { 810 { 811 811 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_operationsMutex); 812 812 _currentOperation = 0; … … 832 832 for(unsigned int i=0; i<camera->getNumChildren(); ++i) 833 833 { 834 nodes.insert(camera->getChild(i)); 835 } 836 834 nodes.insert(camera->getChild(i)); 835 } 836 837 837 for(Cameras::iterator citr = _cameras.begin(); 838 838 citr != _cameras.end(); … … 847 847 if (nitr != nodes.end()) nodes.erase(nitr); 848 848 } 849 } 850 } 851 849 } 850 } 851 852 852 // now release the GLobjects associated with these non shared nodes 853 853 for(NodeSet::iterator nitr = nodes.begin(); … … 874 874 875 875 if (!_traits) return; 876 876 877 877 double widthChangeRatio = double(width) / double(_traits->width); 878 878 double heigtChangeRatio = double(height) / double(_traits->height); 879 double aspectRatioChange = widthChangeRatio / heigtChangeRatio; 880 879 double aspectRatioChange = widthChangeRatio / heigtChangeRatio; 880 881 881 882 882 for(Cameras::iterator itr = _cameras.begin(); … … 885 885 { 886 886 Camera* camera = (*itr); 887 887 888 888 // resize doesn't affect Cameras set up with FBO's. 889 889 if (camera->getRenderTargetImplementation()==osg::Camera::FRAME_BUFFER_OBJECT) continue; 890 890 891 891 Viewport* viewport = camera->getViewport(); 892 892 if (viewport)
