1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
14#ifndef OSGVIEWER_RENDERER
15#define OSGVIEWER_RENDERER 1
17#include <OpenThreads/Condition>
19#include <osgDB/DatabasePager>
20#include <osgUtil/SceneView>
21#include <osgViewer/Export>
25class OSGVIEWER_EXPORT OpenGLQuerySupport : public osg::Referenced
30 virtual void checkQuery(osg::Stats* stats, osg::State* state,
31 osg::Timer_t startTick) = 0;
33 virtual void beginQuery(unsigned int frameNumber, osg::State* state) = 0;
34 virtual void endQuery(osg::State* state) = 0;
35 virtual void initialize(osg::State* state, osg::Timer_t startTick);
38 const osg::GLExtensions* _extensions;
41class OSGVIEWER_EXPORT Renderer : public osg::GraphicsOperation
45 Renderer(osg::Camera* camera);
47 osgUtil::SceneView* getSceneView(unsigned int i) { return _sceneView[i].get(); }
48 const osgUtil::SceneView* getSceneView(unsigned int i) const { return _sceneView[i].get(); }
50 void setDone(bool done) { _done = done; }
51 bool getDone() { return _done; }
53 void setGraphicsThreadDoesCull(bool flag);
54 bool getGraphicsThreadDoesCull() const { return _graphicsThreadDoesCull; }
59 virtual void cull_draw();
61 virtual void compile();
63 virtual void resizeGLObjectBuffers(unsigned int maxSize);
64 virtual void releaseGLObjects(osg::State* = 0) const;
66 void setCompileOnNextDraw(bool flag) { _compileOnNextDraw = flag; }
67 bool getCompileOnNextDraw() const { return _compileOnNextDraw; }
69 virtual void operator () (osg::Object* object);
71 virtual void operator () (osg::GraphicsContext* context);
73 virtual void release();
77 /** Force update of state associated with cameras. */
78 void setCameraRequiresSetUp(bool flag);
79 bool getCameraRequiresSetUp() const;
82 void initialize(osg::State* state);
85 virtual void updateSceneView(osgUtil::SceneView* sceneView);
87 osg::observer_ptr<osg::Camera> _camera;
90 bool _graphicsThreadDoesCull;
91 bool _compileOnNextDraw;
94 osg::ref_ptr<osgUtil::SceneView> _sceneView[2];
96 struct OSGVIEWER_EXPORT ThreadSafeQueue
98 OpenThreads::Mutex _mutex;
99 OpenThreads::Condition _cond;
100 typedef std::list<osgUtil::SceneView*> SceneViewList;
101 SceneViewList _queue;
107 /** Release any thread waiting on the queue, even if the queue is empty. */
110 /** Reset to fefault state (_isReleased = false)*/
113 /** Take a SceneView from the queue. Can return 0 if release() is called when the queue is empty. */
114 osgUtil::SceneView* takeFront();
116 /** Add a SceneView object to the back of the queue. */
117 void add(osgUtil::SceneView* sv);
121 ThreadSafeQueue _availableQueue;
122 ThreadSafeQueue _drawQueue;
125 osg::ref_ptr<OpenGLQuerySupport> _querySupport;
126 osg::Timer_t _startTick;