Changed the return types of makeCurrent to bool, and added a bool GraphicsContext::releaseContext method

along with implementations in osgViewer.
This commit is contained in:
Robert Osfield
2007-01-08 19:29:59 +00:00
parent 4a5eda6522
commit 16d1c00a3d
18 changed files with 221 additions and 126 deletions

View File

@@ -70,13 +70,13 @@ void multipleWindowMultipleCameras(osgViewer::Viewer& viewer)
wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), width, height);
unsigned int numCameras = 4;
unsigned int numCameras = 6;
double aspectRatioScale = (double)numCameras;
double translate_x = double(numCameras)-1;
for(unsigned int i=0; i<numCameras;++i, translate_x -= 2.0)
{
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
traits->screenNum = i / 2;
traits->screenNum = i / 3;
traits->x = (i*width)/numCameras;
traits->y = 0;
traits->width = width/numCameras-1;

View File

@@ -219,15 +219,18 @@ class OSG_EXPORT GraphicsContext : public Referenced
/** Make this graphics context current.
* Implementated by first aquiring a lock of the GraphicsContext mutex, and then doing a call to makeCurrentImplementation(). */
void makeCurrent();
* Implementated by calling makeCurrentImplementation().
* Returns true on success. */
bool makeCurrent();
/** Make this graphics context current with specified read context.
* Implementated by first aquiring a lock of the GraphicsContext mutex, and then doing a call to makeContextCurrentImplementation(). */
void makeContextCurrent(GraphicsContext* readContext);
* Implementated by calling makeContextCurrentImplementation().
* Returns true on success. */
bool makeContextCurrent(GraphicsContext* readContext);
/** Release the graphics context by unlocking the GraphicsContext mutex.*/
void releaseContext();
/** Release the graphics context.
* Returns true on success. */
bool releaseContext();
/** Return true if the current thread has this OpenGL graphics context.*/
inline bool isCurrent() const { return _threadOfLastMakeCurrent == OpenThreads::Thread::CurrentThread(); }
@@ -264,11 +267,14 @@ class OSG_EXPORT GraphicsContext : public Referenced
/** Make this graphics context current implementation.
* Pure virtual - must be implemented by concrate implementations of GraphicsContext. */
virtual void makeCurrentImplementation() = 0;
virtual bool makeCurrentImplementation() = 0;
/** Make this graphics context current with specified read context implementation.
* Pure virtual - must be implemented by concrate implementations of GraphicsContext. */
virtual void makeContextCurrentImplementation(GraphicsContext* readContext) = 0;
virtual bool makeContextCurrentImplementation(GraphicsContext* readContext) = 0;
/** Release the graphics context implementation.*/
virtual bool releaseContextImplementation() = 0;
/** Pure virtual, Bind the graphics context to associated texture implementation.
* Pure virtual - must be implemented by concrate implementations of GraphicsContext. */
@@ -278,6 +284,8 @@ class OSG_EXPORT GraphicsContext : public Referenced
* Pure virtual - must be implemented by Concrate implementations of GraphicsContext. */
virtual void swapBuffersImplementation() = 0;
/** resized method should be called when the underlying window has been resized and the GraphicsWindow and associated Cameras must
be updated to keep in sync with the new size. */
void resized(int x, int y, int width, int height)
@@ -332,7 +340,6 @@ class OSG_EXPORT GraphicsContext : public Referenced
Vec4 _clearColor;
GLbitfield _clearMask;
OpenThreads::Mutex _mutex;
OpenThreads::Thread* _threadOfLastMakeCurrent;
typedef std::list< ref_ptr<GraphicsOperation> > OperationQueue;

View File

@@ -150,6 +150,20 @@ class OSGGA_EXPORT EventQueue : public osg::Referenced
void keyRelease(int key, double time);
/** Method for adapting close window events.*/
void closeWindow() { closeWindow(getTime()); }
/** Method for adapting close window event with specified event time.*/
void closeWindow(double time);
/** Method for adapting application quit events.*/
void quitApplication() { quitApplication(getTime()); }
/** Method for adapting application quit events with specified event time.*/
void quitApplication(double time);
/** Method for adapting frame events.*/
void frame(double time);

View File

@@ -53,7 +53,9 @@ public:
SCROLL,
PEN_PRESSURE,
PEN_PROXIMITY_ENTER,
PEN_PROXIMITY_LEAVE
PEN_PROXIMITY_LEAVE,
CLOSE_WINDOW,
QUIT_APPLICATION
};
enum KeySymbol

