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.
17#include <osg/StateAttribute>
21/** Encapsulate OpenGL glDepthFunc/Mask/Range functions.
23class OSG_EXPORT Depth : public StateAttribute
35 NOTEQUAL = GL_NOTEQUAL,
41 Depth(Function func=LESS,double zNear=0.0, double zFar=1.0,bool writeMask=true);
43 /** Copy constructor using CopyOp to manage deep vs shallow copy.*/
44 Depth(const Depth& dp,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
45 StateAttribute(dp,copyop),
49 _depthWriteMask(dp._depthWriteMask) {}
52 META_StateAttribute(osg, Depth, DEPTH);
54 /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
55 virtual int compare(const StateAttribute& sa) const
57 // check the types are equal and then create the rhs variable
58 // used by the COMPARE_StateAttribute_Parameter macros below.
59 COMPARE_StateAttribute_Types(Depth,sa)
61 // compare each parameter in turn against the rhs.
62 COMPARE_StateAttribute_Parameter(_func)
63 COMPARE_StateAttribute_Parameter(_depthWriteMask)
64 COMPARE_StateAttribute_Parameter(_zNear)
65 COMPARE_StateAttribute_Parameter(_zFar)
67 return 0; // passed all the above comparison macros, must be equal.
70 virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const
72 usage.usesMode(GL_DEPTH_TEST);
76 inline void setFunction(Function func) { _func = func; }
77 inline Function getFunction() const { return _func; }
80 inline void setRange(double zNear, double zFar)
86 inline void setZNear(double zNear) { _zNear=zNear; }
87 inline double getZNear() const { return _zNear; }
89 inline void setZFar(double zFar) { _zFar=zFar; }
90 inline double getZFar() const { return _zFar; }
92 inline void setWriteMask(bool mask) { _depthWriteMask = mask; }
93 inline bool getWriteMask() const { return _depthWriteMask; }
96 virtual void apply(State& state) const;
107 bool _depthWriteMask;