2001-10-04 23:12:57 +08:00
|
|
|
//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield
|
|
|
|
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
|
|
|
//as published by the Free Software Foundation.
|
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
#ifndef OSGUTIL_RENDERSTAGE
|
|
|
|
#define OSGUTIL_RENDERSTAGE 1
|
|
|
|
|
|
|
|
#include <osg/Camera>
|
2001-12-03 06:20:46 +08:00
|
|
|
#include <osg/ColorMask>
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
#include <osgUtil/RenderBin>
|
|
|
|
#include <osgUtil/RenderStageLighting>
|
|
|
|
|
|
|
|
namespace osgUtil {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* RenderState base class. Used for encapsulate a complete stage in
|
|
|
|
* rendering - setting up of viewport, the projection and model
|
|
|
|
* matrices and rendering the RenderBin's enclosed with this RenderStage.
|
2001-09-28 20:36:40 +08:00
|
|
|
* RenderStage also has a dependency list of other RenderStages, each
|
2001-09-20 05:19:47 +08:00
|
|
|
* of which must be called before the rendering of this stage. These
|
|
|
|
* 'pre' rendering stages are used for advanced rendering techniques
|
|
|
|
* like multistage pixel shading or impostors.
|
|
|
|
*/
|
|
|
|
class OSGUTIL_EXPORT RenderStage : public RenderBin
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
|
|
RenderStage();
|
|
|
|
virtual osg::Object* clone() const { return new RenderStage(); }
|
|
|
|
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const RenderStage*>(obj)!=0L; }
|
|
|
|
virtual const char* className() const { return "RenderStage"; }
|
|
|
|
|
|
|
|
virtual void reset();
|
|
|
|
|
|
|
|
|
2001-09-22 10:42:08 +08:00
|
|
|
/** Set the viewport.*/
|
|
|
|
void setViewport(osg::Viewport* viewport) { _viewport = viewport; }
|
|
|
|
|
|
|
|
/** Get the const viewport. */
|
|
|
|
const osg::Viewport* getViewport() const { return _viewport.get(); }
|
|
|
|
|
|
|
|
/** Get the viewport. */
|
|
|
|
osg::Viewport* getViewport() { return _viewport.get(); }
|
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
|
|
|
|
/** Set the clear mask used in glClear(..).
|
|
|
|
* Defaults to GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT. */
|
|
|
|
void setClearMask(const GLbitfield mask) { _clearMask = mask; }
|
|
|
|
|
|
|
|
/** Get the clear mask.*/
|
|
|
|
const GLbitfield getClearMask() const { return _clearMask; }
|
|
|
|
|
|
|
|
|
2001-12-03 06:20:46 +08:00
|
|
|
void setColorMask(osg::ColorMask* cm) { _colorMask = cm; }
|
|
|
|
osg::ColorMask* getColorMask() { return _colorMask.get(); }
|
|
|
|
const osg::ColorMask* getColorMask() const { return _colorMask.get(); }
|
|
|
|
|
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
/** Set the clear color used in glClearColor(..).
|
|
|
|
* glClearColor is only called if mask & GL_COLOR_BUFFER_BIT is true*/
|
|
|
|
void setClearColor(const osg::Vec4& color) { _clearColor=color; }
|
|
|
|
|
|
|
|
/** Get the clear color.*/
|
|
|
|
const osg::Vec4& getClearColor() const { return _clearColor; }
|
|
|
|
|
|
|
|
|
|
|
|
/** Set the clear accum used in glClearAccum(..).
|
|
|
|
* glClearAcumm is only called if mask & GL_ACCUM_BUFFER_BIT is true*/
|
|
|
|
void setClearAccum(const osg::Vec4& color) { _clearAccum=color; }
|
|
|
|
|
|
|
|
/** Get the clear accum.*/
|
|
|
|
const osg::Vec4& getClearAccum() const { return _clearAccum; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Set the clear depth used in glClearDepth(..). Defaults to 1.0
|
|
|
|
* glClearDepth is only called if mask & GL_DEPTH_BUFFER_BIT is true*/
|
|
|
|
void setClearDepth(const double depth) { _clearDepth=depth; }
|
|
|
|
|
|
|
|
/** Get the clear depth.*/
|
|
|
|
const double getClearDepth() const { return _clearDepth; }
|
|
|
|
|
|
|
|
|
|
|
|
/** Set the clear stencil value used in glClearStencil(). Defaults to 1.0
|
|
|
|
* glClearStencil is only called if mask & GL_STENCIL_BUFFER_BIT is true*/
|
|
|
|
void setClearStencil(const int stencil) { _clearStencil=stencil; }
|
|
|
|
|
|
|
|
/** Get the clear color.*/
|
|
|
|
const int getClearStencil() const { return _clearStencil; }
|
|
|
|
|
|
|
|
|
|
|
|
void setCamera(osg::Camera* camera) { _camera = camera; }
|
|
|
|
osg::Camera* getCamera() { return _camera.get(); }
|
|
|
|
const osg::Camera* getCamera() const { return _camera.get(); }
|
|
|
|
|
|
|
|
|
|
|
|
void setRenderStageLighting(RenderStageLighting* rsl) { _renderStageLighting = rsl; }
|
|
|
|
|
|
|
|
RenderStageLighting* getRenderStageLighting() const
|
|
|
|
{
|
|
|
|
if (!_renderStageLighting.valid()) _renderStageLighting = new RenderStageLighting;
|
|
|
|
return _renderStageLighting.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
void setLightingMode(RenderStageLighting::Mode mode) { getRenderStageLighting()->setLightingMode(mode); }
|
|
|
|
RenderStageLighting::Mode getLightingMode() const { return getRenderStageLighting()->getLightingMode(); }
|
|
|
|
|
|
|
|
void setLight(osg::Light* light) { getRenderStageLighting()->setLight(light); }
|
|
|
|
osg::Light* getLight() { return getRenderStageLighting()->getLight(); }
|
|
|
|
const osg::Light* getLight() const { return getRenderStageLighting()->getLight(); }
|
|
|
|
|
|
|
|
virtual void addLight(osg::Light* light,osg::Matrix* matrix)
|
|
|
|
{
|
|
|
|
getRenderStageLighting()->addLight(light,matrix);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void draw(osg::State& state,RenderLeaf*& previous);
|
|
|
|
|
|
|
|
void addToDependencyList(RenderStage* rs);
|
|
|
|
|
|
|
|
/** extract stats for current draw list. */
|
2001-11-05 03:29:20 +08:00
|
|
|
bool getStats(osg::Statistics* primStats);
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
typedef std::vector< osg::ref_ptr<RenderStage> > DependencyList;
|
|
|
|
|
|
|
|
bool _stageDrawnThisFrame;
|
|
|
|
DependencyList _dependencyList;
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Camera> _camera;
|
|
|
|
|
|
|
|
// viewport x,y,width,height.
|
2001-09-22 10:42:08 +08:00
|
|
|
osg::ref_ptr<osg::Viewport> _viewport;
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
GLbitfield _clearMask;
|
2001-12-03 06:20:46 +08:00
|
|
|
osg::ref_ptr<osg::ColorMask> _colorMask;
|
2001-09-20 05:19:47 +08:00
|
|
|
osg::Vec4 _clearColor;
|
|
|
|
osg::Vec4 _clearAccum;
|
|
|
|
double _clearDepth;
|
|
|
|
int _clearStencil;
|
|
|
|
|
|
|
|
mutable osg::ref_ptr<RenderStageLighting> _renderStageLighting;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
virtual ~RenderStage();
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|