TexEnvCombine
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_TEXENVCOMBINE
#define OSG_TEXENVCOMBINE 1
#include <osg/TexEnv>
#include <osg/Vec3>
#include <osg/Vec4>
// If not defined by gl.h use the definition found in:
// http://oss.sgi.com/projects/ogl-sample/registry/ARB/texture_env_combine.txt
#ifndef GL_ARB_texture_env_combine
#define GL_COMBINE_ARB 0x8570
#define GL_COMBINE_RGB_ARB 0x8571
#define GL_COMBINE_ALPHA_ARB 0x8572
#define GL_SOURCE0_RGB_ARB 0x8580
#define GL_SOURCE1_RGB_ARB 0x8581
#define GL_SOURCE2_RGB_ARB 0x8582
#define GL_SOURCE0_ALPHA_ARB 0x8588
#define GL_SOURCE1_ALPHA_ARB 0x8589
#define GL_SOURCE2_ALPHA_ARB 0x858A
#define GL_OPERAND0_RGB_ARB 0x8590
#define GL_OPERAND1_RGB_ARB 0x8591
#define GL_OPERAND2_RGB_ARB 0x8592
#define GL_OPERAND0_ALPHA_ARB 0x8598
#define GL_OPERAND1_ALPHA_ARB 0x8599
#define GL_OPERAND2_ALPHA_ARB 0x859A
#define GL_RGB_SCALE_ARB 0x8573
#define GL_ADD_SIGNED_ARB 0x8574
#define GL_INTERPOLATE_ARB 0x8575
#define GL_SUBTRACT_ARB 0x84E7
#define GL_CONSTANT_ARB 0x8576
#define GL_PRIMARY_COLOR_ARB 0x8577
#define GL_PREVIOUS_ARB 0x8578
#endif
#ifndef GL_ARB_texture_env_dot3
#define GL_DOT3_RGB_ARB 0x86AE
#define GL_DOT3_RGBA_ARB 0x86AF
#endif
#ifndef GL_TEXTURE0
#define GL_TEXTURE0 0x84C0
#endif
namespace osg {
class OSG_EXPORT TexEnvCombine : public StateAttribute
{
public :
TexEnvCombine();
TexEnvCombine(const TexEnvCombine& texenv,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
StateAttribute(texenv,copyop),
_needsTexEnvCrossbar(texenv._needsTexEnvCrossbar),
_combine_RGB(texenv._combine_RGB),
_combine_Alpha(texenv._combine_Alpha),
_source0_RGB(texenv._source0_RGB),
_source1_RGB(texenv._source1_RGB),
_source2_RGB(texenv._source2_RGB),
_source0_Alpha(texenv._source0_Alpha),
_source1_Alpha(texenv._source1_Alpha),
_source2_Alpha(texenv._source2_Alpha),
_operand0_RGB(texenv._operand0_RGB),
_operand1_RGB(texenv._operand1_RGB),
_operand2_RGB(texenv._operand2_RGB),
_operand0_Alpha(texenv._operand0_Alpha),
_operand1_Alpha(texenv._operand1_Alpha),
_operand2_Alpha(texenv._operand2_Alpha),
_scale_RGB(texenv._scale_RGB),
_scale_Alpha(texenv._scale_Alpha),
_constantColor(texenv._constantColor) {}
META_StateAttribute(osg, TexEnvCombine, TEXENV);
virtual bool isTextureAttribute() const { return true; }
virtual int compare(const StateAttribute& sa) const
{
// Check for equal types, then create the rhs variable
// used by the COMPARE_StateAttribute_parameter macros below.
COMPARE_StateAttribute_Types(TexEnvCombine,sa)
// Compare each parameter in turn against the rhs.
COMPARE_StateAttribute_Parameter(_needsTexEnvCrossbar)
COMPARE_StateAttribute_Parameter(_combine_RGB)
COMPARE_StateAttribute_Parameter(_combine_Alpha)
COMPARE_StateAttribute_Parameter(_source0_RGB)
COMPARE_StateAttribute_Parameter(_source1_RGB)
COMPARE_StateAttribute_Parameter(_source2_RGB)
COMPARE_StateAttribute_Parameter(_source0_Alpha)
COMPARE_StateAttribute_Parameter(_source1_Alpha)
COMPARE_StateAttribute_Parameter(_source2_Alpha)
COMPARE_StateAttribute_Parameter(_operand0_RGB)
COMPARE_StateAttribute_Parameter(_operand1_RGB)
COMPARE_StateAttribute_Parameter(_operand2_RGB)
COMPARE_StateAttribute_Parameter(_operand0_Alpha)
COMPARE_StateAttribute_Parameter(_operand1_Alpha)
COMPARE_StateAttribute_Parameter(_operand2_Alpha)
COMPARE_StateAttribute_Parameter(_scale_RGB)
COMPARE_StateAttribute_Parameter(_scale_Alpha)
COMPARE_StateAttribute_Parameter(_constantColor)
return 0; // Passed all the above comparison macros, so must be equal.
}
enum CombineParam
{
REPLACE = GL_REPLACE,
MODULATE = GL_MODULATE,
ADD = GL_ADD,
ADD_SIGNED = GL_ADD_SIGNED_ARB,
INTERPOLATE = GL_INTERPOLATE_ARB,
SUBTRACT = GL_SUBTRACT_ARB,
DOT3_RGB = GL_DOT3_RGB_ARB,
DOT3_RGBA = GL_DOT3_RGBA_ARB
};
void setCombine_RGB(GLint cm);
void setCombine_Alpha(GLint cm);
GLint getCombine_RGB() const { return _combine_RGB; }
GLint getCombine_Alpha() const { return _combine_Alpha; }
enum SourceParam
{
CONSTANT = GL_CONSTANT_ARB,
PRIMARY_COLOR = GL_PRIMARY_COLOR_ARB,
PREVIOUS = GL_PREVIOUS_ARB,
TEXTURE = GL_TEXTURE,
TEXTURE0 = GL_TEXTURE0,
TEXTURE1 = GL_TEXTURE0+1,
TEXTURE2 = GL_TEXTURE0+2,
TEXTURE3 = GL_TEXTURE0+3,
TEXTURE4 = GL_TEXTURE0+4,
TEXTURE5 = GL_TEXTURE0+5,
TEXTURE6 = GL_TEXTURE0+6,
TEXTURE7 = GL_TEXTURE0+7
};
void setSource0_RGB(GLint sp);
void setSource1_RGB(GLint sp);
void setSource2_RGB(GLint sp);
void setSource0_Alpha(GLint sp);
void setSource1_Alpha(GLint sp);
void setSource2_Alpha(GLint sp);
GLint getSource0_RGB() const { return _source0_RGB; }
GLint getSource1_RGB() const { return _source1_RGB; }
GLint getSource2_RGB() const { return _source2_RGB; }
GLint getSource0_Alpha() const { return _source0_Alpha; }
GLint getSource1_Alpha() const { return _source1_Alpha; }
GLint getSource2_Alpha() const { return _source2_Alpha; }
enum OperandParam
{
SRC_COLOR = GL_SRC_COLOR,
ONE_MINUS_SRC_COLOR = GL_ONE_MINUS_SRC_COLOR,
SRC_ALPHA = GL_SRC_ALPHA,
ONE_MINUS_SRC_ALPHA = GL_ONE_MINUS_SRC_ALPHA
};
void setOperand0_RGB(GLint op);
void setOperand1_RGB(GLint op);
void setOperand2_RGB(GLint op);
void setOperand0_Alpha(GLint op);
void setOperand1_Alpha(GLint op);
void setOperand2_Alpha(GLint op);
GLint getOperand0_RGB() const { return _operand0_RGB; }
GLint getOperand1_RGB() const { return _operand1_RGB; }
GLint getOperand2_RGB() const { return _operand2_RGB; }
GLint getOperand0_Alpha() const { return _operand0_Alpha; }
GLint getOperand1_Alpha() const { return _operand1_Alpha; }
GLint getOperand2_Alpha() const { return _operand2_Alpha; }
void setScale_RGB(float scale);
void setScale_Alpha(float scale);
float getScale_RGB() const { return _scale_RGB; }
float getScale_Alpha() const { return _scale_Alpha; }
void setConstantColor( const Vec4& color ) { _constantColor = color; }
const Vec4& getConstantColor() const { return _constantColor; }
void setConstantColorAsLightDirection(const Vec3& direction)
{
_constantColor.set((direction.x()+1.0f)*0.5f,(direction.y()+1.0f)*0.5f,(direction.z()+1.0f)*0.5f,1.0f);
}
Vec3 getConstantColorAsLightDirection() const
{
return Vec3(_constantColor.x()*2.0f-1.0f, _constantColor.y()*2.0f-1.0f, _constantColor.z()*2.0f-1.0f);
}
virtual void apply(State& state) const;
protected :
virtual ~TexEnvCombine();
inline bool needsTexEnvCombiner(GLint value) const
{
switch(value)
{
case(CONSTANT):
case(PRIMARY_COLOR):
case(PREVIOUS):
case(TEXTURE):
return false;
}
return true;
}
void computeNeedForTexEnvCombiners()
{
_needsTexEnvCrossbar = (needsTexEnvCombiner(_source0_RGB) ||
needsTexEnvCombiner(_source1_RGB) ||
needsTexEnvCombiner(_source2_RGB) ||
needsTexEnvCombiner(_source0_Alpha) ||
needsTexEnvCombiner(_source1_Alpha) ||
needsTexEnvCombiner(_source2_Alpha));
}
bool _needsTexEnvCrossbar;
GLint _combine_RGB;
GLint _combine_Alpha;
GLint _source0_RGB;
GLint _source1_RGB;
GLint _source2_RGB;
GLint _source0_Alpha;
GLint _source1_Alpha;
GLint _source2_Alpha;
GLint _operand0_RGB;
GLint _operand1_RGB;
GLint _operand2_RGB;
GLint _operand0_Alpha;
GLint _operand1_Alpha;
GLint _operand2_Alpha;
float _scale_RGB;
float _scale_Alpha;
osg::Vec4 _constantColor;
};
}
#endif
COMPARE_StateAttribute_Parameter
#define COMPARE_StateAttribute_Parameter(parameter)
Definition StateAttribute:69
COMPARE_StateAttribute_Types
#define COMPARE_StateAttribute_Types(TYPE, rhs_attribute)
Definition StateAttribute:57
GL_TEXTURE0
#define GL_TEXTURE0
Definition State:42
GL_SUBTRACT_ARB
#define GL_SUBTRACT_ARB
Definition TexEnvCombine:42
GL_DOT3_RGBA_ARB
#define GL_DOT3_RGBA_ARB
Definition TexEnvCombine:50
GL_PREVIOUS_ARB
#define GL_PREVIOUS_ARB
Definition TexEnvCombine:45
GL_ADD_SIGNED_ARB
#define GL_ADD_SIGNED_ARB
Definition TexEnvCombine:40
GL_DOT3_RGB_ARB
#define GL_DOT3_RGB_ARB
Definition TexEnvCombine:49
GL_INTERPOLATE_ARB
#define GL_INTERPOLATE_ARB
Definition TexEnvCombine:41
GL_PRIMARY_COLOR_ARB
#define GL_PRIMARY_COLOR_ARB
Definition TexEnvCombine:44
GL_CONSTANT_ARB
#define GL_CONSTANT_ARB
Definition TexEnvCombine:43
TexEnv
GL_ADD
#define GL_ADD
Definition TexEnv:23
GL_MODULATE
#define GL_MODULATE
Definition TexEnv:22
Vec3
Vec4
osg::CopyOp
Definition CopyOp:41
osg::CopyOp::SHALLOW_COPY
@ SHALLOW_COPY
Definition CopyOp:47
osg::StateAttribute::StateAttribute
StateAttribute()
osg::StateAttribute::TEXENV
@ TEXENV
Definition StateAttribute:144
osg::State
Definition State:80
osg::TexEnvCombine::TexEnvCombine
TexEnvCombine(const TexEnvCombine &texenv, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
Definition TexEnvCombine:68
osg::TexEnvCombine::setSource0_RGB
void setSource0_RGB(GLint sp)
osg::TexEnvCombine::setSource2_Alpha
void setSource2_Alpha(GLint sp)
osg::TexEnvCombine::getCombine_RGB
GLint getCombine_RGB() const
Definition TexEnvCombine:141
osg::TexEnvCombine::setSource0_Alpha
void setSource0_Alpha(GLint sp)
osg::TexEnvCombine::getConstantColor
const Vec4 & getConstantColor() const
Definition TexEnvCombine:208
osg::TexEnvCombine::setSource1_Alpha
void setSource1_Alpha(GLint sp)
osg::TexEnvCombine::_source1_Alpha
GLint _source1_Alpha
Definition TexEnvCombine:265
osg::TexEnvCombine::getSource0_RGB
GLint getSource0_RGB() const
Definition TexEnvCombine:168
osg::TexEnvCombine::_scale_RGB
float _scale_RGB
Definition TexEnvCombine:278
osg::TexEnvCombine::setOperand1_RGB
void setOperand1_RGB(GLint op)
osg::TexEnvCombine::getOperand2_RGB
GLint getOperand2_RGB() const
Definition TexEnvCombine:194
osg::TexEnvCombine::getOperand0_Alpha
GLint getOperand0_Alpha() const
Definition TexEnvCombine:196
osg::TexEnvCombine::getSource2_Alpha
GLint getSource2_Alpha() const
Definition TexEnvCombine:174
osg::TexEnvCombine::getConstantColorAsLightDirection
Vec3 getConstantColorAsLightDirection() const
Definition TexEnvCombine:217
osg::TexEnvCombine::getSource1_Alpha
GLint getSource1_Alpha() const
Definition TexEnvCombine:173
osg::TexEnvCombine::OperandParam
OperandParam
Definition TexEnvCombine:177
osg::TexEnvCombine::SRC_ALPHA
@ SRC_ALPHA
Definition TexEnvCombine:180
osg::TexEnvCombine::ONE_MINUS_SRC_COLOR
@ ONE_MINUS_SRC_COLOR
Definition TexEnvCombine:179
osg::TexEnvCombine::SRC_COLOR
@ SRC_COLOR
Definition TexEnvCombine:178
osg::TexEnvCombine::ONE_MINUS_SRC_ALPHA
@ ONE_MINUS_SRC_ALPHA
Definition TexEnvCombine:181
osg::TexEnvCombine::setScale_Alpha
void setScale_Alpha(float scale)
osg::TexEnvCombine::isTextureAttribute
virtual bool isTextureAttribute() const
Definition TexEnvCombine:93
osg::TexEnvCombine::computeNeedForTexEnvCombiners
void computeNeedForTexEnvCombiners()
Definition TexEnvCombine:241
osg::TexEnvCombine::getOperand1_Alpha
GLint getOperand1_Alpha() const
Definition TexEnvCombine:197
osg::TexEnvCombine::needsTexEnvCombiner
bool needsTexEnvCombiner(GLint value) const
Definition TexEnvCombine:228
osg::TexEnvCombine::getScale_Alpha
float getScale_Alpha() const
Definition TexEnvCombine:205
osg::TexEnvCombine::compare
virtual int compare(const StateAttribute &sa) const
Definition TexEnvCombine:96
osg::TexEnvCombine::setScale_RGB
void setScale_RGB(float scale)
osg::TexEnvCombine::_operand1_Alpha
GLint _operand1_Alpha
Definition TexEnvCombine:274
osg::TexEnvCombine::apply
virtual void apply(State &state) const
osg::TexEnvCombine::_constantColor
osg::Vec4 _constantColor
Definition TexEnvCombine:281
osg::TexEnvCombine::getSource2_RGB
GLint getSource2_RGB() const
Definition TexEnvCombine:170
osg::TexEnvCombine::SourceParam
SourceParam
Definition TexEnvCombine:145
osg::TexEnvCombine::TEXTURE6
@ TEXTURE6
Definition TexEnvCombine:156
osg::TexEnvCombine::TEXTURE4
@ TEXTURE4
Definition TexEnvCombine:154
osg::TexEnvCombine::TEXTURE7
@ TEXTURE7
Definition TexEnvCombine:157
osg::TexEnvCombine::TEXTURE5
@ TEXTURE5
Definition TexEnvCombine:155
osg::TexEnvCombine::TEXTURE3
@ TEXTURE3
Definition TexEnvCombine:153
osg::TexEnvCombine::PREVIOUS
@ PREVIOUS
Definition TexEnvCombine:148
osg::TexEnvCombine::CONSTANT
@ CONSTANT
Definition TexEnvCombine:146
osg::TexEnvCombine::TEXTURE
@ TEXTURE
Definition TexEnvCombine:149
osg::TexEnvCombine::PRIMARY_COLOR
@ PRIMARY_COLOR
Definition TexEnvCombine:147
osg::TexEnvCombine::TEXTURE0
@ TEXTURE0
Definition TexEnvCombine:150
osg::TexEnvCombine::TEXTURE1
@ TEXTURE1
Definition TexEnvCombine:151
osg::TexEnvCombine::TEXTURE2
@ TEXTURE2
Definition TexEnvCombine:152
osg::TexEnvCombine::_combine_Alpha
GLint _combine_Alpha
Definition TexEnvCombine:258
osg::TexEnvCombine::_operand2_RGB
GLint _operand2_RGB
Definition TexEnvCombine:271
osg::TexEnvCombine::~TexEnvCombine
virtual ~TexEnvCombine()
osg::TexEnvCombine::META_StateAttribute
META_StateAttribute(osg, TexEnvCombine, TEXENV)
osg::TexEnvCombine::_source1_RGB
GLint _source1_RGB
Definition TexEnvCombine:261
osg::TexEnvCombine::TexEnvCombine
TexEnvCombine()
osg::TexEnvCombine::getSource0_Alpha
GLint getSource0_Alpha() const
Definition TexEnvCombine:172
osg::TexEnvCombine::_source0_Alpha
GLint _source0_Alpha
Definition TexEnvCombine:264
osg::TexEnvCombine::getScale_RGB
float getScale_RGB() const
Definition TexEnvCombine:204
osg::TexEnvCombine::_operand2_Alpha
GLint _operand2_Alpha
Definition TexEnvCombine:275
osg::TexEnvCombine::setCombine_Alpha
void setCombine_Alpha(GLint cm)
osg::TexEnvCombine::_needsTexEnvCrossbar
bool _needsTexEnvCrossbar
Definition TexEnvCombine:255
osg::TexEnvCombine::_operand0_Alpha
GLint _operand0_Alpha
Definition TexEnvCombine:273
osg::TexEnvCombine::setOperand0_RGB
void setOperand0_RGB(GLint op)
osg::TexEnvCombine::getOperand2_Alpha
GLint getOperand2_Alpha() const
Definition TexEnvCombine:198
osg::TexEnvCombine::setOperand0_Alpha
void setOperand0_Alpha(GLint op)
osg::TexEnvCombine::getOperand1_RGB
GLint getOperand1_RGB() const
Definition TexEnvCombine:193
osg::TexEnvCombine::setSource2_RGB
void setSource2_RGB(GLint sp)
osg::TexEnvCombine::getSource1_RGB
GLint getSource1_RGB() const
Definition TexEnvCombine:169
osg::TexEnvCombine::_source2_Alpha
GLint _source2_Alpha
Definition TexEnvCombine:266
osg::TexEnvCombine::_source2_RGB
GLint _source2_RGB
Definition TexEnvCombine:262
osg::TexEnvCombine::_operand1_RGB
GLint _operand1_RGB
Definition TexEnvCombine:270
osg::TexEnvCombine::setOperand2_Alpha
void setOperand2_Alpha(GLint op)
osg::TexEnvCombine::setConstantColor
void setConstantColor(const Vec4 &color)
Definition TexEnvCombine:207
osg::TexEnvCombine::getCombine_Alpha
GLint getCombine_Alpha() const
Definition TexEnvCombine:142
osg::TexEnvCombine::setOperand1_Alpha
void setOperand1_Alpha(GLint op)
osg::TexEnvCombine::_operand0_RGB
GLint _operand0_RGB
Definition TexEnvCombine:269
osg::TexEnvCombine::CombineParam
CombineParam
Definition TexEnvCombine:127
osg::TexEnvCombine::ADD_SIGNED
@ ADD_SIGNED
Definition TexEnvCombine:131
osg::TexEnvCombine::REPLACE
@ REPLACE
Definition TexEnvCombine:128
osg::TexEnvCombine::ADD
@ ADD
Definition TexEnvCombine:130
osg::TexEnvCombine::MODULATE
@ MODULATE
Definition TexEnvCombine:129
osg::TexEnvCombine::SUBTRACT
@ SUBTRACT
Definition TexEnvCombine:133
osg::TexEnvCombine::DOT3_RGBA
@ DOT3_RGBA
Definition TexEnvCombine:135
osg::TexEnvCombine::DOT3_RGB
@ DOT3_RGB
Definition TexEnvCombine:134
osg::TexEnvCombine::INTERPOLATE
@ INTERPOLATE
Definition TexEnvCombine:132
osg::TexEnvCombine::_scale_Alpha
float _scale_Alpha
Definition TexEnvCombine:279
osg::TexEnvCombine::setCombine_RGB
void setCombine_RGB(GLint cm)
osg::TexEnvCombine::_source0_RGB
GLint _source0_RGB
Definition TexEnvCombine:260
osg::TexEnvCombine::getOperand0_RGB
GLint getOperand0_RGB() const
Definition TexEnvCombine:192
osg::TexEnvCombine::setOperand2_RGB
void setOperand2_RGB(GLint op)
osg::TexEnvCombine::setConstantColorAsLightDirection
void setConstantColorAsLightDirection(const Vec3 &direction)
Definition TexEnvCombine:212
osg::TexEnvCombine::_combine_RGB
GLint _combine_RGB
Definition TexEnvCombine:257
osg::TexEnvCombine::setSource1_RGB
void setSource1_RGB(GLint sp)
osg::Vec3f::z
value_type & z()
Definition Vec3f:82
osg::Vec3f::y
value_type & y()
Definition Vec3f:81
osg::Vec3f::x
value_type & x()
Definition Vec3f:80
osg
Definition AlphaFunc:19
osg::Vec3
Vec3f Vec3
Definition Vec3:21
osg::Vec4
Vec4f Vec4
Definition Vec4:21
OSG_EXPORT
#define OSG_EXPORT
Definition osg/Export:39