View File

@@ -56,10 +56,13 @@ class OSGPRODUCER_EXPORT GraphicsContextImplementation : public osg::GraphicsCon
virtual void closeImplementation();
/** Make this graphics context current.*/
virtual void makeCurrentImplementation();
virtual bool makeCurrentImplementation();
/** Make this graphics context current with specified read context.*/
virtual void makeContextCurrentImplementation(osg::GraphicsContext* readContext);
virtual bool makeContextCurrentImplementation(osg::GraphicsContext* readContext);
/** Release the graphics context.*/
virtual bool releaseContextImplementation();
/** Bind the graphics context to associated texture.*/
virtual void bindPBufferToTextureImplementation(GLenum buffer);

View File

@@ -74,15 +74,18 @@ class OSGVIEWER_EXPORT GraphicsWindow : public osg::GraphicsContext, public osgG
/** Make this graphics context current implementation.
* Pure virtual - must be implemented by concrate implementations of GraphicsContext. */
virtual void makeCurrentImplementation() { osg::notify(osg::NOTICE)<<"GraphicsWindow::makeCurrentImplementation() not implemented."<<std::endl; }
virtual bool makeCurrentImplementation() { osg::notify(osg::NOTICE)<<"GraphicsWindow::makeCurrentImplementation() not implemented."<<std::endl; return false;}
/** Make this graphics context current with specified read context implementation.
* Pure virtual - must be implemented by concrate implementations of GraphicsContext. */
virtual void makeContextCurrentImplementation(GraphicsContext* /*readContext*/) { osg::notify(osg::NOTICE)<<"GraphicsWindow::makeContextCurrentImplementation(..) not implemented."<<std::endl; }
virtual bool makeContextCurrentImplementation(GraphicsContext* /*readContext*/) { osg::notify(osg::NOTICE)<<"GraphicsWindow::makeContextCurrentImplementation(..) not implemented."<<std::endl; return false;}
/** Release the graphics context.*/
virtual bool releaseContextImplementation() { osg::notify(osg::NOTICE)<<"GraphicsWindow::releaseContextImplementation(..) not implemented."<<std::endl; return false; }
/** Pure virtual, Bind the graphics context to associated texture implementation.
* Pure virtual - must be implemented by concrate implementations of GraphicsContext. */
virtual void bindPBufferToTextureImplementation(GLenum /*buffer*/) { osg::notify(osg::NOTICE)<<"GraphicsWindow::void bindPBufferToTextureImplementation(..) not implemented."<<std::endl; }
virtual void bindPBufferToTextureImplementation(GLenum /*buffer*/) { osg::notify(osg::NOTICE)<<"GraphicsWindow::bindPBufferToTextureImplementation(..) not implemented."<<std::endl; }
/** Swap the front and back buffers implementation.
* Pure virtual - must be implemented by Concrate implementations of GraphicsContext. */

View File

@@ -56,7 +56,10 @@ class GraphicsWindowCocoa : public osgViewer::GraphicsWindow
virtual void closeImplementation();
/** Make this graphics context current.*/
virtual void makeCurrentImplementation();
virtual bool makeCurrentImplementation();
/** Release the graphics context.*/
virtual bool releaseContextImplementation();
/** Swap the front and back buffers.*/
virtual void swapBuffersImplementation();

View File

@@ -56,7 +56,10 @@ class GraphicsWindowWin32 : public osgViewer::GraphicsWindow
virtual void closeImplementation();
/** Make this graphics context current.*/
virtual void makeCurrentImplementation();
virtual bool makeCurrentImplementation();
/** Release the graphics context.*/
virtual bool releaseContextImplementation();
/** Swap the front and back buffers.*/
virtual void swapBuffersImplementation();

View File

