openscenegraph
AlphaFunc
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
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.
7 *
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.
12*/
13
14#ifndef OSG_ALPHAFUNC
15#define OSG_ALPHAFUNC 1
16
17#include <osg/StateAttribute>
18
19namespace osg {
20
21/** Encapsulates OpenGL glAlphaFunc.
22*/
23class OSG_EXPORT AlphaFunc : public StateAttribute
24{
25 public :
26
27 enum ComparisonFunction {
28 NEVER = GL_NEVER,
29 LESS = GL_LESS,
30 EQUAL = GL_EQUAL,
31 LEQUAL = GL_LEQUAL,
32 GREATER = GL_GREATER,
33 NOTEQUAL = GL_NOTEQUAL,
34 GEQUAL = GL_GEQUAL,
35 ALWAYS = GL_ALWAYS
36 };
37
38
39 AlphaFunc();
40
41 AlphaFunc(ComparisonFunction func,float ref):
42 _comparisonFunc(func),
43 _referenceValue(ref) {}
44
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) {}
50
51 META_StateAttribute(osg, AlphaFunc,ALPHAFUNC);
52
53 /** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
54 virtual int compare(const StateAttribute& sa) const
55 {
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)
59
60 // Compare each parameter in turn against the rhs.
61 COMPARE_StateAttribute_Parameter(_comparisonFunc)
62 COMPARE_StateAttribute_Parameter(_referenceValue)
63
64 return 0; // Passed all the above comparison macros, so must be equal.
65 }
66
67 virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const
68 {
69 usage.usesMode(GL_ALPHA_TEST);
70 return true;
71 }
72
73 inline void setFunction(ComparisonFunction func,float ref)
74 {
75 _comparisonFunc = func;
76 _referenceValue = ref;
77 }
78
79 inline void setFunction(ComparisonFunction func) { _comparisonFunc=func; }
80 inline ComparisonFunction getFunction() const { return _comparisonFunc; }
81
82 inline void setReferenceValue(float value) { _referenceValue=value; }
83 inline float getReferenceValue() const { return _referenceValue; }
84
85 virtual void apply(State& state) const;
86
87 protected:
88
89 virtual ~AlphaFunc();
90
91 ComparisonFunction _comparisonFunc;
92 float _referenceValue;
93
94};
95
96}
97
98#endif