Changeset 9868 for OpenSceneGraph/trunk/examples/osgterrain/osgterrain.cpp
- Timestamp:
- 03/08/09 13:00:36 (4 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/examples/osgterrain/osgterrain.cpp
r9618 r9868 58 58 typedef std::vector< osg::ref_ptr<osg::GraphicsThread> > GraphicsThreads; 59 59 60 struct ReleaseBlockOnCompileCompleted : public osgUtil::IncrementalCompileOperation::CompileCompletedCallback 61 { 62 63 ReleaseBlockOnCompileCompleted(osg::RefBlockCount* block): 64 _block(block) {} 65 66 virtual bool compileCompleted(osgUtil::IncrementalCompileOperation::CompileSet* compileSet) 67 { 68 if (_block.valid()) _block->completed(); 69 70 // tell IncrementalCompileOperation that it's now safe to remove the compileSet 71 72 osg::notify(osg::NOTICE)<<"compileCompleted("<<compileSet<<")"<<std::endl; 73 74 return true; 75 } 76 77 osg::ref_ptr<osg::RefBlockCount> _block; 78 }; 60 79 61 80 … … 64 83 public: 65 84 66 LoadAndCompileOperation(const std::string& filename, GraphicsThreads& graphicsThreads, osg::RefBlockCount* block):85 LoadAndCompileOperation(const std::string& filename, osgUtil::IncrementalCompileOperation* ico , osg::RefBlockCount* block): 67 86 Operation("Load and compile Operation", false), 68 87 _filename(filename), 69 _ graphicsThreads(graphicsThreads),88 _incrementalCompileOperation(ico), 70 89 _block(block) {} 71 90 … … 75 94 76 95 _loadedModel = osgDB::readNodeFile(_filename); 77 if (_loadedModel.valid() && !_graphicsThreads.empty())78 {79 osg::ref_ptr<osgUtil::GLObjectsOperation> compileOperation = new osgUtil::GLObjectsOperation(_loadedModel.get());80 81 for(GraphicsThreads::iterator gitr = _graphicsThreads.begin();82 gitr != _graphicsThreads.end();83 ++gitr)84 {85 (*gitr)->add( compileOperation.get());86 // requiresBarrier = true;87 }88 }89 90 if (_block.valid()) _block->completed();96 97 if (_loadedModel.valid() && _incrementalCompileOperation.valid()) 98 { 99 osg::ref_ptr<osgUtil::IncrementalCompileOperation::CompileSet> compileSet = 100 new osgUtil::IncrementalCompileOperation::CompileSet(_loadedModel); 101 102 compileSet->_compileCompletedCallback = new ReleaseBlockOnCompileCompleted(_block.get()); 103 104 _incrementalCompileOperation->add(compileSet.get()); 105 } 106 else 107 { 108 if (_block.valid()) _block->completed(); 109 } 91 110 92 111 // osg::notify(osg::NOTICE)<<"done LoadAndCompileOperation "<<_filename<<std::endl; 93 112 } 94 113 95 std::string _filename;96 GraphicsThreads _graphicsThreads;97 osg::ref_ptr<osg ::Node> _loadedModel;98 osg::ref_ptr<osg::RefBlockCount> _block;114 std::string _filename; 115 osg::ref_ptr<osg::Node> _loadedModel; 116 osg::ref_ptr<osgUtil::IncrementalCompileOperation> _incrementalCompileOperation; 117 osg::ref_ptr<osg::RefBlockCount> _block; 99 118 100 119 }; … … 109 128 110 129 111 MasterOperation(const std::string& filename ):130 MasterOperation(const std::string& filename, osgUtil::IncrementalCompileOperation* ico): 112 131 Operation("Master reading operation",true), 113 _filename(filename) 132 _filename(filename), 133 _incrementalCompileOperation(ico) 114 134 { 115 135 } … … 256 276 if (gt) threads.push_back(gt); 257 277 } 258 259 bool requiresBarrier = false;260 261 278 262 279 if (_operationQueue.valid()) … … 277 294 // osg::notify(osg::NOTICE)<<"Adding LoadAndCompileOperation "<<*nitr<<std::endl; 278 295 279 osg::ref_ptr<LoadAndCompileOperation> loadAndCompile = new LoadAndCompileOperation( *nitr, threads, _endOfLoadBlock.get() );296 osg::ref_ptr<LoadAndCompileOperation> loadAndCompile = new LoadAndCompileOperation( *nitr, _incrementalCompileOperation.get(), _endOfLoadBlock.get() ); 280 297 loadAndCompileList.push_back(loadAndCompile); 281 298 _operationQueue->add( loadAndCompile.get() ); … … 301 318 { 302 319 nodesToAdd[(*litr)->_filename] = (*litr)->_loadedModel; 303 requiresBarrier = true;304 320 } 305 321 } … … 309 325 else 310 326 { 327 328 _endOfLoadBlock = new osg::RefBlockCount(newFiles.size()); 329 330 _endOfLoadBlock->reset(); 331 311 332 for(Files::iterator nitr = newFiles.begin(); 312 333 nitr != newFiles.end(); … … 319 340 nodesToAdd[*nitr] = loadedModel; 320 341 321 osg::ref_ptr<osgUtil::GLObjectsOperation> compileOperation = new osgUtil::GLObjectsOperation(loadedModel.get()); 322 323 for(GraphicsThreads::iterator gitr = threads.begin(); 324 gitr != threads.end(); 325 ++gitr) 342 if (_incrementalCompileOperation.valid()) 326 343 { 327 (*gitr)->add( compileOperation.get() ); 328 requiresBarrier = true; 344 osg::ref_ptr<osgUtil::IncrementalCompileOperation::CompileSet> compileSet = 345 new osgUtil::IncrementalCompileOperation::CompileSet(loadedModel.get()); 346 347 compileSet->_compileCompletedCallback = new ReleaseBlockOnCompileCompleted(_endOfLoadBlock.get()); 348 349 _incrementalCompileOperation->add(compileSet.get()); 350 } 351 else 352 { 353 _endOfLoadBlock->completed(); 329 354 } 330 355 } 331 } 356 else 357 { 358 _endOfLoadBlock->completed(); 359 } 360 } 361 362 _endOfLoadBlock->block(); 363 332 364 } 333 365 334 if (requiresBarrier)335 {336 _endOfCompilebarrier = new osg::BarrierOperation(threads.size()+1);337 _endOfCompilebarrier->setKeep(false);338 339 for(GraphicsThreads::iterator gitr = threads.begin();340 gitr != threads.end();341 ++gitr)342 {343 (*gitr)->add(_endOfCompilebarrier.get());344 }345 346 // osg::notify(osg::NOTICE)<<"Waiting for Compile to complete"<<std::endl;347 348 // wait for the graphics threads to complete.349 _endOfCompilebarrier->block();350 351 // osg::notify(osg::NOTICE)<<"done ... Waiting for Compile to complete"<<std::endl;352 }353 366 } 354 367 … … 455 468 OpenThreads::Block _updatesMergedBlock; 456 469 470 osg::ref_ptr<osgUtil::IncrementalCompileOperation> _incrementalCompileOperation; 457 471 osg::ref_ptr<osg::BarrierOperation> _endOfCompilebarrier; 458 472 osg::ref_ptr<osg::RefBlockCount> _endOfLoadBlock; … … 619 633 viewer.addEventHandler(new osgViewer::RecordCameraPathHandler); 620 634 635 // attach an IncrementaCompileOperation to allow the master loading 636 // to be handled with an incremental compile to avoid frame drops when large objects are added. 637 viewer.setIncrementalCompileOperation(new osgUtil::IncrementalCompileOperation()); 621 638 622 639 double x = 0.0; … … 632 649 while(arguments.read("-m",masterFilename)) 633 650 { 634 masterOperation = new MasterOperation(masterFilename );651 masterOperation = new MasterOperation(masterFilename, viewer.getIncrementalCompileOperation()); 635 652 } 636 653