@@ -70,7 +70,10 @@ class GraphicsWindowX11 : public osgViewer::GraphicsWindow
virtual void closeImplementation();
/** Make this graphics context current.*/
virtual void makeCurrentImplementation();
virtual bool makeCurrentImplementation();
/** Release the graphics context.*/
virtual bool releaseContextImplementation();
/** Swap the front and back buffers.*/
virtual void swapBuffersImplementation();

View File

@@ -171,49 +171,41 @@ bool GraphicsContext::realize()
void GraphicsContext::close(bool callCloseImplementation)
{
osg::notify(osg::NOTICE)<<"close("<<callCloseImplementation<<")"<<this<<std::endl;
osg::notify(osg::INFO)<<"close("<<callCloseImplementation<<")"<<this<<std::endl;
// switch off the graphics thread...
setGraphicsThread(0);
bool sharedContextExists = false;
if (_state.valid())
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_contextIDMapMutex);
if (s_contextIDMap[_state->getContextID()]>1) sharedContextExists = true;
}
// release all the OpenGL objects in the scene graphs associted with this
for(Cameras::iterator itr = _cameras.begin();
itr != _cameras.end();
++itr)
{
Camera* camera = (*itr);
if (camera)
{
osg::notify(osg::INFO)<<"Releasing GL objects for Camera="<<camera<<" _state="<<_state.get()<<std::endl;
camera->releaseGLObjects(_state.get());
}
}
if (callCloseImplementation && _state.valid() && isRealized())
{
osg::notify(osg::INFO)<<"Closing still viable window "<<sharedContextExists<<" _state->getContextID()="<<_state->getContextID()<<std::endl;
bool sharedContextExists = false;
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_contextIDMapMutex);
if (s_contextIDMap[_state->getContextID()]>1) sharedContextExists = true;
}
osg::notify(osg::NOTICE)<<"Closing still viable window "<<sharedContextExists<<" _state->getContextID()="<<_state->getContextID()<<std::endl;
#if 1
// release all the OpenGL objects in the scene graphs associted with this
for(Cameras::iterator itr = _cameras.begin();
itr != _cameras.end();
++itr)
{
Camera* camera = (*itr);
if (camera)
{
osg::notify(osg::NOTICE)<<"Releasing GL objects for Camera "<<camera<<std::endl;
#if 1
camera->releaseGLObjects(_state.get());
#else
camera->releaseGLObjects(0);
#endif
}
}
#endif
#if 1
osg::notify(osg::NOTICE)<<"Doing makeCurrent "<<std::endl;
makeCurrent();
osg::notify(osg::NOTICE)<<"Doing Flush"<<std::endl;
osg::notify(osg::INFO)<<"Doing Flush"<<std::endl;
// flush all the OpenGL object buffer for this context.
double availableTime = 100.0f;
@@ -229,8 +221,8 @@ void GraphicsContext::close(bool callCloseImplementation)
osg::Program::flushDeletedGlPrograms(_state->getContextID(),currentTime,availableTime);
osg::Shader::flushDeletedGlShaders(_state->getContextID(),currentTime,availableTime);
osg::notify(osg::NOTICE)<<"Done Flush "<<availableTime<<std::endl;
#endif
osg::notify(osg::INFO)<<"Done Flush "<<availableTime<<std::endl;
_state->reset();
releaseContext();
@@ -247,46 +239,37 @@ void GraphicsContext::close(bool callCloseImplementation)
}
void GraphicsContext::makeCurrent()
bool GraphicsContext::makeCurrent()
{
ReleaseContext_Block_MakeCurrentOperation* rcbmco = 0;
if (_graphicsThread.valid() &&
_threadOfLastMakeCurrent == _graphicsThread.get() &&
_threadOfLastMakeCurrent != OpenThreads::Thread::CurrentThread())
{
// create a relase contex, block and make current operation to stop the graphics thread while we use the graphics context for ourselves
rcbmco = new ReleaseContext_Block_MakeCurrentOperation;
_graphicsThread->add(rcbmco);
}
if (!isCurrent()) _mutex.lock();
makeCurrentImplementation();
bool result = makeCurrentImplementation();
_threadOfLastMakeCurrent = OpenThreads::Thread::CurrentThread();
if (rcbmco)
if (result)
{
// Let the "relase contex, block and make current operation" proceed, which will now move on to trying to aquire the graphics
// contex itself with a makeCurrent(), this will then block on the GraphicsContext mutex till releaseContext() releases it.
rcbmco->release();
_threadOfLastMakeCurrent = OpenThreads::Thread::CurrentThread();
}
return result;
}
void GraphicsContext::makeContextCurrent(GraphicsContext* readContext)
bool GraphicsContext::makeContextCurrent(GraphicsContext* readContext)
{
if (!isCurrent()) _mutex.lock();
bool result = makeContextCurrentImplementation(readContext);
makeContextCurrentImplementation(readContext);
_threadOfLastMakeCurrent = OpenThreads::Thread::CurrentThread();
if (result)
{
_threadOfLastMakeCurrent = OpenThreads::Thread::CurrentThread();
}
return result;
}
void GraphicsContext::releaseContext()
bool GraphicsContext::releaseContext()
{
_mutex.unlock();
_threadOfLastMakeCurrent = reinterpret_cast<OpenThreads::Thread*>(0xffff);
bool result = releaseContextImplementation();
_threadOfLastMakeCurrent = (OpenThreads::Thread*)(-1);
return result;
}
void GraphicsContext::swapBuffers()
@@ -306,7 +289,6 @@ void GraphicsContext::swapBuffers()
makeCurrent();
swapBuffersImplementation();
clear();
releaseContext();
}
}

