Introduce new osgViewer::Renderer class for implementing of the rendering

of cameras in viewers
This commit is contained in:
Robert Osfield
2007-08-02 11:02:47 +00:00
parent 1b36cfc928
commit c346f5b943
27 changed files with 1040 additions and 1137 deletions

View File

@@ -373,13 +373,23 @@ class OSG_EXPORT Camera : public Transform, public CullSettings
/** Set the Rendering object that is used to implement rendering of the subgraph.*/
void setRenderer(osg::Object* rc) { _renderer = rc; }
void setRenderer(osg::GraphicsOperation* rc) { _renderer = rc; }
/** Get the Rendering object that is used to implement rendering of the subgraph.*/
osg::Object* getRenderer() { return _renderer.get(); }
osg::GraphicsOperation* getRenderer() { return _renderer.get(); }
/** Get the const Rendering object that is used to implement rendering of the subgraph.*/
const osg::Object* getRenderer() const { return _renderer.get(); }
const osg::GraphicsOperation* getRenderer() const { return _renderer.get(); }
/** Set the Rendering cache that is used for cached objects associated with rendering of subgraphs.*/
void setRenderingCache(osg::Object* rc) { _renderingCache = rc; }
/** Get the Rendering cache that is used for cached objects associated with rendering of subgraphs.*/
osg::Object* getRenderingCache() { return _renderingCache.get(); }
/** Get the const Rendering cache that is used for cached objects associated with rendering of subgraphs.*/
const osg::Object* getRenderingCache() const { return _renderingCache.get(); }
/** Draw callback for custom operations.*/
@@ -471,7 +481,8 @@ class OSG_EXPORT Camera : public Transform, public CullSettings
ref_ptr<GraphicsContext> _graphicsContext;
ref_ptr<Object> _renderer;
ref_ptr<GraphicsOperation> _renderer;
ref_ptr<Object> _renderingCache;
ref_ptr<DrawCallback> _preDrawCallback;
ref_ptr<DrawCallback> _postDrawCallback;

View File

@@ -106,6 +106,17 @@ struct OSG_EXPORT FlushDeletedGLObjectsOperation : public GraphicsOperation
double _availableTime;
};
class OSG_EXPORT RunOperations : public osg::GraphicsOperation
{
public:
RunOperations():
osg::GraphicsOperation("RunOperation",true) {}
virtual void operator () (osg::GraphicsContext* context);
};
}
#endif

View File

@@ -957,6 +957,9 @@ class OSG_EXPORT State : public Referenced
inline void setFrameStamp(FrameStamp* fs) { _frameStamp = fs; }
/** Get the frame stamp for the current frame.*/
inline FrameStamp* getFrameStamp() { return _frameStamp.get(); }
/** Get the const frame stamp for the current frame.*/
inline const FrameStamp* getFrameStamp() const { return _frameStamp.get(); }

View File

@@ -127,10 +127,13 @@ class OSG_EXPORT View : public osg::Object
void updateSlave(unsigned int i);
protected :
virtual ~View();
virtual osg::GraphicsOperation* createRenderer(osg::Camera* camera) {}
osg::ref_ptr<osg::Stats> _stats;
LightingMode _lightingMode;

View File

@@ -158,10 +158,6 @@ class OSGVIEWER_EXPORT CompositeViewer : public osg::Referenced
/** Start any threads required by the viewer, as per viewers ThreadingModel.*/
void startThreading();
/** Set up the Operations to render the various viewer cameras on the viewers graphics windows.*/
void setUpRenderingSupport();
protected:
void constructorInit();
@@ -191,9 +187,6 @@ class OSGVIEWER_EXPORT CompositeViewer : public osg::Referenced
unsigned int _numThreadsOnBarrier;
typedef std::map<osg::ref_ptr<osg::Camera>, osg::ref_ptr<osgUtil::SceneView> > CameraSceneViewMap;
CameraSceneViewMap _cameraSceneViewMap;
osg::Timer_t _startTick;
osg::ref_ptr<osg::FrameStamp> _frameStamp;

103
include/osgViewer/Renderer Normal file
View File

