2005-04-15 05:41:28 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2005 Robert Osfield
|
2003-01-21 21:14:29 +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
|
|
|
|
* (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.
|
|
|
|
*/
|
|
|
|
|
2003-02-25 20:28:16 +08:00
|
|
|
#ifndef OSGPRODUCER_OSGSCENEHANDLER
|
|
|
|
#define OSGPRODUCER_OSGSCENEHANDLER 1
|
2003-01-18 02:34:35 +08:00
|
|
|
|
2004-09-24 02:50:38 +08:00
|
|
|
#include <osg/Timer>
|
|
|
|
#include <osgUtil/SceneView>
|
2003-01-18 02:34:35 +08:00
|
|
|
|
|
|
|
#include <Producer/Camera>
|
2004-09-24 02:50:38 +08:00
|
|
|
|
|
|
|
#include <osgProducer/Export>
|
|
|
|
|
|
|
|
|
2003-01-18 02:34:35 +08:00
|
|
|
|
|
|
|
namespace osgProducer {
|
|
|
|
|
2003-06-24 23:40:09 +08:00
|
|
|
class OSGPRODUCER_EXPORT OsgSceneHandler : public Producer::Camera::SceneHandler
|
2003-01-18 02:34:35 +08:00
|
|
|
{
|
|
|
|
public :
|
2003-01-19 06:07:59 +08:00
|
|
|
|
2003-03-21 01:24:25 +08:00
|
|
|
OsgSceneHandler(osg::DisplaySettings *ds = NULL);
|
2003-06-24 23:40:09 +08:00
|
|
|
|
|
|
|
/// set the scene view to which will manage rendering of the OSG scene.
|
|
|
|
void setSceneView(osgUtil::SceneView* sceneView) { _sceneView = sceneView; }
|
|
|
|
|
|
|
|
/// get the scene view.
|
|
|
|
osgUtil::SceneView* getSceneView() { return _sceneView.get(); }
|
|
|
|
|
|
|
|
/// get the const scene view.
|
|
|
|
const osgUtil::SceneView* getSceneView() const { return _sceneView.get(); }
|
2003-01-18 02:34:35 +08:00
|
|
|
|
2003-01-21 04:33:50 +08:00
|
|
|
/// override the init method to force it be run one at a time.
|
|
|
|
virtual void init();
|
2003-03-26 20:50:30 +08:00
|
|
|
|
|
|
|
|
|
|
|
class Callback : public osg::Referenced
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~Callback() {}
|
2003-07-09 22:55:39 +08:00
|
|
|
virtual void operator()(OsgSceneHandler&, Producer::Camera &) = 0;
|
2003-03-26 20:50:30 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
virtual void clear(Producer::Camera& camera)
|
|
|
|
{
|
|
|
|
if (_clearCallback.valid()) (*_clearCallback)(*this,camera);
|
|
|
|
else clearImplementation(camera);
|
|
|
|
}
|
2003-01-21 04:33:50 +08:00
|
|
|
|
2003-03-26 20:50:30 +08:00
|
|
|
virtual void clearImplementation(Producer::Camera& camera);
|
|
|
|
|
|
|
|
void setClearCallback(Callback* callback) { _clearCallback = callback; }
|
|
|
|
Callback* getClearCallback() { return _clearCallback.get(); }
|
|
|
|
const Callback* getClearCallback() const { return _clearCallback.get(); }
|
|
|
|
|
|
|
|
|
|
|
|
virtual void cull(Producer::Camera& camera)
|
|
|
|
{
|
|
|
|
if (_cullCallback.valid()) (*_cullCallback)(*this,camera);
|
|
|
|
else cullImplementation(camera);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void cullImplementation(Producer::Camera& camera);
|
|
|
|
|
|
|
|
void setCullCallback(Callback* callback) { _cullCallback = callback; }
|
|
|
|
Callback* getCullCallback() { return _cullCallback.get(); }
|
|
|
|
const Callback* getCullCallback() const { return _cullCallback.get(); }
|
|
|
|
|
|
|
|
virtual void draw(Producer::Camera& camera)
|
|
|
|
{
|
2005-11-10 19:39:01 +08:00
|
|
|
if (_cleanUpOnNextFrame)
|
2005-05-08 04:47:09 +08:00
|
|
|
{
|
|
|
|
_sceneView->flushAllDeletedGLObjects();
|
2005-11-10 19:39:01 +08:00
|
|
|
_flushOfAllDeletedGLObjectsOnNextFrame = false;
|
|
|
|
_cleanUpOnNextFrame = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (_flushOfAllDeletedGLObjectsOnNextFrame && _sceneView.valid())
|
|
|
|
{
|
|
|
|
_sceneView->flushAllDeletedGLObjects();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_drawCallback.valid()) (*_drawCallback)(*this,camera);
|
|
|
|
else drawImplementation(camera);
|
|
|
|
|
|
|
|
_flushOfAllDeletedGLObjectsOnNextFrame = false;
|
2005-05-08 04:47:09 +08:00
|
|
|
}
|
2003-03-26 20:50:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void drawImplementation(Producer::Camera& camera);
|
|
|
|
|
|
|
|
void setDrawCallback(Callback* callback) { _drawCallback = callback; }
|
|
|
|
Callback* getDrawCallback() { return _drawCallback.get(); }
|
|
|
|
const Callback* getDrawCallback() const { return _drawCallback.get(); }
|
2003-01-18 02:34:35 +08:00
|
|
|
|
2003-03-21 01:24:25 +08:00
|
|
|
void setContextID( int id );
|
2003-01-18 02:34:35 +08:00
|
|
|
|
2005-05-08 04:47:09 +08:00
|
|
|
void setFlushOfAllDeletedGLObjectsOnNextFrame(bool flag) { _flushOfAllDeletedGLObjectsOnNextFrame = flag; }
|
|
|
|
|
|
|
|
bool getFlushOfAllDeletedGLObjectsOnNextFrame() const { return _flushOfAllDeletedGLObjectsOnNextFrame; }
|
|
|
|
|
2005-11-10 19:39:01 +08:00
|
|
|
void setCleanUpOnNextFrame(bool flag) { _cleanUpOnNextFrame = flag; }
|
|
|
|
|
|
|
|
bool getCleanUpOnNextFrame() const { return _cleanUpOnNextFrame; }
|
|
|
|
|
2003-01-19 06:07:59 +08:00
|
|
|
protected:
|
|
|
|
|
2003-02-25 20:28:16 +08:00
|
|
|
virtual ~OsgSceneHandler() {}
|
2003-06-24 23:40:09 +08:00
|
|
|
|
|
|
|
|
|
|
|
osg::ref_ptr<osgUtil::SceneView> _sceneView;
|
2003-01-19 06:07:59 +08:00
|
|
|
|
2003-03-26 20:50:30 +08:00
|
|
|
osg::ref_ptr<Callback> _clearCallback;
|
|
|
|
osg::ref_ptr<Callback> _cullCallback;
|
|
|
|
osg::ref_ptr<Callback> _drawCallback;
|
2004-09-24 02:50:38 +08:00
|
|
|
|
|
|
|
osg::Timer_t _frameStartTick;
|
2004-10-01 03:36:15 +08:00
|
|
|
osg::Timer_t _previousFrameStartTick;
|
2005-05-08 04:47:09 +08:00
|
|
|
|
|
|
|
bool _flushOfAllDeletedGLObjectsOnNextFrame;
|
2005-11-10 19:39:01 +08:00
|
|
|
bool _cleanUpOnNextFrame;
|
2003-01-18 02:34:35 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|