View File

@@ -218,13 +218,14 @@ void TextureObjectManager::flushAllTextureObjects(unsigned int contextID)
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
Texture::TextureObjectList& tol = _textureObjectListMap[contextID];
osg::notify(osg::NOTICE)<<"Flushing texture objects num="<<tol.size()<<" contextID="<<contextID<<std::endl;
// osg::notify(osg::INFO)<<"Flushing texture objects num="<<tol.size()<<" contextID="<<contextID<<std::endl;
for(Texture::TextureObjectList::iterator itr=tol.begin();
itr!=tol.end();
++itr)
{
osg::notify(osg::NOTICE)<<" deleting texture object "<<(*itr)->_id<<std::endl;
// osg::notify(osg::NOTICE)<<" deleting texture object "<<(*itr)->_id<<std::endl;
glDeleteTextures( 1L, &((*itr)->_id));
}
tol.clear();
@@ -1304,8 +1305,8 @@ void Texture::resizeGLObjectBuffers(unsigned int maxSize)
void Texture::releaseGLObjects(State* state) const
{
if (state) osg::notify(osg::NOTICE)<<"Texture::releaseGLObjects contextID="<<state->getContextID()<<std::endl;
else osg::notify(osg::NOTICE)<<"Texture::releaseGLObjects no State "<<std::endl;
// if (state) osg::notify(osg::NOTICE)<<"Texture::releaseGLObjects contextID="<<state->getContextID()<<std::endl;
// else osg::notify(osg::NOTICE)<<"Texture::releaseGLObjects no State "<<std::endl;
if (!state) const_cast<Texture*>(this)->dirtyTextureObject();
else

View File

@@ -26,7 +26,7 @@ View::View()
View::~View()
{
osg::notify(osg::NOTICE)<<"Destructing osg::View"<<std::endl;
osg::notify(osg::INFO)<<"Destructing osg::View"<<std::endl;
if (_camera.valid())
{
@@ -44,7 +44,7 @@ View::~View()
cd._camera->setCullCallback(0);
}
osg::notify(osg::NOTICE)<<"Done destructing osg::View"<<std::endl;
osg::notify(osg::INFO)<<"Done destructing osg::View"<<std::endl;
}

View File

@@ -325,6 +325,25 @@ void EventQueue::keyRelease(int key, double time)
addEvent(event);
}
void EventQueue::closeWindow(double time)
{
GUIEventAdapter* event = new GUIEventAdapter(*_accumulateEventState);
event->setEventType(GUIEventAdapter::CLOSE_WINDOW);
event->setTime(time);
addEvent(event);
}
void EventQueue::quitApplication(double time)
{
GUIEventAdapter* event = new GUIEventAdapter(*_accumulateEventState);
event->setEventType(GUIEventAdapter::QUIT_APPLICATION);
event->setTime(time);
addEvent(event);
}
void EventQueue::frame(double time)
{
GUIEventAdapter* event = new GUIEventAdapter(*_accumulateEventState);

View File

@@ -218,18 +218,18 @@ bool GraphicsContextImplementation::realizeImplementation()
}
}
void GraphicsContextImplementation::makeCurrentImplementation()
bool GraphicsContextImplementation::makeCurrentImplementation()
{
if (!_rs)
{
osg::notify(osg::NOTICE)<<"Error: GraphicsContextImplementation::makeCurrentImplementation() no RenderSurface."<<std::endl;
return;
return false;
}
if (!isRealized())
{
osg::notify(osg::NOTICE)<<"Error: GraphicsContextImplementation::makeCurrentImplementation() not Realized."<<std::endl;
return;
return false;
}
// osg::notify(osg::INFO)<<"GraphicsContextImplementation::makeCurrentImplementation()"<<std::endl;
@@ -238,11 +238,13 @@ void GraphicsContextImplementation::makeCurrentImplementation()
// comment out right now, as Producer's setReadDrawable() is doing a call for us.
// _rs->makeCurrent();
return true;
}
void GraphicsContextImplementation::makeContextCurrentImplementation(osg::GraphicsContext* readContext)
bool GraphicsContextImplementation::makeContextCurrentImplementation(osg::GraphicsContext* readContext)
{
if (!_rs) return;
if (!_rs) return false;
GraphicsContextImplementation* readContextImplemention = dynamic_cast<GraphicsContextImplementation*>(readContext);
@@ -257,6 +259,8 @@ void GraphicsContextImplementation::makeContextCurrentImplementation(osg::Graphi
// comment out right now, as Producer's setReadDrawable() is doing a call for us.
// _rs->makeCurrent();
return true;
}
void GraphicsContextImplementation::closeImplementation()

View File

@@ -46,11 +46,14 @@ class GraphicsContextCocoa : public osg::GraphicsContext
/** Make this graphics context current implementation.
* Pure virtual - must be implemented by concrate implementations of GraphicsContext. */
virtual void makeCurrentImplementation() { osg::notify(osg::NOTICE)<<"GraphicsWindow::makeCurrentImplementation() not implemented."<<std::endl; }
virtual bool makeCurrentImplementation() { osg::notify(osg::NOTICE)<<"GraphicsWindow::makeCurrentImplementation() not implemented."<<std::endl; return false;}
/** Make this graphics context current with specified read context implementation.
* Pure virtual - must be implemented by concrate implementations of GraphicsContext. */
virtual void makeContextCurrentImplementation(GraphicsContext* /*readContext*/) { osg::notify(osg::NOTICE)<<"GraphicsWindow::makeContextCurrentImplementation(..) not implemented."<<std::endl; }
virtual bool makeContextCurrentImplementation(GraphicsContext* /*readContext*/) { osg::notify(osg::NOTICE)<<"GraphicsWindow::makeContextCurrentImplementation(..) not implemented."<<std::endl; return false; }
/** Release the graphics context.*/
virtual bool releaseContextImplementation() { osg::notify(osg::NOTICE)<<"GraphicsWindow::releaseContextImplementation(..) not implemented."<<std::endl; return false; }
/** Pure virtual, Bind the graphics context to associated texture implementation.
* Pure virtual - must be implemented by concrate implementations of GraphicsContext. */
@@ -84,9 +87,16 @@ bool GraphicsWindowCocoa::realizeImplementation()
return false;
}
void GraphicsWindowCocoa::makeCurrentImplementation()
bool GraphicsWindowCocoa::makeCurrentImplementation()
{
osg::notify(osg::NOTICE)<<"GraphicWindowCocoa::makeCurrentImplementation() Please implement me!"<<std::endl;
return false;
}
bool GraphicsWindowCocoa::releaseContextImplementation()
{
osg::notify(osg::NOTICE)<<"GraphicWindowCocoa::releaseContextImplementation() Please implement me!"<<std::endl;
return false;
}
void GraphicsWindowCocoa::closeImplementation()

