Changeset 12935

Show
Ignore:
Timestamp:
02/01/12 18:42:42 (2 years ago)
Author:
robert
Message:

From Colin McDonald?, "I have an application with multiple windows. They share GL objects
between the contexts, using the GraphicsContext::Traits sharedContext
and setting the same contextID.

When one of these shared contexts is closed, GraphicsContext::close
deletes all GLObjects for that contextID, regardless of the fact that
they are shared. This means that all of the other contexts sharing the
objects have to recompile them.

The attached tweak makes GraphicsContext::close a bit less brutal for
shared contexts. I have also changed a misleading diagnostic message.
"

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osg/GraphicsContext.cpp

    r12863 r12935  
    305305    OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_contextIDMapMutex); 
    306306     
     307    s_contextIDMap[contextID].incrementUsageCount(); 
     308 
    307309    OSG_INFO<<"GraphicsContext::incrementContextIDUsageCount("<<contextID<<") to "<<s_contextIDMap[contextID]._numContexts<<std::endl; 
    308  
    309     s_contextIDMap[contextID].incrementUsageCount(); 
    310310} 
    311311 
     
    539539        if (makeCurrent()) 
    540540        { 
    541          
    542             OSG_INFO<<"Doing delete of GL objects"<<std::endl; 
    543  
    544             osg::deleteAllGLObjects(_state->getContextID()); 
    545  
    546             OSG_INFO<<"Done delete of GL objects"<<std::endl; 
     541            if ( !sharedContextExists ) 
     542            { 
     543                OSG_INFO<<"Doing delete of GL objects"<<std::endl; 
     544 
     545                osg::deleteAllGLObjects(_state->getContextID()); 
     546 
     547                OSG_INFO<<"Done delete of GL objects"<<std::endl; 
     548            } 
     549            else 
     550            { 
     551                // If the GL objects are shared with other contexts then only flush those 
     552                // which have already been deleted 
     553 
     554                osg::flushAllDeletedGLObjects(_state->getContextID()); 
     555            } 
    547556 
    548557            _state->reset(); 
     
    562571    // the the flushDelete*() methods not being invoked, such as when using GraphicContextEmbedded where makeCurrent 
    563572    // does not work. 
    564     if (_state.valid()) 
     573    if ( !sharedContextExists && _state.valid()) 
    565574    { 
    566575        OSG_INFO<<"Doing discard of deleted OpenGL objects."<<std::endl;