Stencil
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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.
*/
#ifndef OSG_STENCIL
#define OSG_STENCIL 1
#include <osg/StateAttribute>
namespace osg {
#ifndef GL_INCR_WRAP
#define GL_INCR_WRAP 0x8507
#define GL_DECR_WRAP 0x8508
#endif
class OSG_EXPORT Stencil : public StateAttribute
{
public :
Stencil();
Stencil(const Stencil& stencil,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
StateAttribute(stencil,copyop),
_func(stencil._func),
_funcRef(stencil._funcRef),
_funcMask(stencil._funcMask),
_sfail(stencil._sfail),
_zfail(stencil._zfail),
_zpass(stencil._zpass),
_writeMask(stencil._writeMask) {}
META_StateAttribute(osg, Stencil, STENCIL);
virtual int compare(const StateAttribute& sa) const
{
// check the types are equal and then create the rhs variable
// used by the COMPARE_StateAttribute_Parameter macros below.
COMPARE_StateAttribute_Types(Stencil,sa)
// compare each parameter in turn against the rhs.
COMPARE_StateAttribute_Parameter(_func)
COMPARE_StateAttribute_Parameter(_funcRef)
COMPARE_StateAttribute_Parameter(_funcMask)
COMPARE_StateAttribute_Parameter(_sfail)
COMPARE_StateAttribute_Parameter(_zfail)
COMPARE_StateAttribute_Parameter(_zpass)
COMPARE_StateAttribute_Parameter(_writeMask)
return 0; // passed all the above comparison macros, must be equal.
}
virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const
{
usage.usesMode(GL_STENCIL_TEST);
return true;
}
enum Function
{
NEVER = GL_NEVER,
LESS = GL_LESS,
EQUAL = GL_EQUAL,
LEQUAL = GL_LEQUAL,
GREATER = GL_GREATER,
NOTEQUAL = GL_NOTEQUAL,
GEQUAL = GL_GEQUAL,
ALWAYS = GL_ALWAYS
};
inline void setFunction(Function func,int ref,unsigned int mask)
{
_func = func;
_funcRef = ref;
_funcMask = mask;
}
inline void setFunction(Function func) { _func = func; }
inline Function getFunction() const { return _func; }
inline void setFunctionRef(int ref) { _funcRef=ref; }
inline int getFunctionRef() const { return _funcRef; }
inline void setFunctionMask(unsigned int mask) { _funcMask=mask; }
inline unsigned int getFunctionMask() const { return _funcMask; }
enum Operation
{
KEEP = GL_KEEP,
ZERO = GL_ZERO,
REPLACE = GL_REPLACE,
INCR = GL_INCR,
DECR = GL_DECR,
INVERT = GL_INVERT,
INCR_WRAP = GL_INCR_WRAP,
DECR_WRAP = GL_DECR_WRAP
};
inline void setOperation(Operation sfail, Operation zfail, Operation zpass)
{
_sfail = sfail;
_zfail = zfail;
_zpass = zpass;
}
inline void setStencilFailOperation(Operation sfail) { _sfail = sfail; }
inline Operation getStencilFailOperation() const { return _sfail; }
inline void setStencilPassAndDepthFailOperation(Operation zfail) { _zfail=zfail; }
inline Operation getStencilPassAndDepthFailOperation() const { return _zfail; }
inline void setStencilPassAndDepthPassOperation(Operation zpass) { _zpass=zpass; }
inline Operation getStencilPassAndDepthPassOperation() const { return _zpass; }
inline void setWriteMask(unsigned int mask) { _writeMask = mask; }
inline unsigned int getWriteMask() const { return _writeMask; }
virtual void apply(State& state) const;
protected:
virtual ~Stencil();
Function _func;
int _funcRef;
unsigned int _funcMask;
Operation _sfail;
Operation _zfail;
Operation _zpass;
unsigned int _writeMask;
};
}
#endif
StateAttribute
COMPARE_StateAttribute_Parameter
#define COMPARE_StateAttribute_Parameter(parameter)
Definition StateAttribute:69
COMPARE_StateAttribute_Types
#define COMPARE_StateAttribute_Types(TYPE, rhs_attribute)
Definition StateAttribute:57
GL_DECR_WRAP
#define GL_DECR_WRAP
Definition Stencil:23
GL_INCR_WRAP
#define GL_INCR_WRAP
Definition Stencil:22
osg::CopyOp
Definition CopyOp:41
osg::CopyOp::SHALLOW_COPY
@ SHALLOW_COPY
Definition CopyOp:47
osg::Referenced::ref
int ref() const
Definition Referenced:161
osg::StateAttribute::StateAttribute
StateAttribute()
osg::StateAttribute::STENCIL
@ STENCIL
Definition StateAttribute:152
osg::State
Definition State:80
osg::Stencil::_func
Function _func
Definition Stencil:171
osg::Stencil::setFunctionMask
void setFunctionMask(unsigned int mask)
Definition Stencil:110
osg::Stencil::Stencil
Stencil()
osg::Stencil::setStencilPassAndDepthFailOperation
void setStencilPassAndDepthFailOperation(Operation zfail)
Definition Stencil:147
osg::Stencil::Operation
Operation
Definition Stencil:115
osg::Stencil::INCR_WRAP
@ INCR_WRAP
Definition Stencil:122
osg::Stencil::DECR
@ DECR
Definition Stencil:120
osg::Stencil::ZERO
@ ZERO
Definition Stencil:117
osg::Stencil::INVERT
@ INVERT
Definition Stencil:121
osg::Stencil::KEEP
@ KEEP
Definition Stencil:116
osg::Stencil::INCR
@ INCR
Definition Stencil:119
osg::Stencil::DECR_WRAP
@ DECR_WRAP
Definition Stencil:123
osg::Stencil::REPLACE
@ REPLACE
Definition Stencil:118
osg::Stencil::META_StateAttribute
META_StateAttribute(osg, Stencil, STENCIL)
osg::Stencil::_zfail
Operation _zfail
Definition Stencil:176
osg::Stencil::Function
Function
Definition Stencil:86
osg::Stencil::GEQUAL
@ GEQUAL
Definition Stencil:93
osg::Stencil::EQUAL
@ EQUAL
Definition Stencil:89
osg::Stencil::LEQUAL
@ LEQUAL
Definition Stencil:90
osg::Stencil::GREATER
@ GREATER
Definition Stencil:91
osg::Stencil::NOTEQUAL
@ NOTEQUAL
Definition Stencil:92
osg::Stencil::LESS
@ LESS
Definition Stencil:88
osg::Stencil::NEVER
@ NEVER
Definition Stencil:87
osg::Stencil::ALWAYS
@ ALWAYS
Definition Stencil:94
osg::Stencil::setStencilFailOperation
void setStencilFailOperation(Operation sfail)
Definition Stencil:141
osg::Stencil::setFunction
void setFunction(Function func, int ref, unsigned int mask)
Definition Stencil:97
osg::Stencil::compare
virtual int compare(const StateAttribute &sa) const
Definition Stencil:61
osg::Stencil::setFunctionRef
void setFunctionRef(int ref)
Definition Stencil:107
osg::Stencil::_funcRef
int _funcRef
Definition Stencil:172
osg::Stencil::apply
virtual void apply(State &state) const
osg::Stencil::getStencilPassAndDepthPassOperation
Operation getStencilPassAndDepthPassOperation() const
Definition Stencil:156
osg::Stencil::_sfail
Operation _sfail
Definition Stencil:175
osg::Stencil::_writeMask
unsigned int _writeMask
Definition Stencil:179
osg::Stencil::setFunction
void setFunction(Function func)
Definition Stencil:104
osg::Stencil::getStencilPassAndDepthFailOperation
Operation getStencilPassAndDepthFailOperation() const
Definition Stencil:150
osg::Stencil::~Stencil
virtual ~Stencil()
osg::Stencil::setWriteMask
void setWriteMask(unsigned int mask)
Definition Stencil:159
osg::Stencil::getModeUsage
virtual bool getModeUsage(StateAttribute::ModeUsage &usage) const
Definition Stencil:79
osg::Stencil::getFunctionMask
unsigned int getFunctionMask() const
Definition Stencil:111
osg::Stencil::getFunctionRef
int getFunctionRef() const
Definition Stencil:108
osg::Stencil::_funcMask
unsigned int _funcMask
Definition Stencil:173
osg::Stencil::getStencilFailOperation
Operation getStencilFailOperation() const
Definition Stencil:144
osg::Stencil::getWriteMask
unsigned int getWriteMask() const
Definition Stencil:161
osg::Stencil::setStencilPassAndDepthPassOperation
void setStencilPassAndDepthPassOperation(Operation zpass)
Definition Stencil:153
osg::Stencil::setOperation
void setOperation(Operation sfail, Operation zfail, Operation zpass)
Definition Stencil:133
osg::Stencil::_zpass
Operation _zpass
Definition Stencil:177
osg::Stencil::getFunction
Function getFunction() const
Definition Stencil:105
osg::Stencil::Stencil
Stencil(const Stencil &stencil, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
Definition Stencil:47
osg
Definition AlphaFunc:19
OSG_EXPORT
#define OSG_EXPORT
Definition osg/Export:39
osg::StateAttribute::ModeUsage
Definition StateAttribute:308
osg::StateAttribute::ModeUsage::usesMode
virtual void usesMode(GLMode mode)=0