2012-03-22 01:36:20 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2007-08-02 19:02:47 +08:00
|
|
|
*
|
2012-03-22 01:36:20 +08:00
|
|
|
* 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
|
2007-08-02 19:02:47 +08:00
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
2012-03-22 01:36:20 +08:00
|
|
|
*
|
2007-08-02 19:02:47 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-03-22 01:36:20 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2007-08-02 19:02:47 +08:00
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef OSGVIEWER_RENDERER
|
|
|
|
#define OSGVIEWER_RENDERER 1
|
|
|
|
|
2011-01-12 00:58:17 +08:00
|
|
|
#include <OpenThreads/Condition>
|
2007-08-02 19:02:47 +08:00
|
|
|
#include <osg/Timer>
|
2008-04-17 02:13:41 +08:00
|
|
|
#include <osgDB/DatabasePager>
|
2007-08-02 19:02:47 +08:00
|
|
|
#include <osgUtil/SceneView>
|
|
|
|
#include <osgViewer/Export>
|
|
|
|
|
|
|
|
namespace osgViewer {
|
|
|
|
|
2010-11-11 00:58:58 +08:00
|
|
|
class OSGVIEWER_EXPORT OpenGLQuerySupport : public osg::Referenced
|
2007-08-02 19:02:47 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
OpenGLQuerySupport();
|
|
|
|
|
2010-11-11 00:58:58 +08:00
|
|
|
virtual void checkQuery(osg::Stats* stats, osg::State* state,
|
|
|
|
osg::Timer_t startTick) = 0;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-12-23 04:11:05 +08:00
|
|
|
virtual void beginQuery(unsigned int frameNumber, osg::State* state) = 0;
|
2010-11-11 00:58:58 +08:00
|
|
|
virtual void endQuery(osg::State* state) = 0;
|
|
|
|
virtual void initialize(osg::State* state, osg::Timer_t startTick);
|
2007-08-02 19:02:47 +08:00
|
|
|
protected:
|
|
|
|
|
|
|
|
const osg::Drawable::Extensions* _extensions;
|
|
|
|
};
|
|
|
|
|
2010-11-11 00:58:58 +08:00
|
|
|
class OSGVIEWER_EXPORT Renderer : public osg::GraphicsOperation
|
2007-08-02 19:02:47 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
Renderer(osg::Camera* camera);
|
|
|
|
|
|
|
|
osgUtil::SceneView* getSceneView(unsigned int i) { return _sceneView[i].get(); }
|
2010-04-19 19:43:06 +08:00
|
|
|
const osgUtil::SceneView* getSceneView(unsigned int i) const { return _sceneView[i].get(); }
|
2007-08-02 19:02:47 +08:00
|
|
|
|
|
|
|
void setDone(bool done) { _done = done; }
|
|
|
|
bool getDone() { return _done; }
|
|
|
|
|
|
|
|
void setGraphicsThreadDoesCull(bool flag);
|
|
|
|
bool getGraphicsThreadDoesCull() const { return _graphicsThreadDoesCull; }
|
|
|
|
|
2008-05-11 01:04:02 +08:00
|
|
|
|
2008-04-17 02:13:41 +08:00
|
|
|
virtual void cull();
|
|
|
|
virtual void draw();
|
|
|
|
virtual void cull_draw();
|
2007-08-02 19:02:47 +08:00
|
|
|
|
2008-05-11 01:04:02 +08:00
|
|
|
virtual void compile();
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2008-05-11 01:04:02 +08:00
|
|
|
void setCompileOnNextDraw(bool flag) { _compileOnNextDraw = flag; }
|
|
|
|
bool getCompileOnNextDraw() const { return _compileOnNextDraw; }
|
|
|
|
|
2007-08-02 19:02:47 +08:00
|
|
|
virtual void operator () (osg::Object* object);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2007-08-02 19:02:47 +08:00
|
|
|
virtual void operator () (osg::GraphicsContext* context);
|
|
|
|
|
|
|
|
virtual void release();
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2010-04-19 19:43:06 +08:00
|
|
|
/** Force update of state associated with cameras. */
|
|
|
|
void setCameraRequiresSetUp(bool flag);
|
|
|
|
bool getCameraRequiresSetUp() const;
|
|
|
|
|
2007-08-26 17:46:49 +08:00
|
|
|
protected:
|
2010-11-11 00:58:58 +08:00
|
|
|
void initialize(osg::State* state);
|
2007-08-02 19:02:47 +08:00
|
|
|
virtual ~Renderer();
|
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
virtual void updateSceneView(osgUtil::SceneView* sceneView);
|
2008-04-17 02:13:41 +08:00
|
|
|
|
2007-08-02 19:02:47 +08:00
|
|
|
osg::observer_ptr<osg::Camera> _camera;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2007-08-02 19:02:47 +08:00
|
|
|
bool _done;
|
|
|
|
bool _graphicsThreadDoesCull;
|
2008-05-11 01:04:02 +08:00
|
|
|
bool _compileOnNextDraw;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2007-08-02 19:02:47 +08:00
|
|
|
osg::ref_ptr<osgUtil::SceneView> _sceneView[2];
|
|
|
|
|
2008-11-08 01:23:55 +08:00
|
|
|
struct OSGVIEWER_EXPORT ThreadSafeQueue
|
2007-08-23 01:17:25 +08:00
|
|
|
{
|
|
|
|
OpenThreads::Mutex _mutex;
|
2011-01-12 00:58:17 +08:00
|
|
|
OpenThreads::Condition _cond;
|
2007-08-23 01:17:25 +08:00
|
|
|
typedef std::list<osgUtil::SceneView*> SceneViewList;
|
|
|
|
SceneViewList _queue;
|
2011-01-12 00:58:17 +08:00
|
|
|
bool _isReleased;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2008-11-08 01:23:55 +08:00
|
|
|
ThreadSafeQueue();
|
|
|
|
~ThreadSafeQueue();
|
2011-01-12 00:58:17 +08:00
|
|
|
|
|
|
|
/** Release any thread waiting on the queue, even if the queue is empty. */
|
|
|
|
void release();
|
|
|
|
|
|
|
|
/** Take a SceneView from the queue. Can return 0 if release() is called when the queue is empty. */
|
2007-08-23 01:17:25 +08:00
|
|
|
osgUtil::SceneView* takeFront();
|
2011-01-12 00:58:17 +08:00
|
|
|
|
|
|
|
/** Add a SceneView object to the back of the queue. */
|
2007-08-23 01:17:25 +08:00
|
|
|
void add(osgUtil::SceneView* sv);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-11-08 01:23:55 +08:00
|
|
|
ThreadSafeQueue _availableQueue;
|
|
|
|
ThreadSafeQueue _drawQueue;
|
2007-08-23 01:17:25 +08:00
|
|
|
|
2010-11-11 00:58:58 +08:00
|
|
|
bool _initialized;
|
|
|
|
osg::ref_ptr<OpenGLQuerySupport> _querySupport;
|
|
|
|
osg::Timer_t _startTick;
|
2007-08-02 19:02:47 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|