root/OpenSceneGraph/trunk/include/osg/AlphaFunc @ 13041

Revision 13041, 3.1 kB (checked in by robert, 3 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
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#ifndef GL_ALPHA_TEST
20    #define GL_ALPHA_TEST 0x0BC0
21#endif
22
23namespace osg {
24
25/** Encapsulates OpenGL glAlphaFunc.
26*/
27class OSG_EXPORT AlphaFunc : public StateAttribute
28{
29    public :
30
31        enum ComparisonFunction {
32            NEVER = GL_NEVER,
33            LESS = GL_LESS,
34            EQUAL = GL_EQUAL,
35            LEQUAL = GL_LEQUAL,
36            GREATER = GL_GREATER,
37            NOTEQUAL = GL_NOTEQUAL,
38            GEQUAL = GL_GEQUAL,
39            ALWAYS = GL_ALWAYS
40        };
41
42
43        AlphaFunc();
44
45        AlphaFunc(ComparisonFunction func,float ref):
46            _comparisonFunc(func),
47            _referenceValue(ref) {}
48
49        /** Copy constructor using CopyOp to manage deep vs shallow copy. */
50        AlphaFunc(const AlphaFunc& af,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
51            StateAttribute(af,copyop),
52            _comparisonFunc(af._comparisonFunc),
53            _referenceValue(af._referenceValue) {}
54
55        META_StateAttribute(osg, AlphaFunc,ALPHAFUNC);
56
57        /** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
58        virtual int compare(const StateAttribute& sa) const
59        {
60            // Check for equal types, then create the rhs variable
61            // used by the COMPARE_StateAttribute_Parameter macros below.
62            COMPARE_StateAttribute_Types(AlphaFunc,sa)
63
64            // Compare each parameter in turn against the rhs.
65            COMPARE_StateAttribute_Parameter(_comparisonFunc)
66            COMPARE_StateAttribute_Parameter(_referenceValue)
67
68            return 0; // Passed all the above comparison macros, so must be equal.
69        }
70
71        virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const
72        {
73            usage.usesMode(GL_ALPHA_TEST);
74            return true;
75        }
76
77        inline void setFunction(ComparisonFunction func,float ref)
78        {
79            _comparisonFunc = func;
80            _referenceValue = ref;
81        }
82
83        inline void setFunction(ComparisonFunction func) { _comparisonFunc=func; }
84        inline ComparisonFunction getFunction() const { return _comparisonFunc; }
85
86        inline void setReferenceValue(float value) { _referenceValue=value; }
87        inline float getReferenceValue() const { return _referenceValue; }
88
89        virtual void apply(State& state) const;
90
91    protected:
92
93        virtual ~AlphaFunc();
94
95        ComparisonFunction _comparisonFunc;
96        float _referenceValue;
97
98};
99
100}
101
102#endif
Note: See TracBrowser for help on using the browser.