View File

@@ -46,11 +46,14 @@ class GraphicsContextWin32 : public osg::GraphicsContext
/** Make this graphics context current implementation.
* Pure virtual - must be implemented by concrate implementations of GraphicsContext. */
virtual void makeCurrentImplementation() { osg::notify(osg::NOTICE)<<"GraphicsWindow::makeCurrentImplementation() not implemented."<<std::endl; }
virtual bool makeCurrentImplementation() { osg::notify(osg::NOTICE)<<"GraphicsWindow::makeCurrentImplementation() not implemented."<<std::endl; return false; }
/** Make this graphics context current with specified read context implementation.
* Pure virtual - must be implemented by concrate implementations of GraphicsContext. */
virtual void makeContextCurrentImplementation(GraphicsContext* /*readContext*/) { osg::notify(osg::NOTICE)<<"GraphicsWindow::makeContextCurrentImplementation(..) not implemented."<<std::endl; }
virtual bool makeContextCurrentImplementation(GraphicsContext* /*readContext*/) { osg::notify(osg::NOTICE)<<"GraphicsWindow::makeContextCurrentImplementation(..) not implemented."<<std::endl; return false;}
/** Release the graphics context.*/
virtual bool releaseContextImplementation() { osg::notify(osg::NOTICE)<<"GraphicsWindow::releaseContextImplementation(..) not implemented."<<std::endl; return false; }
/** Pure virtual, Bind the graphics context to associated texture implementation.
* Pure virtual - must be implemented by concrate implementations of GraphicsContext. */
@@ -84,9 +87,17 @@ bool GraphicsWindowWin32::realizeImplementation()
return false;
}
void GraphicsWindowWin32::makeCurrentImplementation()
bool GraphicsWindowWin32::makeCurrentImplementation()
{
osg::notify(osg::NOTICE)<<"GraphicWindowWin32::makeCurrentImplementation() Please implement me!"<<std::endl;
return false;
}
bool GraphicWindowWin32::releaseContextImplementation()
{
osg::notify(osg::NOTICE)<<"GraphicWindowWin32::releaseContextImplementation() Please implement me!"<<std::endl;
return false;
}
void GraphicsWindowWin32::closeImplementation()

