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

@@ -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;