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.
14#ifndef OSG_BLENDEQUATION
15#define OSG_BLENDEQUATION 1
17#include <osg/StateAttribute>
23#define GL_FUNC_ADD 0x8006
24#define GL_FUNC_SUBTRACT 0x800A
25#define GL_FUNC_REVERSE_SUBTRACT 0x800B
29#define GL_LOGIC_OP 0x0BF1
32#ifndef GL_ALPHA_MIN_SGIX
33#define GL_ALPHA_MIN_SGIX 0x8320
34#define GL_ALPHA_MAX_SGIX 0x8321
39/** Encapsulates OpenGL BlendEquation state. */
40class OSG_EXPORT BlendEquation : public StateAttribute
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
57 BlendEquation(Equation equation);
59 BlendEquation(Equation equationRGB, Equation equationAlpha);
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){}
67 META_StateAttribute(osg, BlendEquation,BLENDEQUATION);
69 /** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
70 virtual int compare(const StateAttribute& sa) const
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)
76 // Compare each parameter in turn against the rhs.
77 COMPARE_StateAttribute_Parameter(_equationRGB)
78 COMPARE_StateAttribute_Parameter(_equationAlpha)
80 return 0; // Passed all the above comparison macros, so must be equal.
83 virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const
85 usage.usesMode(GL_BLEND);
90 inline void setEquation(Equation equation) { _equationRGB = _equationAlpha = equation; }
91 inline Equation getEquation() const { return _equationRGB; }
93 inline void setEquationRGB(Equation equation) { _equationRGB = equation; }
94 inline Equation getEquationRGB() const { return _equationRGB; }
96 inline void setEquationAlpha(Equation equation) { _equationAlpha = equation; }
97 inline Equation getEquationAlpha() const { return _equationAlpha; }
99 virtual void apply(State& state) const;
103 virtual ~BlendEquation();
106 Equation _equationRGB, _equationAlpha;