View File

@@ -63,11 +63,14 @@ class GraphicsContextX11 : public osg::GraphicsContext
/** Make this graphics context current implementation.
* Pure virtual - must be implemented by concrate implementations of GraphicsContext. */
virtual void makeCurrentImplementation() { osg::notify(osg::NOTICE)<<"GraphicsWindow::makeCurrentImplementation() not implemented."<<std::endl; }
virtual bool makeCurrentImplementation() { osg::notify(osg::NOTICE)<<"GraphicsWindow::makeCurrentImplementation() not implemented."<<std::endl; return false;}
/** Make this graphics context current with specified read context implementation.
* Pure virtual - must be implemented by concrate implementations of GraphicsContext. */
virtual void makeContextCurrentImplementation(GraphicsContext* /*readContext*/) { osg::notify(osg::NOTICE)<<"GraphicsWindow::makeContextCurrentImplementation(..) not implemented."<<std::endl; }
virtual bool makeContextCurrentImplementation(GraphicsContext* /*readContext*/) { osg::notify(osg::NOTICE)<<"GraphicsWindow::makeContextCurrentImplementation(..) not implemented."<<std::endl; return false; }
/** Release the graphics context.*/
virtual bool releaseContextImplementation() { osg::notify(osg::NOTICE)<<"GraphicsWindow::releaseContextImplementation(..) not implemented."<<std::endl; return false; }
/** Pure virtual, Bind the graphics context to associated texture implementation.
* Pure virtual - must be implemented by concrate implementations of GraphicsContext. */
@@ -533,38 +536,33 @@ bool GraphicsWindowX11::realizeImplementation()
return true;
}
void GraphicsWindowX11::makeCurrentImplementation()
bool GraphicsWindowX11::makeCurrentImplementation()
{
if (!_realized)
{
osg::notify(osg::NOTICE)<<"Warning: GraphicsWindow not realized, cannot do makeCurrent."<<std::endl;
return;
return false;
}
// osg::notify(osg::NOTICE)<<"makeCurrentImplementation "<<this<<" "<<OpenThreads::Thread::CurrentThread()<<std::endl;
// osg::notify(osg::NOTICE)<<" glXMakeCurrent ("<<_display<<","<<_window<<","<<_glxContext<<std::endl;
if (glXMakeCurrent( _display, _window, _glxContext ))
return glXMakeCurrent( _display, _window, _glxContext )==True;
}
bool GraphicsWindowX11::releaseContextImplementation()
{
if (!_realized)
{
// osg::notify(osg::NOTICE)<<"makeCurrentImplementation sucessful"<<std::endl;
osg::notify(osg::NOTICE)<<"Warning: GraphicsWindow not realized, cannot do makeCurrent."<<std::endl;
return false;
}
else
{
osg::notify(osg::NOTICE)<<"makeCurrentImplementation failed"<<std::endl;
while(!glXMakeCurrent( _display, _window, _glxContext ))
{
OpenThreads::Thread::YieldCurrentThread();
osg::notify(osg::NOTICE)<<" makeCurrentImplementation failed again."<<std::endl;
}
// osg::notify(osg::NOTICE)<<" Succeeded at last."<<std::endl;
}
// osg::notify(osg::NOTICE)<<"makeCurrentImplementation "<<this<<" "<<OpenThreads::Thread::CurrentThread()<<std::endl;
// osg::notify(osg::NOTICE)<<" glXMakeCurrent ("<<_display<<","<<_window<<","<<_glxContext<<std::endl;
return glXMakeCurrent( _display, None, NULL )==True;
}
@@ -640,6 +638,7 @@ void GraphicsWindowX11::checkEvents()
{
osg::notify(osg::INFO)<<"DeleteWindow event recieved"<<std::endl;
destroyWindowRequested = true;
getEventQueue()->closeWindow(eventTime);
}
}
case Expose :
@@ -859,12 +858,13 @@ void GraphicsWindowX11::checkEvents()
resized(windowX, windowY, windowWidth, windowHeight);
getEventQueue()->windowResize(windowX, windowY, windowWidth, windowHeight, resizeTime);
}
#if 0
if (destroyWindowRequested)
{
close();
}
#endif
}
void GraphicsWindowX11::grabFocus()

