Changeset 4483 for OpenSceneGraph/trunk/examples/osgcamera/osgcamera.cpp
- Timestamp:
- 08/31/05 12:55:58 (8 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/examples/osgcamera/osgcamera.cpp
r4482 r4483 54 54 }; 55 55 56 // Frame operation, that does a cull and drawon the scene graph.57 struct FrameOperation : public osg::GraphicsThread::Operation56 // Cull operation, that does a cull on the scene graph. 57 struct CullOperation : public osg::GraphicsThread::Operation 58 58 { 59 FrameOperation(osg::CameraNode* camera, osg::FrameStamp* frameStamp):60 osg::GraphicsThread::Operation(" Frame",true),59 CullOperation(osg::CameraNode* camera, osgUtil::SceneView* sceneView): 60 osg::GraphicsThread::Operation("Cull",true), 61 61 _camera(camera), 62 _frameStamp(frameStamp) 63 { 64 _sceneView = new osgUtil::SceneView; 65 _sceneView->setDefaults(); 66 _sceneView->setFrameStamp(_frameStamp.get()); 67 68 if (camera->getNumChildren()>=1) 69 { 70 _sceneView->setSceneData(camera->getChild(0)); 71 } 62 _sceneView(sceneView) 63 { 72 64 } 73 65 … … 80 72 81 73 _sceneView->cull(); 74 } 75 76 osg::ref_ptr<osg::CameraNode> _camera; 77 osg::ref_ptr<osgUtil::SceneView> _sceneView; 78 }; 79 80 // Draw operation, that does a draw on the scene graph. 81 struct DrawOperation : public osg::GraphicsThread::Operation 82 { 83 DrawOperation(osgUtil::SceneView* sceneView): 84 osg::GraphicsThread::Operation("Draw",true), 85 _sceneView(sceneView) 86 { 87 } 88 89 virtual void operator () (osg::GraphicsContext*) 90 { 82 91 _sceneView->draw(); 83 92 } 84 93 85 osg::ref_ptr<osg::CameraNode> _camera;86 osg::ref_ptr<osg::FrameStamp> _frameStamp;87 94 osg::ref_ptr<osgUtil::SceneView> _sceneView; 88 95 }; … … 218 225 { 219 226 osg::GraphicsContext* context = *gitr; 220 context->getGraphicsThread()->add(compileOp.get(), true);227 context->getGraphicsThread()->add(compileOp.get(), false); 221 228 } 222 229 … … 232 239 } 233 240 241 osg::ref_ptr<osg::BarrierOperation> glFinishBarrierOp = new osg::BarrierOperation(graphicsContextSet.size(), osg::BarrierOperation::GL_FINISH); 242 243 // we can put a finish in to gate rendering throughput, so that each new frame starts with a clean sheet. 244 // you should only enable one of these, doFinishBeforeNewDraw will allow for the better parallism of the two finish approaches 245 bool doFinishBeforeNewDraw = true; 246 bool doFinishAfterSwap = false; 247 234 248 // third add the frame for each camera. 235 249 for(citr = cameraList.begin(); … … 238 252 { 239 253 osg::CameraNode* camera = citr->get(); 240 camera->getGraphicsContext()->getGraphicsThread()->add( new FrameOperation(camera, frameStamp.get()), false); 254 255 // create a scene view to do the cull and draw 256 osgUtil::SceneView* sceneView = new osgUtil::SceneView; 257 sceneView->setDefaults(); 258 sceneView->setFrameStamp(frameStamp.get()); 259 260 if (camera->getNumChildren()>=1) 261 { 262 sceneView->setSceneData(camera->getChild(0)); 263 } 264 265 // cull traversal operation 266 camera->getGraphicsContext()->getGraphicsThread()->add( new CullOperation(camera, sceneView), false); 267 268 // optionally add glFinish barrier to ensure that all OpenGL commands are completed before we start dispatching a new frame 269 if (doFinishBeforeNewDraw) camera->getGraphicsContext()->getGraphicsThread()->add( glFinishBarrierOp.get(), false); 270 271 // draw traversal operation. 272 camera->getGraphicsContext()->getGraphicsThread()->add( new DrawOperation(sceneView), false); 241 273 } 242 274 … … 246 278 // are held back until they have all dispatched their fifo to the graphics hardware. 247 279 // The swapOp just issues a swap buffers for each of the graphics contexts. 248 // The post swap barrier is an optional extra which does a glFinish after the swap buffers.249 280 osg::ref_ptr<osg::BarrierOperation> frameEndBarrierOp = new osg::BarrierOperation(graphicsContextSet.size()+1, osg::BarrierOperation::NO_OPERATION); 250 281 osg::ref_ptr<osg::BarrierOperation> preSwapBarrierOp = new osg::BarrierOperation(graphicsContextSet.size(), osg::BarrierOperation::GL_FLUSH); 251 282 osg::ref_ptr<osg::SwapBuffersOperation> swapOp = new osg::SwapBuffersOperation(); 252 osg::ref_ptr<osg::BarrierOperation> postSwapBarrierOp = new osg::BarrierOperation(graphicsContextSet.size(), osg::BarrierOperation::GL_FINISH);253 bool waitTillSwapBufferFinished = false;254 283 for(gitr = graphicsContextSet.begin(); 255 284 gitr != graphicsContextSet.end(); … … 257 286 { 258 287 osg::GraphicsContext* context = *gitr; 288 259 289 context->getGraphicsThread()->add(frameEndBarrierOp.get(), false); 260 290 context->getGraphicsThread()->add(preSwapBarrierOp.get(), false); 261 291 context->getGraphicsThread()->add(swapOp.get(), false); 262 if (waitTillSwapBufferFinished) context->getGraphicsThread()->add(postSwapBarrierOp.get(), false); 292 293 // optionally add finish barrier to ensure that we don't do any other graphics work till the current OpenGL commands are complete. 294 if (doFinishAfterSwap) context->getGraphicsThread()->add(glFinishBarrierOp.get(), false); 263 295 } 264 296
