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.
15#define OSG_ALPHAFUNC 1
17#include <osg/StateAttribute>
21/** Encapsulates OpenGL glAlphaFunc.
23class OSG_EXPORT AlphaFunc : public StateAttribute
27 enum ComparisonFunction {
33 NOTEQUAL = GL_NOTEQUAL,
41 AlphaFunc(ComparisonFunction func,float ref):
42 _comparisonFunc(func),
43 _referenceValue(ref) {}
45 /** Copy constructor using CopyOp to manage deep vs shallow copy. */
46 AlphaFunc(const AlphaFunc& af,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
47 StateAttribute(af,copyop),
48 _comparisonFunc(af._comparisonFunc),
49 _referenceValue(af._referenceValue) {}
51 META_StateAttribute(osg, AlphaFunc,ALPHAFUNC);
53 /** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
54 virtual int compare(const StateAttribute& sa) const
56 // Check for equal types, then create the rhs variable
57 // used by the COMPARE_StateAttribute_Parameter macros below.
58 COMPARE_StateAttribute_Types(AlphaFunc,sa)
60 // Compare each parameter in turn against the rhs.
61 COMPARE_StateAttribute_Parameter(_comparisonFunc)
62 COMPARE_StateAttribute_Parameter(_referenceValue)
64 return 0; // Passed all the above comparison macros, so must be equal.
67 virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const
69 usage.usesMode(GL_ALPHA_TEST);
73 inline void setFunction(ComparisonFunction func,float ref)
75 _comparisonFunc = func;
76 _referenceValue = ref;
79 inline void setFunction(ComparisonFunction func) { _comparisonFunc=func; }
80 inline ComparisonFunction getFunction() const { return _comparisonFunc; }
82 inline void setReferenceValue(float value) { _referenceValue=value; }
83 inline float getReferenceValue() const { return _referenceValue; }
85 virtual void apply(State& state) const;
91 ComparisonFunction _comparisonFunc;
92 float _referenceValue;