2003-01-22 00:45:36 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 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.
|
|
|
|
*/
|
2001-10-04 23:12:57 +08:00
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
#ifndef OSGUTIL_RENDERSTAGE
|
|
|
|
#define OSGUTIL_RENDERSTAGE 1
|
|
|
|
|
2001-12-03 06:20:46 +08:00
|
|
|
#include <osg/ColorMask>
|
2002-04-13 19:08:04 +08:00
|
|
|
#include <osg/Viewport>
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
#include <osgUtil/RenderBin>
|
|
|
|
#include <osgUtil/RenderStageLighting>
|
|
|
|
|
|
|
|
namespace osgUtil {
|
|
|
|
|
|
|
|
/**
|
2004-09-27 02:39:34 +08:00
|
|
|
* RenderStage base class. Used for encapsulate a complete stage in
|
2001-09-20 05:19:47 +08:00
|
|
|
* 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:
|
|
|
|
|
|
|
|
|
2002-09-17 23:47:23 +08:00
|
|
|
RenderStage(SortMode mode=SORT_BY_STATE);
|
|
|
|
|
|
|
|
RenderStage(const RenderStage& rhs,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
|
|
|
|
2002-12-16 21:40:58 +08:00
|
|
|
virtual osg::Object* cloneType() const { return new RenderStage(); }
|
|
|
|
virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new RenderStage(*this,copyop); } // note only implements a clone of type.
|
2001-09-20 05:19:47 +08:00
|
|
|
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. */
|
2002-09-02 20:31:35 +08:00
|
|
|
void setClearMask(GLbitfield mask) { _clearMask = mask; }
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
/** Get the clear mask.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
GLbitfield getClearMask() const { return _clearMask; }
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
|
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(..).
|
2004-09-27 02:39:34 +08:00
|
|
|
* glClearAcumm is only called if mask & GL_ACCUM_BUFFER_BIT is true. */
|
2001-09-20 05:19:47 +08:00
|
|
|
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
|
2004-09-27 02:39:34 +08:00
|
|
|
* glClearDepth is only called if mask & GL_DEPTH_BUFFER_BIT is true. */
|
2002-09-02 20:31:35 +08:00
|
|
|
void setClearDepth(double depth) { _clearDepth=depth; }
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
/** Get the clear depth.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
double getClearDepth() const { return _clearDepth; }
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
|
2004-09-27 02:39:34 +08:00
|
|
|
/** Set the clear stencil value used in glClearStencil(). Defaults to 0;
|
2001-09-20 05:19:47 +08:00
|
|
|
* glClearStencil is only called if mask & GL_STENCIL_BUFFER_BIT is true*/
|
2002-09-02 20:31:35 +08:00
|
|
|
void setClearStencil(int stencil) { _clearStencil=stencil; }
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
/** Get the clear color.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
int getClearStencil() const { return _clearStencil; }
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
void setRenderStageLighting(RenderStageLighting* rsl) { _renderStageLighting = rsl; }
|
|
|
|
|
|
|
|
RenderStageLighting* getRenderStageLighting() const
|
|
|
|
{
|
2002-12-16 21:40:58 +08:00
|
|
|
if (!_renderStageLighting.valid()) _renderStageLighting = new RenderStageLighting;
|
2001-09-20 05:19:47 +08:00
|
|
|
return _renderStageLighting.get();
|
|
|
|
}
|
|
|
|
|
2003-01-10 17:25:42 +08:00
|
|
|
virtual void addPositionedAttribute(osg::RefMatrix* matrix,const osg::StateAttribute* attr)
|
2001-09-20 05:19:47 +08:00
|
|
|
{
|
2002-05-02 08:14:40 +08:00
|
|
|
getRenderStageLighting()->addPositionedAttribute(matrix,attr);
|
2001-09-20 05:19:47 +08:00
|
|
|
}
|
2002-05-02 08:14:40 +08:00
|
|
|
|
2004-06-17 22:02:15 +08:00
|
|
|
virtual void addPositionedTextureAttribute(unsigned int textureUnit, osg::RefMatrix* matrix,const osg::StateAttribute* attr)
|
|
|
|
{
|
|
|
|
getRenderStageLighting()->addPositionedTextureAttribute(textureUnit, matrix,attr);
|
|
|
|
}
|
|
|
|
|
2002-09-19 17:52:50 +08:00
|
|
|
virtual void drawPreRenderStages(osg::State& state,RenderLeaf*& previous);
|
2002-10-17 21:48:46 +08:00
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
virtual void draw(osg::State& state,RenderLeaf*& previous);
|
2004-09-27 02:39:34 +08:00
|
|
|
|
2002-10-17 21:48:46 +08:00
|
|
|
virtual void drawImplementation(osg::State& state,RenderLeaf*& previous);
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
void addToDependencyList(RenderStage* rs);
|
|
|
|
|
2004-09-27 02:39:34 +08:00
|
|
|
/** Extract stats for current draw list. */
|
2003-07-15 21:46:19 +08:00
|
|
|
bool getStats(Statistics* primStats);
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2004-08-02 20:19:50 +08:00
|
|
|
#ifndef USE_DEPRECATED_API
|
|
|
|
protected:
|
|
|
|
#endif
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2004-08-02 20:19:50 +08:00
|
|
|
virtual ~RenderStage();
|
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
typedef std::vector< osg::ref_ptr<RenderStage> > DependencyList;
|
|
|
|
|
|
|
|
bool _stageDrawnThisFrame;
|
|
|
|
DependencyList _dependencyList;
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2002-02-03 20:33:41 +08:00
|
|
|
}
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|