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_BLENDEQUATION
15#define OSG_BLENDEQUATION 1
16
17#include <osg/StateAttribute>
18
19#ifndef GL_VERSION_1_2
20/* Logic Ops */
21#define GL_MIN                                  0x8007
22#define GL_MAX                                  0x8008
23#define GL_FUNC_ADD                             0x8006
24#define GL_FUNC_SUBTRACT                        0x800A
25#define GL_FUNC_REVERSE_SUBTRACT                0x800B
26#endif
27
28#ifndef GL_LOGIC_OP
29#define GL_LOGIC_OP                             0x0BF1
30#endif
31
32#ifndef GL_ALPHA_MIN_SGIX
33#define GL_ALPHA_MIN_SGIX                       0x8320
34#define GL_ALPHA_MAX_SGIX                       0x8321
35#endif
36
37namespace osg {
38
39/** Encapsulates OpenGL BlendEquation state. */
40class OSG_EXPORT BlendEquation : public StateAttribute
41{
42    public :
43
44        enum Equation {
45            RGBA_MIN                        = GL_MIN,
46            RGBA_MAX                        = GL_MAX,
47            ALPHA_MIN                       = GL_ALPHA_MIN_SGIX,
48            ALPHA_MAX                       = GL_ALPHA_MAX_SGIX,
49            LOGIC_OP                        = GL_LOGIC_OP,
50            FUNC_ADD                        = GL_FUNC_ADD,
51            FUNC_SUBTRACT                   = GL_FUNC_SUBTRACT,
52            FUNC_REVERSE_SUBTRACT           = GL_FUNC_REVERSE_SUBTRACT
53        };
54
55        BlendEquation();
56
57        BlendEquation(Equation equation);
58
59        BlendEquation(Equation equationRGB, Equation equationAlpha);
60
61        /** Copy constructor using CopyOp to manage deep vs shallow copy. */
62        BlendEquation(const BlendEquation& trans,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
63            StateAttribute(trans,copyop),
64            _equationRGB(trans._equationRGB),
65            _equationAlpha(trans._equationAlpha){}
66
67        META_StateAttribute(osg, BlendEquation,BLENDEQUATION);
68
69        /** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
70        virtual int compare(const StateAttribute& sa) const
71        {
72            // Check for equal types, then create the rhs variable
73            // used by the COMPARE_StateAttribute_Parameter macros below.
74            COMPARE_StateAttribute_Types(BlendEquation,sa)
75
76            // Compare each parameter in turn against the rhs.
77            COMPARE_StateAttribute_Parameter(_equationRGB)
78            COMPARE_StateAttribute_Parameter(_equationAlpha)
79
80            return 0; // Passed all the above comparison macros, so must be equal.
81        }
82
83        virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const
84        {
85            usage.usesMode(GL_BLEND);
86            return true;
87        }
88
89
90        inline void setEquation(Equation equation) { _equationRGB = _equationAlpha = equation; }
91        inline Equation getEquation() const { return _equationRGB; }
92
93        inline void setEquationRGB(Equation equation) { _equationRGB = equation; }
94        inline Equation getEquationRGB() const { return _equationRGB; }
95
96        inline void setEquationAlpha(Equation equation) { _equationAlpha = equation; }
97        inline Equation getEquationAlpha() const { return _equationAlpha; }
98
99        virtual void apply(State& state) const;
100
101protected :
102
103        virtual ~BlendEquation();
104
105
106        Equation _equationRGB, _equationAlpha;
107};
108
109}
110
111#endif
112