OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AlphaFunc.h
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 
19 namespace osg {
20 
24 {
25  public :
26 
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 
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 
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.
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 
93 
94 };
95 
96 }
97 
98 #endif
float getReferenceValue() const
Definition: AlphaFunc.h:83
AlphaFunc(const AlphaFunc &af, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
Definition: AlphaFunc.h:46
#define OSG_EXPORT
Definition: Export.h:43
void setFunction(ComparisonFunction func)
Definition: AlphaFunc.h:79
#define COMPARE_StateAttribute_Types(TYPE, rhs_attribute)
virtual bool getModeUsage(StateAttribute::ModeUsage &usage) const
Definition: AlphaFunc.h:67
virtual void usesMode(GLMode mode)=0
virtual int compare(const StateAttribute &sa) const
Definition: AlphaFunc.h:54
void setReferenceValue(float value)
Definition: AlphaFunc.h:82
void setFunction(ComparisonFunction func, float ref)
Definition: AlphaFunc.h:73
float _referenceValue
Definition: AlphaFunc.h:92
#define META_StateAttribute(library, name, type)
ComparisonFunction _comparisonFunc
Definition: AlphaFunc.h:91
Definition: AlphaFunc.h:19
AlphaFunc(ComparisonFunction func, float ref)
Definition: AlphaFunc.h:41
#define COMPARE_StateAttribute_Parameter(parameter)
ComparisonFunction getFunction() const
Definition: AlphaFunc.h:80
#define GL_ALPHA_TEST
Definition: GLDefines.h:604