2005-08-16 21:29:07 +08:00
|
|
|
// C++ source file - (C) 2003 Robert Osfield, released under the OSGPL.
|
|
|
|
//
|
|
|
|
// Simple example of use of Producer::RenderSurface to create an OpenGL
|
|
|
|
// graphics window, and OSG for rendering.
|
|
|
|
|
|
|
|
#include <osg/Timer>
|
|
|
|
#include <osg/GraphicsContext>
|
2005-08-20 16:59:03 +08:00
|
|
|
#include <osg/GraphicsThread>
|
2005-08-18 00:13:06 +08:00
|
|
|
|
|
|
|
#include <osgUtil/UpdateVisitor>
|
|
|
|
#include <osgUtil/CullVisitor>
|
2005-08-20 16:59:03 +08:00
|
|
|
#include <osgUtil/SceneView>
|
2005-08-31 06:28:30 +08:00
|
|
|
#include <osgUtil/GLObjectsVisitor>
|
2005-08-18 00:13:06 +08:00
|
|
|
|
2005-08-16 21:29:07 +08:00
|
|
|
#include <osgDB/ReadFile>
|
2005-09-01 04:39:05 +08:00
|
|
|
#include <osgDB/DynamicLibrary>
|
|
|
|
#include <osgDB/Registry>
|
2005-08-18 00:13:06 +08:00
|
|
|
|
2005-08-20 16:59:03 +08:00
|
|
|
#include <map>
|
|
|
|
#include <list>
|
2005-08-16 21:29:07 +08:00
|
|
|
#include <iostream>
|
|
|
|
|
2005-08-18 16:37:01 +08:00
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// **************** THIS IS AN EXPERIMENTAL IMPLEMENTATION ***************
|
|
|
|
// ************************** PLEASE DO NOT COPY ************************
|
|
|
|
//
|
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
2005-08-31 17:21:34 +08:00
|
|
|
// Compile operation, that compile OpenGL objects.
|
2005-08-31 06:28:30 +08:00
|
|
|
struct CompileOperation : public osg::GraphicsThread::Operation
|
|
|
|
{
|
|
|
|
CompileOperation(osg::Node* scene):
|
|
|
|
osg::GraphicsThread::Operation("Compile",false),
|
|
|
|
_scene(scene)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void operator () (osg::GraphicsContext* context)
|
|
|
|
{
|
|
|
|
std::cout<<"Compile"<<std::endl;
|
|
|
|
|
|
|
|
osgUtil::GLObjectsVisitor compileVisitor;
|
|
|
|
compileVisitor.setState(context->getState());
|
|
|
|
|
|
|
|
// do the compile traversal
|
|
|
|
_scene->accept(compileVisitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Node> _scene;
|
|
|
|
};
|
|
|
|
|
2005-08-31 18:55:58 +08:00
|
|
|
// Cull operation, that does a cull on the scene graph.
|
|
|
|
struct CullOperation : public osg::GraphicsThread::Operation
|
2005-08-20 16:59:03 +08:00
|
|
|
{
|
2005-10-28 21:11:56 +08:00
|
|
|
CullOperation(osgUtil::SceneView* sceneView):
|
2005-08-31 18:55:58 +08:00
|
|
|
osg::GraphicsThread::Operation("Cull",true),
|
|
|
|
_sceneView(sceneView)
|
2005-08-20 16:59:03 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void operator () (osg::GraphicsContext* context)
|
|
|
|
{
|
|
|
|
_sceneView->setState(context->getState());
|
|
|
|
_sceneView->cull();
|
|
|
|
}
|
|
|
|
|
2005-08-31 18:55:58 +08:00
|
|
|
osg::ref_ptr<osgUtil::SceneView> _sceneView;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Draw operation, that does a draw on the scene graph.
|
|
|
|
struct DrawOperation : public osg::GraphicsThread::Operation
|
|
|
|
{
|
|
|
|
DrawOperation(osgUtil::SceneView* sceneView):
|
|
|
|
osg::GraphicsThread::Operation("Draw",true),
|
|
|
|
_sceneView(sceneView)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void operator () (osg::GraphicsContext*)
|
|
|
|
{
|
|
|
|
_sceneView->draw();
|
|
|
|
}
|
|
|
|
|
2005-08-20 16:59:03 +08:00
|
|
|
osg::ref_ptr<osgUtil::SceneView> _sceneView;
|
|
|
|
};
|
2005-08-18 00:13:06 +08:00
|
|
|
|
2005-11-10 23:25:06 +08:00
|
|
|
struct CleanUpOperation : public osg::GraphicsThread::Operation
|
|
|
|
{
|
|
|
|
CleanUpOperation(osgUtil::SceneView* sceneView):
|
|
|
|
osg::GraphicsThread::Operation("CleanUp",false),
|
|
|
|
_sceneView(sceneView)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void operator () (osg::GraphicsContext*)
|
|
|
|
{
|
|
|
|
_sceneView->releaseAllGLObjects();
|
|
|
|
_sceneView->flushAllDeletedGLObjects();
|
|
|
|
}
|
|
|
|
|
|
|
|
osg::ref_ptr<osgUtil::SceneView> _sceneView;
|
|
|
|
};
|
2005-08-31 17:21:34 +08:00
|
|
|
|
|
|
|
// main does the following steps to create a multi-thread, multiple camera/graphics context view of a scene graph.
|
|
|
|
//
|
|
|
|
// 1) load the scene graph
|
|
|
|
//
|
|
|
|
// 2) create a list of camera, each with their own graphis context, with a graphics thread for each context.
|
|
|
|
//
|
|
|
|
// 3) set up the graphic threads so that the do an initial compile OpenGL objects operation, this is done once, and then this compile op is disgarded
|
|
|
|
//
|
|
|
|
// 4) set up the graphics thread so that it has all the graphics ops required for the main loop, these ops are:
|
|
|
|
// 4.a) frame begin barrair, syncronizes all the waiting graphic threads so they don't run while update is occuring
|
|
|
|
// 4.b) frame operation - the cull and draw for each camera
|
|
|
|
// 4.c) frame end barrier, releases the update thread once all graphic threads have dispatched all their OpenGL commands
|
|
|
|
// 4.d) pre swap barrier, barrier which ensures that all graphics threads have sent their data down to the gfx card.
|
|
|
|
// 4.e) swap buffers, do the swap buffers on all the graphics contexts.
|
|
|
|
//
|
|
|
|
// 5. The main loop:
|
|
|
|
// 5.a) update
|
|
|
|
// 5.b) join the frame begin barrrier, releasing all the graphics threads to do their stuff
|
|
|
|
// 5.c) block on the frame end barrier, waiting till all the graphics threads have done their cull/draws.
|
|
|
|
// 5.d) check to see if any of the windows has been closed.
|
|
|
|
//
|
2005-08-18 00:13:06 +08:00
|
|
|
int main( int argc, char **argv )
|
|
|
|
{
|
2005-12-07 17:48:28 +08:00
|
|
|
osg::Referenced::setThreadSafeReferenceCounting(true);
|
|
|
|
|
2005-09-03 04:06:11 +08:00
|
|
|
// use an ArgumentParser object to manage the program arguments.
|
|
|
|
osg::ArgumentParser arguments(&argc,argv);
|
2005-09-01 04:39:05 +08:00
|
|
|
|
2005-09-03 04:06:11 +08:00
|
|
|
std::string windowingLibrary("osgProducer");
|
|
|
|
while (arguments.read("--windowing",windowingLibrary)) {}
|
|
|
|
|
|
|
|
// load the osgProducer library manually.
|
|
|
|
osg::ref_ptr<osgDB::DynamicLibrary> windowingLib =
|
2005-11-18 04:22:55 +08:00
|
|
|
osgDB::DynamicLibrary::loadLibrary(osgDB::Registry::instance()->createLibraryNameForNodeKit(windowingLibrary));
|
2005-09-03 04:06:11 +08:00
|
|
|
|
|
|
|
|
|
|
|
if (!windowingLib)
|
2005-08-18 00:13:06 +08:00
|
|
|
{
|
2005-09-03 04:06:11 +08:00
|
|
|
std::cout<<"Error: failed to loading windowing library: "<<windowingLibrary<<std::endl;
|
2005-08-18 00:13:06 +08:00
|
|
|
}
|
|
|
|
|
2005-09-03 04:06:11 +08:00
|
|
|
unsigned int numberCameras = 3;
|
|
|
|
while (arguments.read("--cameras",numberCameras)) {}
|
2005-09-01 04:39:05 +08:00
|
|
|
|
2005-09-03 04:06:11 +08:00
|
|
|
unsigned int xpos = 0;
|
|
|
|
unsigned int ypos = 400;
|
|
|
|
unsigned int width = 400;
|
|
|
|
unsigned int height = 400;
|
|
|
|
|
|
|
|
while (arguments.read("--xpos",xpos)) {}
|
|
|
|
while (arguments.read("--ypos",ypos)) {}
|
|
|
|
while (arguments.read("--height",height)) {}
|
|
|
|
while (arguments.read("--width",width)) {}
|
|
|
|
|
|
|
|
unsigned int maxNumFrames = 1000;
|
|
|
|
while (arguments.read("--max-num-frames",maxNumFrames)) {}
|
2005-09-01 04:39:05 +08:00
|
|
|
|
2005-08-18 00:13:06 +08:00
|
|
|
// load the scene.
|
2005-09-03 04:06:11 +08:00
|
|
|
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);
|
2005-08-18 00:13:06 +08:00
|
|
|
if (!loadedModel)
|
|
|
|
{
|
|
|
|
std::cout << argv[0] <<": No data loaded." << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-08-20 16:59:03 +08:00
|
|
|
// set up the frame stamp for current frame to record the current time and frame number so that animtion code can advance correctly
|
|
|
|
osg::ref_ptr<osg::FrameStamp> frameStamp = new osg::FrameStamp;
|
|
|
|
|
2005-08-18 00:13:06 +08:00
|
|
|
unsigned int frameNum = 0;
|
|
|
|
|
2005-08-20 16:59:03 +08:00
|
|
|
osgUtil::UpdateVisitor updateVisitor;
|
|
|
|
updateVisitor.setFrameStamp(frameStamp.get());
|
|
|
|
|
2005-08-31 17:21:34 +08:00
|
|
|
typedef std::list< osg::ref_ptr<osg::CameraNode> > CameraList;
|
2005-08-20 16:59:03 +08:00
|
|
|
typedef std::set< osg::GraphicsContext* > GraphicsContextSet;
|
2005-08-18 00:13:06 +08:00
|
|
|
|
2005-08-31 17:21:34 +08:00
|
|
|
CameraList cameraList;
|
2005-08-20 16:59:03 +08:00
|
|
|
GraphicsContextSet graphicsContextSet;
|
2005-08-18 16:37:01 +08:00
|
|
|
|
2005-08-31 17:21:34 +08:00
|
|
|
// create the cameras, graphic contexts and graphic threads.
|
2005-08-31 06:28:30 +08:00
|
|
|
bool shareContexts = false;
|
|
|
|
osg::GraphicsContext* previousContext = 0;
|
2005-08-20 16:59:03 +08:00
|
|
|
for(unsigned int i=0; i< numberCameras; ++i)
|
|
|
|
{
|
|
|
|
osg::ref_ptr<osg::CameraNode> camera = new osg::CameraNode;
|
|
|
|
camera->addChild(loadedModel.get());
|
2005-08-18 16:37:01 +08:00
|
|
|
|
2005-08-20 16:59:03 +08:00
|
|
|
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
|
|
|
|
traits->_windowName = "osgcamera";
|
|
|
|
traits->_x = xpos;
|
|
|
|
traits->_y = ypos;
|
|
|
|
traits->_width = width;
|
|
|
|
traits->_height = height;
|
|
|
|
traits->_windowDecoration = true;
|
|
|
|
traits->_doubleBuffer = true;
|
2005-08-31 06:28:30 +08:00
|
|
|
traits->_sharedContext = shareContexts ? previousContext : 0;
|
|
|
|
|
2005-08-20 16:59:03 +08:00
|
|
|
xpos += width;
|
2005-08-18 16:37:01 +08:00
|
|
|
|
2005-08-20 16:59:03 +08:00
|
|
|
osg::ref_ptr<osg::GraphicsContext> gfxc = osg::GraphicsContext::createGraphicsContext(traits.get());
|
2005-08-18 00:13:06 +08:00
|
|
|
|
2005-08-20 16:59:03 +08:00
|
|
|
if (!gfxc)
|
|
|
|
{
|
|
|
|
std::cout<<"Unable to create window."<<std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
2005-08-18 16:37:01 +08:00
|
|
|
|
2005-08-20 16:59:03 +08:00
|
|
|
camera->setGraphicsContext(gfxc.get());
|
2005-08-18 16:37:01 +08:00
|
|
|
|
2005-08-20 16:59:03 +08:00
|
|
|
// initialize the view to look at the center of the scene graph
|
|
|
|
const osg::BoundingSphere& bs = loadedModel->getBound();
|
|
|
|
osg::Matrix viewMatrix;
|
|
|
|
viewMatrix.makeLookAt(bs.center()-osg::Vec3(0.0,2.0f*bs.radius(),0.0),bs.center(),osg::Vec3(0.0f,0.0f,1.0f));
|
2005-08-18 00:13:06 +08:00
|
|
|
|
2005-08-20 16:59:03 +08:00
|
|
|
camera->setViewport(0,0,traits->_width,traits->_height);
|
|
|
|
camera->setProjectionMatrixAsPerspective(50.0f,1.4f,1.0f,10000.0f);
|
|
|
|
camera->setViewMatrix(viewMatrix);
|
2005-08-18 00:13:06 +08:00
|
|
|
|
2005-08-30 22:41:08 +08:00
|
|
|
// graphics thread will realize the window.
|
2005-08-20 16:59:03 +08:00
|
|
|
gfxc->createGraphicsThread();
|
2005-08-18 00:13:06 +08:00
|
|
|
|
2005-08-31 17:21:34 +08:00
|
|
|
cameraList.push_back(camera);
|
2005-08-31 06:28:30 +08:00
|
|
|
|
|
|
|
previousContext = gfxc.get();
|
2005-08-16 21:29:07 +08:00
|
|
|
}
|
|
|
|
|
2005-08-20 16:59:03 +08:00
|
|
|
|
2005-08-31 17:21:34 +08:00
|
|
|
// build the list of unique graphics contexts.
|
|
|
|
CameraList::iterator citr;
|
|
|
|
for(citr = cameraList.begin();
|
|
|
|
citr != cameraList.end();
|
2005-08-20 16:59:03 +08:00
|
|
|
++citr)
|
2005-08-16 21:29:07 +08:00
|
|
|
{
|
2005-08-31 17:21:34 +08:00
|
|
|
graphicsContextSet.insert(const_cast<osg::GraphicsContext*>((*citr)->getGraphicsContext()));
|
2005-08-16 21:29:07 +08:00
|
|
|
}
|
|
|
|
|
2005-08-31 06:28:30 +08:00
|
|
|
|
2005-08-31 17:21:34 +08:00
|
|
|
std::cout<<"Number of cameras = "<<cameraList.size()<<std::endl;
|
|
|
|
std::cout<<"Number of graphics contexts = "<<graphicsContextSet.size()<<std::endl;
|
2005-08-20 16:59:03 +08:00
|
|
|
|
2005-08-16 21:29:07 +08:00
|
|
|
|
2005-08-31 06:28:30 +08:00
|
|
|
// first the compile of the GL Objects, do it syncronously.
|
|
|
|
GraphicsContextSet::iterator gitr;
|
2005-08-31 17:21:34 +08:00
|
|
|
osg::ref_ptr<CompileOperation> compileOp = new CompileOperation(loadedModel.get());
|
2005-08-31 06:28:30 +08:00
|
|
|
for(gitr = graphicsContextSet.begin();
|
|
|
|
gitr != graphicsContextSet.end();
|
|
|
|
++gitr)
|
|
|
|
{
|
|
|
|
osg::GraphicsContext* context = *gitr;
|
2005-08-31 18:55:58 +08:00
|
|
|
context->getGraphicsThread()->add(compileOp.get(), false);
|
2005-08-31 06:28:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// second the begin frame barrier to all graphics threads
|
2005-08-31 17:21:34 +08:00
|
|
|
osg::ref_ptr<osg::BarrierOperation> frameBeginBarrierOp = new osg::BarrierOperation(graphicsContextSet.size()+1, osg::BarrierOperation::NO_OPERATION);
|
2005-08-31 06:28:30 +08:00
|
|
|
for(gitr = graphicsContextSet.begin();
|
|
|
|
gitr != graphicsContextSet.end();
|
|
|
|
++gitr)
|
|
|
|
{
|
|
|
|
osg::GraphicsContext* context = *gitr;
|
|
|
|
context->getGraphicsThread()->add(frameBeginBarrierOp.get(), false);
|
|
|
|
}
|
|
|
|
|
2005-08-31 18:55:58 +08:00
|
|
|
osg::ref_ptr<osg::BarrierOperation> glFinishBarrierOp = new osg::BarrierOperation(graphicsContextSet.size(), osg::BarrierOperation::GL_FINISH);
|
|
|
|
|
|
|
|
// we can put a finish in to gate rendering throughput, so that each new frame starts with a clean sheet.
|
|
|
|
// you should only enable one of these, doFinishBeforeNewDraw will allow for the better parallism of the two finish approaches
|
2005-08-31 20:49:23 +08:00
|
|
|
// note, both are disabled right now, as glFinish is spin locking the CPU, not something that we want...
|
|
|
|
bool doFinishBeforeNewDraw = false;
|
2005-08-31 18:55:58 +08:00
|
|
|
bool doFinishAfterSwap = false;
|
|
|
|
|
2005-08-31 06:28:30 +08:00
|
|
|
// third add the frame for each camera.
|
2005-08-31 17:21:34 +08:00
|
|
|
for(citr = cameraList.begin();
|
|
|
|
citr != cameraList.end();
|
2005-08-31 06:28:30 +08:00
|
|
|
++citr)
|
|
|
|
{
|
2005-08-31 17:21:34 +08:00
|
|
|
osg::CameraNode* camera = citr->get();
|
2005-10-28 21:11:56 +08:00
|
|
|
osg::GraphicsThread* graphicsThread = camera->getGraphicsContext()->getGraphicsThread();
|
2005-08-31 18:55:58 +08:00
|
|
|
|
|
|
|
// create a scene view to do the cull and draw
|
|
|
|
osgUtil::SceneView* sceneView = new osgUtil::SceneView;
|
|
|
|
sceneView->setDefaults();
|
|
|
|
sceneView->setFrameStamp(frameStamp.get());
|
2005-10-28 21:11:56 +08:00
|
|
|
sceneView->setCamera(camera);
|
2005-08-31 18:55:58 +08:00
|
|
|
|
|
|
|
// cull traversal operation
|
2005-10-28 21:11:56 +08:00
|
|
|
graphicsThread->add( new CullOperation(sceneView), false);
|
2005-08-31 18:55:58 +08:00
|
|
|
|
|
|
|
// optionally add glFinish barrier to ensure that all OpenGL commands are completed before we start dispatching a new frame
|
2005-10-28 21:11:56 +08:00
|
|
|
if (doFinishBeforeNewDraw) graphicsThread->add( glFinishBarrierOp.get(), false);
|
2005-08-31 18:55:58 +08:00
|
|
|
|
|
|
|
// draw traversal operation.
|
2005-10-28 21:11:56 +08:00
|
|
|
graphicsThread->add( new DrawOperation(sceneView), false);
|
2005-08-31 06:28:30 +08:00
|
|
|
}
|
|
|
|
|
2005-08-31 17:21:34 +08:00
|
|
|
// fourth add the frame end barrier, the pre swap barrier and finally the swap buffers to each graphics thread.
|
|
|
|
// The frame end barrier tells the main thead that the draw dispatch/read phase of the scene graph is complete.
|
|
|
|
// The pre swap barrier is an optional extra, which does a flush before joining the barrier, using this all graphics threads
|
|
|
|
// are held back until they have all dispatched their fifo to the graphics hardware.
|
|
|
|
// The swapOp just issues a swap buffers for each of the graphics contexts.
|
|
|
|
osg::ref_ptr<osg::BarrierOperation> frameEndBarrierOp = new osg::BarrierOperation(graphicsContextSet.size()+1, osg::BarrierOperation::NO_OPERATION);
|
|
|
|
osg::ref_ptr<osg::BarrierOperation> preSwapBarrierOp = new osg::BarrierOperation(graphicsContextSet.size(), osg::BarrierOperation::GL_FLUSH);
|
|
|
|
osg::ref_ptr<osg::SwapBuffersOperation> swapOp = new osg::SwapBuffersOperation();
|
2005-08-31 06:28:30 +08:00
|
|
|
for(gitr = graphicsContextSet.begin();
|
|
|
|
gitr != graphicsContextSet.end();
|
|
|
|
++gitr)
|
|
|
|
{
|
|
|
|
osg::GraphicsContext* context = *gitr;
|
2005-08-31 18:55:58 +08:00
|
|
|
|
2005-08-31 06:28:30 +08:00
|
|
|
context->getGraphicsThread()->add(frameEndBarrierOp.get(), false);
|
2005-08-31 20:49:23 +08:00
|
|
|
// context->getGraphicsThread()->add(preSwapBarrierOp.get(), false);
|
2005-08-31 06:28:30 +08:00
|
|
|
context->getGraphicsThread()->add(swapOp.get(), false);
|
2005-08-31 18:55:58 +08:00
|
|
|
|
|
|
|
// optionally add finish barrier to ensure that we don't do any other graphics work till the current OpenGL commands are complete.
|
|
|
|
if (doFinishAfterSwap) context->getGraphicsThread()->add(glFinishBarrierOp.get(), false);
|
2005-08-31 06:28:30 +08:00
|
|
|
}
|
|
|
|
|
2005-08-31 17:21:34 +08:00
|
|
|
|
|
|
|
// record the timer tick at the start of rendering.
|
|
|
|
osg::Timer_t start_tick = osg::Timer::instance()->tick();
|
|
|
|
osg::Timer_t previous_tick = start_tick;
|
|
|
|
|
2005-09-01 04:39:05 +08:00
|
|
|
bool done = false;
|
2005-08-31 17:21:34 +08:00
|
|
|
|
2005-08-31 06:28:30 +08:00
|
|
|
// main loop - update scene graph, dispatch frame, wait for frame done.
|
2005-09-01 04:39:05 +08:00
|
|
|
while( !done && frameNum<maxNumFrames)
|
2005-08-16 21:29:07 +08:00
|
|
|
{
|
2005-08-20 16:59:03 +08:00
|
|
|
|
2005-08-30 22:41:08 +08:00
|
|
|
osg::Timer_t current_tick = osg::Timer::instance()->tick();
|
|
|
|
|
|
|
|
frameStamp->setReferenceTime(osg::Timer::instance()->delta_s(start_tick,current_tick));
|
2005-08-16 21:29:07 +08:00
|
|
|
frameStamp->setFrameNumber(frameNum++);
|
|
|
|
|
2005-08-31 20:49:23 +08:00
|
|
|
//std::cout<<"Frame rate "<<1.0/osg::Timer::instance()->delta_s(previous_tick,current_tick)<<std::endl;
|
2005-08-30 22:41:08 +08:00
|
|
|
previous_tick = current_tick;
|
2005-08-20 16:59:03 +08:00
|
|
|
|
|
|
|
|
2005-08-31 03:03:02 +08:00
|
|
|
// do the update traversal.
|
2005-08-20 16:59:03 +08:00
|
|
|
loadedModel->accept(updateVisitor);
|
|
|
|
|
2005-08-31 06:28:30 +08:00
|
|
|
// dispatch the frame.
|
|
|
|
frameBeginBarrierOp->block();
|
|
|
|
|
|
|
|
// wait till the frame is done.
|
2005-08-20 16:59:03 +08:00
|
|
|
frameEndBarrierOp->block();
|
|
|
|
|
|
|
|
// check if any of the windows are closed
|
|
|
|
for(gitr = graphicsContextSet.begin();
|
|
|
|
gitr != graphicsContextSet.end();
|
|
|
|
++gitr)
|
|
|
|
{
|
|
|
|
osg::GraphicsContext* context = *gitr;
|
|
|
|
if (!context->isRealized()) done = true;
|
|
|
|
}
|
2005-08-16 21:29:07 +08:00
|
|
|
|
|
|
|
}
|
2005-11-10 23:25:06 +08:00
|
|
|
|
2005-09-01 04:39:05 +08:00
|
|
|
|
|
|
|
std::cout<<"Exiting application"<<std::endl;
|
|
|
|
|
2005-11-10 23:25:06 +08:00
|
|
|
// start clean up.
|
|
|
|
for(gitr = graphicsContextSet.begin();
|
|
|
|
gitr != graphicsContextSet.end();
|
|
|
|
++gitr)
|
|
|
|
{
|
|
|
|
osg::GraphicsContext* context = *gitr;
|
|
|
|
osg::GraphicsThread* thread = context->getGraphicsThread();
|
|
|
|
if (thread)
|
|
|
|
{
|
|
|
|
thread->removeAllOperations();
|
|
|
|
thread->setDone(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cout<<"Removed all operations"<<std::endl;
|
|
|
|
|
2005-08-16 21:29:07 +08:00
|
|
|
return 0;
|
|
|
|
}
|