Show
Ignore:
Timestamp:
10/02/07 23:23:58 (7 years ago)
Author:
robert
Message:

Merged the threading set up and rendering code from Viewer and CompositeViewer?
into ViewerBase? to allow CompositeViewer? to inherit the same theading models
previously just supported by osgViewer::Viewer

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/include/osgViewer/ViewerBase

    r7507 r7535  
    7272 
    7373        /** Set the threading model the rendering traversals will use.*/ 
    74         virtual void setThreadingModel(ThreadingModel threadingModel) = 0; 
     74        virtual void setThreadingModel(ThreadingModel threadingModel); 
    7575         
    7676        /** Get the threading model the rendering traversals will use.*/ 
    7777        ThreadingModel getThreadingModel() const { return _threadingModel; } 
    78          
     78 
     79        /** Let the viewer suggest the best threading model for the viewers camera/window setup and the hardware available.*/ 
     80        virtual ThreadingModel suggestBestThreadingModel(); 
     81 
     82        /** Set up the threading and processor affinity as per the viewers threading model.*/ 
     83        virtual void setUpThreading();       
     84 
     85        /** Return true if viewer threads are running. */ 
     86        bool areThreadsRunning() const { return _threadsRunning; } 
     87 
     88        /** Stop any threads begin run by viewer.*/ 
     89        virtual void stopThreading(); 
     90 
     91        /** Start any threads required by the viewer.*/ 
     92        virtual void startThreading();         
     93 
     94        enum BarrierPosition 
     95        { 
     96            BeforeSwapBuffers, 
     97            AfterSwapBuffers 
     98        }; 
     99         
     100         /** Set the position of the end barrier. 
     101          * AfterSwapBuffers will may result is slightly higher framerates, by may 
     102          * lead to inconcistent swapping between different windows. 
     103          * BeforeSwapBuffers may lead to slightly lower framerate, but improve consistency in timing of swap buffers, 
     104          * especially important if you are likely to consistently break frame.*/ 
     105        void setEndBarrierPosition(BarrierPosition bp); 
     106 
     107        /** Get the end barrier position.*/ 
     108        BarrierPosition getEndBarrierPosition() const { return _endBarrierPosition; } 
     109 
     110  
    79111  
    80112        /** Set the done flag to singnal the viewer's work is done and should exit the frame loop.*/ 
     
    134166        /** Remove an update operation.*/ 
    135167        void removeUpdateOperation(osg::Operation* operation); 
     168 
     169 
     170        /** Set the graphics operation to call on realization of the viewers graphics windows.*/ 
     171        void setRealizeOperation(osg::Operation* op) { _realizeOperation = op; } 
     172 
     173        /** Get the graphics operation to call on realization of the viewers graphics windows.*/ 
     174        osg::Operation* getRealizeOperation() { return _realizeOperation.get(); } 
     175 
     176 
     177        /** Check to see if windows are still open, if not set viewer done to true. */ 
     178        void checkWindowStatus(); 
     179 
    136180 
    137181 
     
    145189        /** Render a complete new frame. 
    146190          * Calls advance(), eventTraversal(), updateTraversal(), renderingTraversals(). */ 
    147         virtual void frame(double simulationTime=USE_REFERENCE_TIME) = 0; 
     191        virtual void frame(double simulationTime=USE_REFERENCE_TIME); 
    148192 
    149193        virtual void advance(double simulationTime=USE_REFERENCE_TIME) = 0; 
     
    153197        virtual void updateTraversal() = 0; 
    154198         
    155         virtual void renderingTraversals() = 0; 
     199        virtual void renderingTraversals(); 
    156200 
    157201        typedef std::vector<osg::Camera*> Cameras; 
     
    176220        virtual void getViews(Views& views, bool onlyValid=true) = 0; 
    177221 
    178  
    179         /** Set the graphics operation to call on realization of the viewers graphics windows.*/ 
    180         void setRealizeOperation(osg::Operation* op) { _realizeOperation = op; } 
    181  
    182         /** Get the graphics operation to call on realization of the viewers graphics windows.*/ 
    183         osg::Operation* getRealizeOperation() { return _realizeOperation.get(); } 
    184  
    185         /** Set up the threading and processor affinity as per the viewers threading model.*/ 
    186         virtual void setUpThreading() = 0; 
    187  
    188         /** Return true if viewer threads are running. */ 
    189         bool areThreadsRunning() const { return _threadsRunning; } 
    190  
    191         /** Stop any threads begin run by viewer.*/ 
    192         virtual void stopThreading() = 0; 
    193  
    194         /** Start any threads required by the viewer.*/ 
    195         virtual void startThreading() = 0;         
     222        virtual double elapsedTime() = 0; 
     223 
     224        virtual osg::FrameStamp* getViewerFrameStamp() = 0; 
    196225 
    197226        /** Get the keyboard and mouse usage of this viewer.*/ 
     
    200229    protected: 
    201230     
     231        inline void makeCurrent(osg::GraphicsContext* gc) 
     232        { 
     233            if (_currentContext==gc) return; 
     234             
     235            releaseContext(); 
     236             
     237            if (gc && gc->valid() && gc->makeCurrent()) _currentContext = gc; 
     238        } 
     239         
     240        inline void releaseContext() 
     241        { 
     242            if (_currentContext.valid() && _currentContext->valid()) 
     243            { 
     244                _currentContext->releaseContext(); 
     245            } 
     246            _currentContext = 0; 
     247        } 
     248 
     249        virtual void viewerInit() = 0; 
     250         
     251 
    202252        osg::ref_ptr<osg::Stats>                    _stats; 
    203253 
     254        bool                                        _firstFrame; 
    204255        bool                                        _done; 
    205256        int                                         _keyEventSetsDone; 
     
    208259        ThreadingModel                              _threadingModel; 
    209260        bool                                        _threadsRunning; 
     261 
     262        BarrierPosition                             _endBarrierPosition; 
     263 
     264        osg::ref_ptr<osg::BarrierOperation>         _startRenderingBarrier; 
     265        osg::ref_ptr<osg::BarrierOperation>         _endRenderingDispatchBarrier; 
     266        osg::ref_ptr<osg::EndOfDynamicDrawBlock>    _endDynamicDrawBlock; 
    210267         
    211268        osg::ref_ptr<osgGA::EventVisitor>           _eventVisitor; 
     
    216273        osg::ref_ptr<osg::Operation>                _realizeOperation; 
    217274 
     275        osg::observer_ptr<osg::GraphicsContext>     _currentContext; 
    218276}; 
     277 
    219278} 
    220279