OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BlendFunc.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_BLENDFUNC
15 #define OSG_BLENDFUNC 1
16 
17 #include <osg/StateAttribute>
18 
19 #ifndef GL_VERSION_1_2
20 #define GL_CONSTANT_COLOR 0x8001
21 #define GL_ONE_MINUS_CONSTANT_COLOR 0x8002
22 #define GL_CONSTANT_ALPHA 0x8003
23 #define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004
24 #define GL_BLEND_COLOR 0x8005
25 #endif
26 
27 #ifndef GL_VERSION_1_4
28 #define GL_BLEND_DST_RGB 0x80C8
29 #define GL_BLEND_SRC_RGB 0x80C9
30 #define GL_BLEND_DST_ALPHA 0x80CA
31 #define GL_BLEND_SRC_ALPHA 0x80CB
32 #endif
33 
34 
35 namespace osg {
36 
66 {
67  public :
68 
69  BlendFunc();
70 
71  BlendFunc(GLenum source, GLenum destination);
72  BlendFunc(GLenum source, GLenum destination, GLenum source_alpha, GLenum destination_alpha);
73 
75  BlendFunc(const BlendFunc& trans,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
76  StateAttribute(trans,copyop),
77  _source_factor(trans._source_factor),
78  _destination_factor(trans._destination_factor),
79  _source_factor_alpha(trans._source_factor_alpha),
80  _destination_factor_alpha(trans._destination_factor_alpha) {}
81 
82  META_StateAttribute(osg, BlendFunc,BLENDFUNC);
83 
85  virtual int compare(const StateAttribute& sa) const
86  {
87  // Check for equal types, then create the rhs variable
88  // used by the COMPARE_StateAttribute_Parameter macros below.
90 
91  // Compare each parameter in turn against the rhs.
92  COMPARE_StateAttribute_Parameter(_source_factor)
93  COMPARE_StateAttribute_Parameter(_destination_factor)
94  COMPARE_StateAttribute_Parameter(_source_factor_alpha)
95  COMPARE_StateAttribute_Parameter(_destination_factor_alpha)
96 
97  return 0; // Passed all the above comparison macros, so must be equal.
98  }
99 
100  virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const
101  {
102  usage.usesMode(GL_BLEND);
103  return true;
104  }
105 
107  DST_ALPHA = GL_DST_ALPHA,
108  DST_COLOR = GL_DST_COLOR,
109  ONE = GL_ONE,
110  ONE_MINUS_DST_ALPHA = GL_ONE_MINUS_DST_ALPHA,
111  ONE_MINUS_DST_COLOR = GL_ONE_MINUS_DST_COLOR,
112  ONE_MINUS_SRC_ALPHA = GL_ONE_MINUS_SRC_ALPHA,
113  ONE_MINUS_SRC_COLOR = GL_ONE_MINUS_SRC_COLOR,
114  SRC_ALPHA = GL_SRC_ALPHA,
115  SRC_ALPHA_SATURATE = GL_SRC_ALPHA_SATURATE,
116  SRC_COLOR = GL_SRC_COLOR,
117  CONSTANT_COLOR = GL_CONSTANT_COLOR,
118  ONE_MINUS_CONSTANT_COLOR = GL_ONE_MINUS_CONSTANT_COLOR,
119  CONSTANT_ALPHA = GL_CONSTANT_ALPHA,
120  ONE_MINUS_CONSTANT_ALPHA = GL_ONE_MINUS_CONSTANT_ALPHA,
121  ZERO = GL_ZERO
122  };
123 
124  inline void setFunction( GLenum source, GLenum destination )
125  {
126  _source_factor = source;
127  _destination_factor = destination;
128  _source_factor_alpha = source;
129  _destination_factor_alpha = destination;
130  }
131 
132  inline void setFunction( GLenum source_rgb, GLenum destination_rgb, GLenum source_alpha, GLenum destination_alpha )
133  {
134  _source_factor = source_rgb;
135  _destination_factor = destination_rgb;
136  _source_factor_alpha = source_alpha;
137  _destination_factor_alpha = destination_alpha;
138  }
139 
140  void setSource(GLenum source) { _source_factor = _source_factor_alpha = source; }
141  inline GLenum getSource() const { return _source_factor; }
142 
143  void setSourceRGB(GLenum source) { _source_factor = source; }
144  inline GLenum getSourceRGB() const { return _source_factor; }
145 
146  void setSourceAlpha(GLenum source) { _source_factor_alpha = source; }
147  inline GLenum getSourceAlpha() const { return _source_factor_alpha; }
148 
149  void setDestination(GLenum destination) { _destination_factor = _destination_factor_alpha = destination; }
150  inline GLenum getDestination() const { return _destination_factor; }
151 
152  void setDestinationRGB(GLenum destination) { _destination_factor = destination; }
153  inline GLenum getDestinationRGB() const { return _destination_factor; }
154 
155  void setDestinationAlpha(GLenum destination) { _destination_factor_alpha = destination; }
156  inline GLenum getDestinationAlpha() const { return _destination_factor_alpha; }
157 
158  virtual void apply(State& state) const;
159 
160  protected :
161 
162  virtual ~BlendFunc();
163 
168 };
169 
170 }
171 
172 #endif
#define OSG_EXPORT
Definition: Export.h:43
void setSourceAlpha(GLenum source)
Definition: BlendFunc.h:146
#define GL_ONE_MINUS_CONSTANT_COLOR
Definition: BlendFunc.h:21
#define COMPARE_StateAttribute_Types(TYPE, rhs_attribute)
#define GL_CONSTANT_COLOR
Definition: BlendFunc.h:20
virtual bool getModeUsage(StateAttribute::ModeUsage &usage) const
Definition: BlendFunc.h:100
#define GL_ONE_MINUS_CONSTANT_ALPHA
Definition: BlendFunc.h:23
void setSource(GLenum source)
Definition: BlendFunc.h:140
virtual void usesMode(GLMode mode)=0
#define GL_CONSTANT_ALPHA
Definition: BlendFunc.h:22
void setDestinationAlpha(GLenum destination)
Definition: BlendFunc.h:155
void setFunction(GLenum source_rgb, GLenum destination_rgb, GLenum source_alpha, GLenum destination_alpha)
Definition: BlendFunc.h:132
GLenum getSource() const
Definition: BlendFunc.h:141
void setDestinationRGB(GLenum destination)
Definition: BlendFunc.h:152
GLenum getSourceRGB() const
Definition: BlendFunc.h:144
GLenum _destination_factor_alpha
Definition: BlendFunc.h:167
GLenum _source_factor_alpha
Definition: BlendFunc.h:166
void setDestination(GLenum destination)
Definition: BlendFunc.h:149
GLenum _destination_factor
Definition: BlendFunc.h:165
GLenum _source_factor
Definition: BlendFunc.h:164
BlendFunc(const BlendFunc &trans, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
Definition: BlendFunc.h:75
virtual int compare(const StateAttribute &sa) const
Definition: BlendFunc.h:85
#define META_StateAttribute(library, name, type)
void setSourceRGB(GLenum source)
Definition: BlendFunc.h:143
void setFunction(GLenum source, GLenum destination)
Definition: BlendFunc.h:124
GLenum getDestinationAlpha() const
Definition: BlendFunc.h:156
Definition: AlphaFunc.h:19
#define COMPARE_StateAttribute_Parameter(parameter)
GLenum getDestination() const
Definition: BlendFunc.h:150
GLenum getDestinationRGB() const
Definition: BlendFunc.h:153
GLenum getSourceAlpha() const
Definition: BlendFunc.h:147