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

Revision 13041, 6.2 kB (checked in by robert, 2 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_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        /** Encapsulates queries of extension availability, obtains extension
101          * function pointers, and provides convenience wrappers for
102          * calling extension functions. */
103        class OSG_EXPORT Extensions : public osg::Referenced
104        {
105            public:
106                Extensions(unsigned int contextID);
107
108                Extensions(const Extensions& rhs);
109
110                void lowestCommonDenominator(const Extensions& rhs);
111
112                void setupGLExtensions(unsigned int contextID);
113
114                bool isBlendEquationSupported() const { return _isBlendEquationSupported; }
115                bool isBlendEquationSeparateSupported() const { return _isBlendEquationSeparateSupported; }
116                bool isSGIXMinMaxSupported() const { return _isSGIXMinMaxSupported; }
117                bool isLogicOpSupported() const { return _isLogicOpSupported; }
118
119                void glBlendEquation(GLenum mode) const;
120                void glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha) const;
121
122            protected:
123
124                ~Extensions() {}
125
126                typedef void (GL_APIENTRY * GLBlendEquationProc)(GLenum mode);
127                typedef void (GL_APIENTRY * GLBlendEquationSeparateProc)(GLenum modeRGB, GLenum modeAlpha);
128
129                bool                _isBlendEquationSupported;
130                bool                _isBlendEquationSeparateSupported;
131                bool                _isSGIXMinMaxSupported;
132                bool                _isLogicOpSupported;
133
134                GLBlendEquationProc _glBlendEquation;
135                GLBlendEquationSeparateProc _glBlendEquationSeparate;
136        };
137
138        /** Returns the Extensions object for the given context.
139          * If createIfNotInitalized is true and the Extensions object doesn't
140          * exist, getExtensions() creates it on the given context.
141          * Returns NULL if createIfNotInitalized is false and the Extensions
142          * object doesn't exist. */
143        static Extensions* getExtensions(unsigned int contextID,bool createIfNotInitalized);
144
145        /** setExtensions() allows users to override the extensions across graphics contexts.
146          * Typically used when you have different extensions supported across graphics pipes,
147          * but need to ensure that they all use the same low common denominator extensions. */
148        static void setExtensions(unsigned int contextID,Extensions* extensions);
149
150
151    protected :
152
153        virtual ~BlendEquation();
154
155
156        Equation _equationRGB, _equationAlpha;
157};
158
159}
160
161#endif
Note: See TracBrowser for help on using the browser.