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 OSG_STENCILTWOSIDED
15#define OSG_STENCILTWOSIDED 1
21#ifndef GL_STENCIL_TEST_TWO_SIDE
22#define GL_STENCIL_TEST_TWO_SIDE 0x8910
25/** Provides OpenGL two sided stencil functionality, also known as separate stencil.
26 * It enables to specify different stencil function for front and back facing polygons.
27 * Two sided stenciling is used usually to eliminate the need of two rendering passes
28 * when using standard stenciling functions. See also \sa osg::Stencil.
30 * Two sided stenciling is available since OpenGL 2.0. It is also supported by
31 * EXT_stencil_two_side extension especially on Nvidia cards.
32 * Another extension introduced by ATI is ATI_separate_stencil. However, ATI's extension
33 * is limited to have reference and mask value the same for both faces.
34 * ATI's extension is currently not supported by the current implementation.
36 * osg::StencilTwoSided does nothing if OpenGL 2.0 or EXT_stencil_two_side are not available.
38class OSG_EXPORT StencilTwoSided : public StateAttribute
45 /** Copy constructor using CopyOp to manage deep vs shallow copy.*/
46 StencilTwoSided(const StencilTwoSided& stencil,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
48 META_StateAttribute(osg, StencilTwoSided, STENCIL);
50 /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
51 virtual int compare(const StateAttribute& sa) const;
53 virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const
55 usage.usesMode(GL_STENCIL_TEST);
72 NOTEQUAL = GL_NOTEQUAL,
77 inline void setFunction(Face face, Function func,int ref,unsigned int mask)
81 _funcMask[face] = mask;
84 inline void setFunction(Face face, Function func) { _func[face] = func; }
85 inline Function getFunction(Face face) const { return _func[face]; }
87 inline void setFunctionRef(Face face, int ref) { _funcRef[face]=ref; }
88 inline int getFunctionRef(Face face) const { return _funcRef[face]; }
90 inline void setFunctionMask(Face face, unsigned int mask) { _funcMask[face]=mask; }
91 inline unsigned int getFunctionMask(Face face) const { return _funcMask[face]; }
102 INCR_WRAP = GL_INCR_WRAP,
103 DECR_WRAP = GL_DECR_WRAP
106 /** set the operations to apply when the various stencil and depth
107 * tests fail or pass. First parameter is to control the operation
108 * when the stencil test fails. The second parameter is to control the
109 * operation when the stencil test passes, but depth test fails. The
110 * third parameter controls the operation when both the stencil test
111 * and depth pass. Ordering of parameter is the same as if using
113 inline void setOperation(Face face, Operation sfail, Operation zfail, Operation zpass)
115 _sfail[face] = sfail;
116 _zfail[face] = zfail;
117 _zpass[face] = zpass;
120 /** set the operation when the stencil test fails.*/
121 inline void setStencilFailOperation(Face face, Operation sfail) { _sfail[face] = sfail; }
123 /** get the operation when the stencil test fails.*/
124 inline Operation getStencilFailOperation(Face face) const { return _sfail[face]; }
126 /** set the operation when the stencil test passes but the depth test fails.*/
127 inline void setStencilPassAndDepthFailOperation(Face face, Operation zfail) { _zfail[face]=zfail; }
129 /** get the operation when the stencil test passes but the depth test fails.*/
130 inline Operation getStencilPassAndDepthFailOperation(Face face) const { return _zfail[face]; }
132 /** set the operation when both the stencil test and the depth test pass.*/
133 inline void setStencilPassAndDepthPassOperation(Face face, Operation zpass) { _zpass[face]=zpass; }
135 /** get the operation when both the stencil test and the depth test pass.*/
136 inline Operation getStencilPassAndDepthPassOperation(Face face) const { return _zpass[face]; }
139 inline void setWriteMask(Face face, unsigned int mask) { _writeMask[face] = mask; }
141 inline unsigned int getWriteMask(Face face) const { return _writeMask[face]; }
144 virtual void apply(State& state) const;
148 virtual ~StencilTwoSided();
152 unsigned int _funcMask[2];
158 unsigned int _writeMask[2];