Changeset 9868

Show
Ignore:
Timestamp:
03/08/09 13:00:36 (4 years ago)
Author:
robert
Message:

Preliminary work on general purpose incremental compile support in osgViewer.

Location:
OpenSceneGraph/trunk
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/examples/osgterrain/osgterrain.cpp

    r9618 r9868  
    5858typedef std::vector< osg::ref_ptr<osg::GraphicsThread> > GraphicsThreads; 
    5959 
     60struct 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}; 
    6079 
    6180 
     
    6483public: 
    6584 
    66     LoadAndCompileOperation(const std::string& filename, GraphicsThreads& graphicsThreads, osg::RefBlockCount* block): 
     85    LoadAndCompileOperation(const std::string& filename, osgUtil::IncrementalCompileOperation* ico , osg::RefBlockCount* block): 
    6786        Operation("Load and compile Operation", false), 
    6887        _filename(filename), 
    69         _graphicsThreads(graphicsThreads), 
     88        _incrementalCompileOperation(ico), 
    7089        _block(block) {} 
    7190 
     
    7594 
    7695        _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        } 
    91110 
    92111        // osg::notify(osg::NOTICE)<<"done LoadAndCompileOperation "<<_filename<<std::endl; 
    93112    } 
    94113     
    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; 
    99118 
    100119}; 
     
    109128 
    110129 
    111     MasterOperation(const std::string& filename): 
     130    MasterOperation(const std::string& filename, osgUtil::IncrementalCompileOperation* ico): 
    112131        Operation("Master reading operation",true), 
    113         _filename(filename) 
     132        _filename(filename), 
     133        _incrementalCompileOperation(ico) 
    114134    { 
    115135    } 
     
    256276                if (gt) threads.push_back(gt); 
    257277            } 
    258  
    259             bool requiresBarrier = false; 
    260  
    261278 
    262279            if (_operationQueue.valid()) 
     
    277294                    // osg::notify(osg::NOTICE)<<"Adding LoadAndCompileOperation "<<*nitr<<std::endl; 
    278295 
    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() ); 
    280297                    loadAndCompileList.push_back(loadAndCompile); 
    281298                    _operationQueue->add( loadAndCompile.get() ); 
     
    301318                    { 
    302319                        nodesToAdd[(*litr)->_filename] = (*litr)->_loadedModel; 
    303                         requiresBarrier = true; 
    304320                    } 
    305321                } 
     
    309325            else 
    310326            { 
     327 
     328                _endOfLoadBlock = new osg::RefBlockCount(newFiles.size()); 
     329                 
     330                _endOfLoadBlock->reset(); 
     331 
    311332                for(Files::iterator nitr = newFiles.begin(); 
    312333                    nitr != newFiles.end(); 
     
    319340                        nodesToAdd[*nitr] = loadedModel; 
    320341 
    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()) 
    326343                        { 
    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(); 
    329354                        } 
    330355                    } 
    331                 } 
     356                    else 
     357                    { 
     358                        _endOfLoadBlock->completed(); 
     359                    } 
     360                } 
     361 
     362                _endOfLoadBlock->block(); 
     363 
    332364            } 
    333365                         
    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             } 
    353366        } 
    354367         
     
    455468    OpenThreads::Block                  _updatesMergedBlock; 
    456469 
     470    osg::ref_ptr<osgUtil::IncrementalCompileOperation>  _incrementalCompileOperation; 
    457471    osg::ref_ptr<osg::BarrierOperation> _endOfCompilebarrier; 
    458472    osg::ref_ptr<osg::RefBlockCount>    _endOfLoadBlock; 
     
    619633    viewer.addEventHandler(new osgViewer::RecordCameraPathHandler); 
    620634 
     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()); 
    621638 
    622639    double x = 0.0; 
     
    632649    while(arguments.read("-m",masterFilename)) 
    633650    { 
    634         masterOperation = new MasterOperation(masterFilename); 
     651        masterOperation = new MasterOperation(masterFilename, viewer.getIncrementalCompileOperation()); 
    635652    } 
    636653     
  • OpenSceneGraph/trunk/include/osgUtil/GLObjectsVisitor

    r9377 r9868  
    124124 
    125125        virtual void operator () (osg::GraphicsContext* context); 
    126  
     126         
    127127    protected: 
    128128     
     
    131131}; 
    132132 
     133class OSGUTIL_EXPORT IncrementalCompileOperation : public osg::GraphicsOperation 
     134{ 
     135    public: 
     136 
     137        IncrementalCompileOperation(); 
     138         
     139        typedef std::vector<osg::GraphicsContext*> Contexts; 
     140        void assignContexts(Contexts& contexts); 
     141        void removeContexts(Contexts& contexts); 
     142 
     143        void addGraphicsContext(osg::GraphicsContext* gc); 
     144        void removeGraphicsContext(osg::GraphicsContext* gc); 
     145 
     146 
     147        /** Merge subgraphs that have been compiled.*/ 
     148        void mergeCompiledSubgraphs(); 
     149 
     150        virtual void operator () (osg::GraphicsContext* context); 
     151         
     152 
     153 
     154        struct CompileData : public osg::Referenced 
     155        { 
     156            typedef std::list< osg::ref_ptr<osg::Texture> >  Textures; 
     157            typedef std::list< osg::ref_ptr<osg::Drawable> > Drawables; 
     158            typedef std::list< osg::ref_ptr<osg::Program> >  Programs; 
     159             
     160            bool empty() const { return _textures.empty() && _drawables.empty() && _programs.empty(); } 
     161             
     162            Textures    _textures; 
     163            Drawables   _drawables; 
     164            Programs    _programs; 
     165        }; 
     166 
     167        class CompileSet; 
     168        typedef std::set<osg::GraphicsContext*> ContextSet; 
     169        typedef std::map<osg::GraphicsContext*, osg::ref_ptr<CompileData> >  CompileMap; 
     170         
     171        struct CompileCompletedCallback : public osg::Referenced 
     172        { 
     173            virtual bool compileCompleted(CompileSet* compileSet) = 0; 
     174        }; 
     175 
     176        class CompileSet : public osg::Referenced 
     177        { 
     178        public: 
     179         
     180             
     181            CompileSet() {} 
     182             
     183            CompileSet(osg::Node*subgraphToCompile): 
     184                _subgraphToCompile(subgraphToCompile) {} 
     185 
     186            CompileSet(osg::Group* attachmentPoint, osg::Node*subgraphToCompile): 
     187                _attachmentPoint(attachmentPoint), 
     188                _subgraphToCompile(subgraphToCompile) {} 
     189         
     190            void buildCompileMap(ContextSet& context); 
     191 
     192            osg::ref_ptr<osg::Group>                _attachmentPoint; 
     193            osg::ref_ptr<osg::Node>                 _subgraphToCompile; 
     194            osg::ref_ptr<CompileCompletedCallback>  _compileCompletedCallback; 
     195            CompileMap                              _compileMap; 
     196             
     197        // protected: 
     198         
     199            virtual ~CompileSet() {} 
     200        }; 
     201         
     202        typedef std::list< osg::ref_ptr<CompileSet> >  CompileSets; 
     203 
     204 
     205        /** Add a subgraph to be compiled.*/ 
     206        void add(osg::Node* subgraphToCompile); 
     207 
     208        /** Add a subgraph to be compiled and add automatically to attachPoint on call to mergeCompiledSubgraphs.*/ 
     209        void add(osg::Group* attachmentPoint, osg::Node* subgraphToCompile); 
     210 
     211        /** Add a CompileSet to be compiled.*/ 
     212        void add(CompileSet* compileSet, bool callBuildCompileMap=true); 
     213 
     214 
     215        OpenThreads::Mutex& getToCompiledMutex() { return _toCompileMutex; } 
     216        CompileSets& getToCompile() { return _compiled; } 
     217         
     218        OpenThreads::Mutex& getCompiledMutex() { return _compiledMutex; } 
     219        CompileSets& getCompiled() { return _compiled; } 
     220 
     221    protected: 
     222 
     223        virtual ~IncrementalCompileOperation(); 
     224 
     225     
     226        OpenThreads::Mutex  _toCompileMutex; 
     227        CompileSets         _toCompile; 
     228         
     229        OpenThreads::Mutex  _compiledMutex; 
     230        CompileSets         _compiled; 
     231         
     232        ContextSet          _contexts; 
     233 
     234}; 
     235 
     236 
    133237} 
    134238 
  • OpenSceneGraph/trunk/include/osgViewer/ViewerBase

    r9554 r9868  
    1818 
    1919#include <osgUtil/UpdateVisitor> 
     20#include <osgUtil/GLObjectsVisitor> 
    2021 
    2122#include <osgGA/MatrixManipulator> 
     
    185186        /** Get the graphics operation to call on realization of the viewers graphics windows.*/ 
    186187        osg::Operation* getRealizeOperation() { return _realizeOperation.get(); } 
     188         
     189         
     190        /** Set the incremental compile operation. 
     191          * Used to manage the OpenGL object compilation and merging of subgraphs in a way that avoids overloading 
     192          * the rendering of frame with too many new objects in one frame. */ 
     193        void setIncrementalCompileOperation(osgUtil::IncrementalCompileOperation* ico); 
     194 
     195        /** Get the incremental compile operation. */ 
     196        osgUtil::IncrementalCompileOperation* getIncrementalCompileOperation() { return _incrementalCompileOperation.get(); } 
    187197 
    188198 
     
    261271        virtual void viewerInit() = 0; 
    262272 
    263         bool                                        _firstFrame; 
    264         bool                                        _done; 
    265         int                                         _keyEventSetsDone; 
    266         bool                                        _quitEventSetsDone; 
    267         bool                                        _releaseContextAtEndOfFrameHint; 
    268          
    269         ThreadingModel                              _threadingModel; 
    270         bool                                        _threadsRunning; 
    271  
    272         BarrierPosition                             _endBarrierPosition; 
    273  
    274         osg::ref_ptr<osg::BarrierOperation>         _startRenderingBarrier; 
    275         osg::ref_ptr<osg::BarrierOperation>         _endRenderingDispatchBarrier; 
    276         osg::ref_ptr<osg::EndOfDynamicDrawBlock>    _endDynamicDrawBlock; 
    277          
    278         osg::ref_ptr<osgGA::EventVisitor>           _eventVisitor; 
    279          
    280         osg::ref_ptr<osg::OperationQueue>           _updateOperations; 
    281         osg::ref_ptr<osgUtil::UpdateVisitor>        _updateVisitor; 
    282          
    283         osg::ref_ptr<osg::Operation>                _realizeOperation; 
    284  
    285         osg::observer_ptr<osg::GraphicsContext>     _currentContext; 
     273        bool                                                _firstFrame; 
     274        bool                                                _done; 
     275        int                                                 _keyEventSetsDone; 
     276        bool                                                _quitEventSetsDone; 
     277        bool                                                _releaseContextAtEndOfFrameHint; 
     278         
     279        ThreadingModel                                      _threadingModel; 
     280        bool                                                _threadsRunning; 
     281 
     282        BarrierPosition                                     _endBarrierPosition; 
     283 
     284        osg::ref_ptr<osg::BarrierOperation>                 _startRenderingBarrier; 
     285        osg::ref_ptr<osg::BarrierOperation>                 _endRenderingDispatchBarrier; 
     286        osg::ref_ptr<osg::EndOfDynamicDrawBlock>            _endDynamicDrawBlock; 
     287         
     288        osg::ref_ptr<osgGA::EventVisitor>                   _eventVisitor; 
     289         
     290        osg::ref_ptr<osg::OperationQueue>                   _updateOperations; 
     291        osg::ref_ptr<osgUtil::UpdateVisitor>                _updateVisitor; 
     292         
     293        osg::ref_ptr<osg::Operation>                        _realizeOperation; 
     294        osg::ref_ptr<osgUtil::IncrementalCompileOperation>  _incrementalCompileOperation; 
     295 
     296        osg::observer_ptr<osg::GraphicsContext>             _currentContext; 
    286297}; 
    287298 
  • OpenSceneGraph/trunk/src/osg/GraphicsContext.cpp

    r8872 r9868  
    318318GraphicsContext* GraphicsContext::getOrCreateCompileContext(unsigned int contextID) 
    319319{ 
    320     osg::notify(osg::INFO)<<"GraphicsContext::createCompileContext."<<std::endl; 
     320    osg::notify(osg::NOTICE)<<"GraphicsContext::createCompileContext."<<std::endl; 
    321321 
    322322    {     
     
    350350        OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_contextIDMapMutex); 
    351351        s_contextIDMap[contextID]._compileContext = gc; 
    352         osg::notify(osg::INFO)<<"   succeeded GraphicsContext::createCompileContext."<<std::endl; 
     352        osg::notify(osg::NOTICE)<<"   succeeded GraphicsContext::createCompileContext."<<std::endl; 
    353353        return gc.release(); 
    354354    } 
  • OpenSceneGraph/trunk/src/osgUtil/GLObjectsVisitor.cpp

    r8360 r9868  
    1414#include <osg/Drawable> 
    1515#include <osg/Notify> 
     16#include <OpenThreads/ScopedLock> 
    1617 
    1718using namespace osg; 
    1819using namespace osgUtil; 
    1920 
     21 
     22///////////////////////////////////////////////////////////////// 
     23// 
     24// GLObjectsVisitor 
     25// 
    2026GLObjectsVisitor::GLObjectsVisitor(Mode mode) 
    2127{ 
     
    146152} 
    147153 
     154///////////////////////////////////////////////////////////////// 
     155// 
     156// GLObjectsVisitor 
     157// 
     158 
    148159GLObjectsOperation::GLObjectsOperation(GLObjectsVisitor::Mode mode): 
    149160    osg::GraphicsOperation("GLObjectOperation",false), 
     
    183194    // osg::notify(osg::NOTICE)<<"GLObjectsOperation::after >>>>>>>>>>> "<<std::endl; 
    184195} 
     196 
     197///////////////////////////////////////////////////////////////// 
     198// 
     199// IncrementalCompileOperation 
     200// 
     201IncrementalCompileOperation::IncrementalCompileOperation(): 
     202    osg::GraphicsOperation("IncrementalCompileOperation",true) 
     203{ 
     204} 
     205 
     206IncrementalCompileOperation::~IncrementalCompileOperation() 
     207{ 
     208} 
     209 
     210void IncrementalCompileOperation::assignContexts(Contexts& contexts) 
     211{ 
     212    for(Contexts::iterator itr = contexts.begin(); 
     213        itr != contexts.end(); 
     214        ++itr) 
     215    { 
     216        osg::GraphicsContext* gc = *itr; 
     217        addGraphicsContext(gc); 
     218    } 
     219} 
     220 
     221void IncrementalCompileOperation::removeContexts(Contexts& contexts) 
     222{ 
     223    for(Contexts::iterator itr = contexts.begin(); 
     224        itr != contexts.end(); 
     225        ++itr) 
     226    { 
     227        osg::GraphicsContext* gc = *itr; 
     228        removeGraphicsContext(gc); 
     229    } 
     230} 
     231 
     232 
     233void IncrementalCompileOperation::addGraphicsContext(osg::GraphicsContext* gc) 
     234{ 
     235    if (_contexts.count(gc)==0) 
     236    { 
     237        gc->add(this); 
     238        _contexts.insert(gc); 
     239    } 
     240} 
     241 
     242void IncrementalCompileOperation::removeGraphicsContext(osg::GraphicsContext* gc) 
     243{ 
     244    if (_contexts.count(gc)!=0) 
     245    { 
     246        gc->remove(this); 
     247        _contexts.erase(gc); 
     248    } 
     249} 
     250 
     251void IncrementalCompileOperation::add(osg::Node* subgraphToCompile) 
     252{ 
     253    osg::notify(osg::NOTICE)<<"IncrementalCompileOperation::add("<<subgraphToCompile<<")"<<std::endl; 
     254    add(new CompileSet(subgraphToCompile)); 
     255} 
     256 
     257void IncrementalCompileOperation::add(osg::Group* attachmentPoint, osg::Node* subgraphToCompile) 
     258{ 
     259    osg::notify(osg::NOTICE)<<"IncrementalCompileOperation::add("<<attachmentPoint<<", "<<subgraphToCompile<<")"<<std::endl; 
     260    add(new CompileSet(attachmentPoint, subgraphToCompile)); 
     261} 
     262 
     263 
     264void IncrementalCompileOperation::add(CompileSet* compileSet, bool callBuildCompileMap) 
     265{ 
     266    if (!compileSet) return; 
     267     
     268    if (callBuildCompileMap) compileSet->buildCompileMap(_contexts); 
     269 
     270    osg::notify(osg::NOTICE)<<"IncrementalCompileOperation::add(CompileSet = "<<compileSet<<", "<<", "<<callBuildCompileMap<<")"<<std::endl; 
     271 
     272    OpenThreads::ScopedLock<OpenThreads::Mutex>  lock(_toCompileMutex); 
     273    _toCompile.push_back(compileSet); 
     274} 
     275 
     276void IncrementalCompileOperation::mergeCompiledSubgraphs() 
     277{ 
     278    osg::notify(osg::NOTICE)<<"IncrementalCompileOperation::mergeCompiledSubgraphs()"<<std::endl; 
     279 
     280    OpenThreads::ScopedLock<OpenThreads::Mutex>  compilded_lock(_compiledMutex); 
     281     
     282    for(CompileSets::iterator itr = _compiled.begin();  
     283        itr != _compiled.end(); 
     284        ++itr) 
     285    { 
     286        CompileSet* cs = itr->get(); 
     287        if (cs->_attachmentPoint.valid()) 
     288        { 
     289            cs->_attachmentPoint->addChild(cs->_subgraphToCompile.get()); 
     290        } 
     291    } 
     292     
     293    _compiled.clear(); 
     294} 
     295 
     296void IncrementalCompileOperation::CompileSet::buildCompileMap(ContextSet& context) 
     297{ 
     298} 
     299 
     300void IncrementalCompileOperation::operator () (osg::GraphicsContext* context) 
     301{ 
     302    osg::notify(osg::NOTICE)<<"IncrementalCompileOperation::operator () ("<<context<<")"<<std::endl; 
     303 
     304    OpenThreads::ScopedLock<OpenThreads::Mutex>  toCompile_lock(_toCompileMutex); 
     305    for(CompileSets::iterator itr = _toCompile.begin();  
     306        itr != _toCompile.end(); 
     307        ) 
     308    { 
     309        CompileSet* cs = itr->get(); 
     310        CompileMap& cm = cs->_compileMap; 
     311        CompileData* cd = cm[context].get(); 
     312         
     313        if (cd) 
     314        {         
     315            // compile textures 
     316            cd->_textures.clear(); 
     317 
     318            // compile drawables 
     319            cd->_drawables.clear(); 
     320 
     321            // compile programs 
     322            cd->_programs.clear(); 
     323        } 
     324                 
     325        if (!cd || cd->empty()) 
     326        { 
     327            if (cs->_compileCompletedCallback.valid()) 
     328            { 
     329                if (cs->_compileCompletedCallback->compileCompleted(cs)) 
     330                { 
     331                    // callback will handle merging of subgraph so no need to place CompileSet in merge. 
     332                } 
     333                else 
     334                { 
     335                    OpenThreads::ScopedLock<OpenThreads::Mutex>  compilded_lock(_compiledMutex); 
     336                    _compiled.push_back(cs); 
     337                } 
     338            } 
     339         
     340            // remove from toCompileSet; 
     341            itr = _toCompile.erase(itr); 
     342        } 
     343        else 
     344        { 
     345            ++itr; 
     346        } 
     347    } 
     348} 
  • OpenSceneGraph/trunk/src/osgViewer/CompositeViewer.cpp

    r9554 r9868  
    498498    } 
    499499     
     500    // attach contexts to _incrementalCompileOperation if attached. 
     501    if (_incrementalCompileOperation) _incrementalCompileOperation->assignContexts(contexts); 
     502 
     503 
    500504    bool grabFocus = true; 
    501505    if (grabFocus) 
     
    995999    } 
    9961000 
     1001    if (_incrementalCompileOperation.valid()) 
     1002    { 
     1003        // merge subgraphs that have been compiled by the incremental compiler operation. 
     1004        _incrementalCompileOperation->mergeCompiledSubgraphs(); 
     1005    } 
     1006 
    9971007    if (_updateOperations.valid()) 
    9981008    { 
  • OpenSceneGraph/trunk/src/osgViewer/Viewer.cpp

    r9554 r9868  
    449449        } 
    450450    } 
    451      
     451 
     452    // attach contexts to _incrementalCompileOperation if attached. 
     453    if (_incrementalCompileOperation) _incrementalCompileOperation->assignContexts(contexts); 
     454 
    452455    bool grabFocus = true; 
    453456    if (grabFocus) 
     
    899902        _updateOperations->runOperations(this); 
    900903    } 
     904     
     905    if (_incrementalCompileOperation.valid()) 
     906    { 
     907        // merge subgraphs that have been compiled by the incremental compiler operation. 
     908        _incrementalCompileOperation->mergeCompiledSubgraphs(); 
     909    } 
     910 
    901911 
    902912    { 
  • OpenSceneGraph/trunk/src/osgViewer/ViewerBase.cpp

    r9591 r9868  
    376376        if (!gc->isRealized()) 
    377377        { 
    378             osg::notify(osg::INFO)<<"ViewerBase::startThreading() : Realizng window "<<gc<<std::endl; 
     378            osg::notify(osg::INFO)<<"ViewerBase::startThreading() : Realizing window "<<gc<<std::endl; 
    379379            gc->realize(); 
    380380        } 
     
    550550        _updateOperations->remove(operation); 
    551551    }  
     552} 
     553 
     554void ViewerBase::setIncrementalCompileOperation(osgUtil::IncrementalCompileOperation* ico) 
     555{ 
     556    if (_incrementalCompileOperation == ico) return; 
     557     
     558    Contexts contexts; 
     559    getContexts(contexts, false); 
     560     
     561    if (_incrementalCompileOperation.valid()) _incrementalCompileOperation->removeContexts(contexts); 
     562 
     563    // assign new operation         
     564    _incrementalCompileOperation = ico; 
     565 
     566    if (_incrementalCompileOperation) _incrementalCompileOperation->assignContexts(contexts); 
    552567} 
    553568