View File

@@ -605,7 +605,8 @@ void Viewer::eventTraversal()
osgGA::EventQueue::Events gw_events;
gw->getEventQueue()->takeEvents(gw_events);
for(osgGA::EventQueue::Events::iterator itr = gw_events.begin();
osgGA::EventQueue::Events::iterator itr;
for(itr = gw_events.begin();
itr != gw_events.end();
++itr)
{
@@ -692,6 +693,32 @@ void Viewer::eventTraversal()
// osg::notify(osg::NOTICE)<<" mouse Xmin = "<<event->getXmin()<<" Ymin="<<event->getYmin()<<" xMax="<<event->getXmax()<<" Ymax="<<event->getYmax()<<std::endl;
}
for(itr = gw_events.begin();
itr != gw_events.end();
++itr)
{
osgGA::GUIEventAdapter* event = itr->get();
switch(event->getEventType())
{
case(osgGA::GUIEventAdapter::CLOSE_WINDOW):
{
stopThreading();
gw->close();
// setThreadingModel(ThreadPerCamera);
setThreadingModel(SingleThreaded);
startThreading();
break;
}
default:
break;
}
}
events.insert(events.end(), gw_events.begin(), gw_events.end());
}
@@ -792,6 +819,9 @@ void Viewer::eventTraversal()
{
case(osgGA::GUIEventAdapter::KEYUP):
if (event->getKey()==_keySetsDone) _done = true;
else if (event->getKey()=='s') { setThreadingModel(SingleThreaded); }
else if (event->getKey()=='c') { setThreadingModel(ThreadPerCamera); }
else if (event->getKey()=='w') { setThreadingModel(ThreadPerContext); }
break;
default:
break;