OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TexEnvCombine.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_TEXENVCOMBINE
15 #define OSG_TEXENVCOMBINE 1
16 
17 #include <osg/TexEnv>
18 #include <osg/Vec3>
19 #include <osg/Vec4>
20 
21 // If not defined by gl.h use the definition found in:
22 // http://oss.sgi.com/projects/ogl-sample/registry/ARB/texture_env_combine.txt
23 #ifndef GL_ARB_texture_env_combine
24 #define GL_COMBINE_ARB 0x8570
25 #define GL_COMBINE_RGB_ARB 0x8571
26 #define GL_COMBINE_ALPHA_ARB 0x8572
27 #define GL_SOURCE0_RGB_ARB 0x8580
28 #define GL_SOURCE1_RGB_ARB 0x8581
29 #define GL_SOURCE2_RGB_ARB 0x8582
30 #define GL_SOURCE0_ALPHA_ARB 0x8588
31 #define GL_SOURCE1_ALPHA_ARB 0x8589
32 #define GL_SOURCE2_ALPHA_ARB 0x858A
33 #define GL_OPERAND0_RGB_ARB 0x8590
34 #define GL_OPERAND1_RGB_ARB 0x8591
35 #define GL_OPERAND2_RGB_ARB 0x8592
36 #define GL_OPERAND0_ALPHA_ARB 0x8598
37 #define GL_OPERAND1_ALPHA_ARB 0x8599
38 #define GL_OPERAND2_ALPHA_ARB 0x859A
39 #define GL_RGB_SCALE_ARB 0x8573
40 #define GL_ADD_SIGNED_ARB 0x8574
41 #define GL_INTERPOLATE_ARB 0x8575
42 #define GL_SUBTRACT_ARB 0x84E7
43 #define GL_CONSTANT_ARB 0x8576
44 #define GL_PRIMARY_COLOR_ARB 0x8577
45 #define GL_PREVIOUS_ARB 0x8578
46 #endif
47 
48 #ifndef GL_ARB_texture_env_dot3
49 #define GL_DOT3_RGB_ARB 0x86AE
50 #define GL_DOT3_RGBA_ARB 0x86AF
51 #endif
52 
53 #ifndef GL_TEXTURE0
54 #define GL_TEXTURE0 0x84C0
55 #endif
56 
57 namespace osg {
58 
62 {
63  public :
64 
65  TexEnvCombine();
66 
69  StateAttribute(texenv,copyop),
70  _needsTexEnvCrossbar(texenv._needsTexEnvCrossbar),
71  _combine_RGB(texenv._combine_RGB),
72  _combine_Alpha(texenv._combine_Alpha),
73  _source0_RGB(texenv._source0_RGB),
74  _source1_RGB(texenv._source1_RGB),
75  _source2_RGB(texenv._source2_RGB),
76  _source0_Alpha(texenv._source0_Alpha),
77  _source1_Alpha(texenv._source1_Alpha),
78  _source2_Alpha(texenv._source2_Alpha),
79  _operand0_RGB(texenv._operand0_RGB),
80  _operand1_RGB(texenv._operand1_RGB),
81  _operand2_RGB(texenv._operand2_RGB),
82  _operand0_Alpha(texenv._operand0_Alpha),
83  _operand1_Alpha(texenv._operand1_Alpha),
84  _operand2_Alpha(texenv._operand2_Alpha),
85  _scale_RGB(texenv._scale_RGB),
86  _scale_Alpha(texenv._scale_Alpha),
87  _constantColor(texenv._constantColor) {}
88 
89 
91 
92 
93  virtual bool isTextureAttribute() const { return true; }
94 
96  virtual int compare(const StateAttribute& sa) const
97  {
98  // Check for equal types, then create the rhs variable
99  // used by the COMPARE_StateAttribute_parameter macros below.
101 
102  // Compare each parameter in turn against the rhs.
103  COMPARE_StateAttribute_Parameter(_needsTexEnvCrossbar)
105  COMPARE_StateAttribute_Parameter(_combine_Alpha)
109  COMPARE_StateAttribute_Parameter(_source0_Alpha)
110  COMPARE_StateAttribute_Parameter(_source1_Alpha)
111  COMPARE_StateAttribute_Parameter(_source2_Alpha)
112  COMPARE_StateAttribute_Parameter(_operand0_RGB)
113  COMPARE_StateAttribute_Parameter(_operand1_RGB)
114  COMPARE_StateAttribute_Parameter(_operand2_RGB)
115  COMPARE_StateAttribute_Parameter(_operand0_Alpha)
116  COMPARE_StateAttribute_Parameter(_operand1_Alpha)
117  COMPARE_StateAttribute_Parameter(_operand2_Alpha)
120  COMPARE_StateAttribute_Parameter(_constantColor)
121 
122  return 0; // Passed all the above comparison macros, so must be equal.
123  }
124 
125 
127  {
128  REPLACE = GL_REPLACE,
129  MODULATE = GL_MODULATE,
130  ADD = GL_ADD,
131  ADD_SIGNED = GL_ADD_SIGNED_ARB,
132  INTERPOLATE = GL_INTERPOLATE_ARB,
133  SUBTRACT = GL_SUBTRACT_ARB,
134  DOT3_RGB = GL_DOT3_RGB_ARB,
135  DOT3_RGBA = GL_DOT3_RGBA_ARB
136  };
137 
138  void setCombine_RGB(GLint cm);
139  void setCombine_Alpha(GLint cm);
140 
141  GLint getCombine_RGB() const { return _combine_RGB; }
142  GLint getCombine_Alpha() const { return _combine_Alpha; }
143 
145  {
146  CONSTANT = GL_CONSTANT_ARB,
147  PRIMARY_COLOR = GL_PRIMARY_COLOR_ARB,
148  PREVIOUS = GL_PREVIOUS_ARB,
149  TEXTURE = GL_TEXTURE,
150  TEXTURE0 = GL_TEXTURE0,
151  TEXTURE1 = GL_TEXTURE0+1,
152  TEXTURE2 = GL_TEXTURE0+2,
153  TEXTURE3 = GL_TEXTURE0+3,
154  TEXTURE4 = GL_TEXTURE0+4,
155  TEXTURE5 = GL_TEXTURE0+5,
156  TEXTURE6 = GL_TEXTURE0+6,
157  TEXTURE7 = GL_TEXTURE0+7
158  };
159 
160  void setSource0_RGB(GLint sp);
161  void setSource1_RGB(GLint sp);
162  void setSource2_RGB(GLint sp);
163 
164  void setSource0_Alpha(GLint sp);
165  void setSource1_Alpha(GLint sp);
166  void setSource2_Alpha(GLint sp);
167 
168  GLint getSource0_RGB() const { return _source0_RGB; }
169  GLint getSource1_RGB() const { return _source1_RGB; }
170  GLint getSource2_RGB() const { return _source2_RGB; }
171 
172  GLint getSource0_Alpha() const { return _source0_Alpha; }
173  GLint getSource1_Alpha() const { return _source1_Alpha; }
174  GLint getSource2_Alpha() const { return _source2_Alpha; }
175 
177  {
178  SRC_COLOR = GL_SRC_COLOR,
179  ONE_MINUS_SRC_COLOR = GL_ONE_MINUS_SRC_COLOR,
180  SRC_ALPHA = GL_SRC_ALPHA,
181  ONE_MINUS_SRC_ALPHA = GL_ONE_MINUS_SRC_ALPHA
182  };
183 
184  void setOperand0_RGB(GLint op);
185  void setOperand1_RGB(GLint op);
186  void setOperand2_RGB(GLint op);
187 
188  void setOperand0_Alpha(GLint op);
189  void setOperand1_Alpha(GLint op);
190  void setOperand2_Alpha(GLint op);
191 
192  GLint getOperand0_RGB() const { return _operand0_RGB; }
193  GLint getOperand1_RGB() const { return _operand1_RGB; }
194  GLint getOperand2_RGB() const { return _operand2_RGB; }
195 
196  GLint getOperand0_Alpha() const { return _operand0_Alpha; }
197  GLint getOperand1_Alpha() const { return _operand1_Alpha; }
198  GLint getOperand2_Alpha() const { return _operand2_Alpha; }
199 
200 
201  void setScale_RGB(float scale);
202  void setScale_Alpha(float scale);
203 
204  float getScale_RGB() const { return _scale_RGB; }
205  float getScale_Alpha() const { return _scale_Alpha; }
206 
207  void setConstantColor( const Vec4& color ) { _constantColor = color; }
208  const Vec4& getConstantColor() const { return _constantColor; }
209 
212  void setConstantColorAsLightDirection(const Vec3& direction)
213  {
214  _constantColor.set((direction.x()+1.0f)*0.5f,(direction.y()+1.0f)*0.5f,(direction.z()+1.0f)*0.5f,1.0f);
215  }
216 
218  {
219  return Vec3(_constantColor.x()*2.0f-1.0f, _constantColor.y()*2.0f-1.0f, _constantColor.z()*2.0f-1.0f);
220  }
221 
222  virtual void apply(State& state) const;
223 
224  protected :
225 
226  virtual ~TexEnvCombine();
227 
228  inline bool needsTexEnvCombiner(GLint value) const
229  {
230  switch(value)
231  {
232  case(CONSTANT):
233  case(PRIMARY_COLOR):
234  case(PREVIOUS):
235  case(TEXTURE):
236  return false;
237  }
238  return true;
239  }
240 
242  {
243  _needsTexEnvCrossbar = (needsTexEnvCombiner(_source0_RGB) ||
244  needsTexEnvCombiner(_source1_RGB) ||
245  needsTexEnvCombiner(_source2_RGB) ||
246  needsTexEnvCombiner(_source0_Alpha) ||
247  needsTexEnvCombiner(_source1_Alpha) ||
248  needsTexEnvCombiner(_source2_Alpha));
249  }
250 
251 
252 
253 
254 
256 
259 
263 
267 
268 
272 
276 
277 
278  float _scale_RGB;
280 
282 
283 };
284 
285 }
286 
287 #endif
#define OSG_EXPORT
Definition: Export.h:43
void computeNeedForTexEnvCombiners()
GLint getOperand1_RGB() const
#define GL_SUBTRACT_ARB
Definition: TexEnvCombine.h:42
#define COMPARE_StateAttribute_Types(TYPE, rhs_attribute)
bool needsTexEnvCombiner(GLint value) const
value_type & x()
Definition: Vec3f.h:80
GLint getCombine_RGB() const
value_type & z()
Definition: Vec3f.h:82
GLint getSource1_RGB() const
float getScale_RGB() const
osg::Vec4 _constantColor
GLint getOperand1_Alpha() const
#define GL_TEXTURE0
Definition: TexEnvCombine.h:54
GLint getSource2_Alpha() const
virtual bool isTextureAttribute() const
Definition: TexEnvCombine.h:93
Vec3 getConstantColorAsLightDirection() const
const Vec4 & getConstantColor() const
#define GL_CONSTANT_ARB
Definition: TexEnvCombine.h:43
GLint getOperand2_RGB() const
#define GL_DOT3_RGBA_ARB
Definition: TexEnvCombine.h:50
#define GL_INTERPOLATE_ARB
Definition: TexEnvCombine.h:41
GLint getSource0_Alpha() const
Vec3f Vec3
Definition: Vec3.h:21
#define GL_MODULATE
Definition: TexEnv.h:24
GLint getOperand2_Alpha() const
GLint getOperand0_Alpha() const
#define GL_PRIMARY_COLOR_ARB
Definition: TexEnvCombine.h:44
void setConstantColor(const Vec4 &color)
GLint getSource0_RGB() const
value_type & y()
Definition: Vec3f.h:81
#define META_StateAttribute(library, name, type)
GLint getSource2_RGB() const
virtual int compare(const StateAttribute &sa) const
Definition: TexEnvCombine.h:96
#define GL_ADD_SIGNED_ARB
Definition: TexEnvCombine.h:40
GLint getOperand0_RGB() const
#define GL_ADD
Definition: TexEnv.h:23
Definition: AlphaFunc.h:19
#define COMPARE_StateAttribute_Parameter(parameter)
TexEnvCombine(const TexEnvCombine &texenv, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
Definition: TexEnvCombine.h:68
float getScale_Alpha() const
#define GL_PREVIOUS_ARB
Definition: TexEnvCombine.h:45
#define GL_DOT3_RGB_ARB
Definition: TexEnvCombine.h:49
GLint getSource1_Alpha() const
void setConstantColorAsLightDirection(const Vec3 &direction)
GLint getCombine_Alpha() const