@@ -0,0 +1,103 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSGVIEWER_RENDERER
#define OSGVIEWER_RENDERER 1
#include <osg/Timer>
#include <osgUtil/SceneView>
#include <osgViewer/Export>
namespace osgViewer {
class OpenGLQuerySupport
{
public:
OpenGLQuerySupport();
typedef std::pair<GLuint, int> QueryFrameNumberPair;
typedef std::list<QueryFrameNumberPair> QueryFrameNumberList;
typedef std::vector<GLuint> QueryList;
void setStartTick(osg::Timer_t startTick) { _startTick = startTick; }
osg::Timer_t getStartTick() const { return _startTick; }
void checkQuery(osg::Stats* stats);
GLuint createQueryObject();
void beginQuery(int frameNumber);
inline void endQuery();
void initialize(osg::State* state);
protected:
osg::Timer_t _startTick;
bool _initialized;
bool _timerQuerySupported;
const osg::Drawable::Extensions* _extensions;
QueryFrameNumberList _queryFrameNumberList;
QueryList _availableQueryObjects;
double _previousQueryTime;
};
class OSGVIEWER_EXPORT Renderer : public osg::GraphicsOperation, public OpenGLQuerySupport
{
public:
Renderer(osg::Camera* camera);
osgUtil::SceneView* getSceneView(unsigned int i) { return _sceneView[i].get(); }
void setDone(bool done) { _done = done; }
bool getDone() { return _done; }
void setGraphicsThreadDoesCull(bool flag);
bool getGraphicsThreadDoesCull() const { return _graphicsThreadDoesCull; }
void cull();
void draw();
void cull_draw();
virtual void operator () (osg::Object* object);
virtual void operator () (osg::GraphicsContext* context);
virtual void release();
protected:
void updateSceneView(osgUtil::SceneView* sceneView);
virtual ~Renderer();
osg::observer_ptr<osg::Camera> _camera;
bool _done;
bool _graphicsThreadDoesCull;
unsigned int _currentCull;
unsigned int _currentDraw;
OpenThreads::Mutex _mutex[2];
bool _lockHeld[2];
osg::ref_ptr<osgUtil::SceneView> _sceneView[2];
int _frameNumber[2];
osg::ref_ptr<osg::FlushDeletedGLObjectsOperation> _flushOperation;
};
}
#endif

View File

@@ -122,13 +122,13 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
void computeActiveCoordinateSystemNodePath();
/** Set the DsplaySettings object associated with this view.*/
/** Set the DisplaySettings object associated with this view.*/
void setDisplaySettings(osg::DisplaySettings* ds) { _displaySettings = ds; }
/** Set the DsplaySettings object associated with this view.*/
/** Set the DisplaySettings object associated with this view.*/
osg::DisplaySettings* getDisplaySettings() { return _displaySettings.get(); }
/** Set the DsplaySettings object associated with this view.*/
/** Set the DisplaySettings object associated with this view.*/
const osg::DisplaySettings* getDisplaySettings() const { return _displaySettings.get(); }
/** Set the FusionDistanceMode and Value. Note, is used only when working in stereo.*/
@@ -176,8 +176,6 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
virtual void requestRedraw();
virtual void requestContinuousUpdate(bool needed=true);
virtual void requestWarpPointer(float x,float y);
public:
@@ -186,9 +184,10 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
protected:
virtual ~View();
virtual osg::GraphicsOperation* createRenderer(osg::Camera* camera);
osg::ref_ptr<osgViewer::Scene> _scene;
osg::ref_ptr<osgGA::EventQueue> _eventQueue;
osg::ref_ptr<osgGA::MatrixManipulator> _cameraManipulator;

View File

@@ -172,9 +172,6 @@ class OSGVIEWER_EXPORT Viewer : public osgViewer::View
/** Start any threads required by the viewer.*/
void startThreading();
/** Set up the Operations to render the various viewer cameras on the viewers graphics windows.*/
void setUpRenderingSupport();
/** Get the keyboard and mouse usage of this viewer.*/
virtual void getUsage(osg::ApplicationUsage& usage) const;
@@ -221,9 +218,6 @@ class OSGVIEWER_EXPORT Viewer : public osgViewer::View
unsigned int _numWindowsOpenAtLastSetUpThreading;
typedef std::list< osg::ref_ptr<osgUtil::SceneView> > SceneViews;
SceneViews _sceneViews;
osg::Timer_t _startTick;
osg::ref_ptr<osg::FrameStamp> _frameStamp;