2003-01-22 00:45:36 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 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.
|
|
|
|
*/
|
2002-08-19 23:11:09 +08:00
|
|
|
|
|
|
|
#ifndef OSG_TEXENVCOMBINE
|
|
|
|
#define OSG_TEXENVCOMBINE 1
|
|
|
|
|
|
|
|
#include <osg/GL>
|
|
|
|
#include <osg/StateAttribute>
|
|
|
|
#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
|
|
|
|
|
2002-08-26 23:02:31 +08:00
|
|
|
#ifndef GL_ARB_texture_env_dot3
|
|
|
|
#define GL_DOT3_RGB_ARB 0x86AE
|
|
|
|
#define GL_DOT3_RGBA_ARB 0x86AF
|
|
|
|
#endif
|
|
|
|
|
2002-08-20 22:15:49 +08:00
|
|
|
#ifndef GL_TEXTURE0
|
|
|
|
#define GL_TEXTURE0 0x84C0
|
|
|
|
#endif
|
|
|
|
|
2002-08-19 23:11:09 +08:00
|
|
|
namespace osg {
|
|
|
|
|
|
|
|
/** TexEnvCombine - encapsulates the OpenGL glTexEnvCombine (texture environment) state.*/
|
|
|
|
class SG_EXPORT TexEnvCombine : public StateAttribute
|
|
|
|
{
|
|
|
|
public :
|
|
|
|
|
|
|
|
TexEnvCombine();
|
|
|
|
|
|
|
|
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
|
|
|
TexEnvCombine(const TexEnvCombine& texenv,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
|
|
|
StateAttribute(texenv,copyop),
|
2002-08-20 22:15:49 +08:00
|
|
|
_needsTexEnvCrossbar(texenv._needsTexEnvCrossbar),
|
2002-08-19 23:11:09 +08:00
|
|
|
_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; }
|
|
|
|
|
|
|
|
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
|
|
|
|
virtual int compare(const StateAttribute& sa) const
|
|
|
|
{
|
|
|
|
// check the types are equal and then create the rhs variable
|
|
|
|
// used by the COMPARE_StateAttribute_Paramter macro's below.
|
|
|
|
COMPARE_StateAttribute_Types(TexEnvCombine,sa)
|
|
|
|
|
|
|
|
// compare each paramter in turn against the rhs.
|
2002-08-20 22:15:49 +08:00
|
|
|
COMPARE_StateAttribute_Parameter(_needsTexEnvCrossbar)
|
2002-08-19 23:11:09 +08:00
|
|
|
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 macro's, must be equal.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
enum CombineParam
|
|
|
|
{
|
|
|
|
REPLACE = GL_REPLACE,
|
|
|
|
MODULATE = GL_MODULATE,
|
|
|
|
ADD = GL_ADD,
|
|
|
|
ADD_SIGNED = GL_ADD_SIGNED_ARB,
|
|
|
|
INTERPOLATE = GL_INTERPOLATE_ARB,
|
2002-08-25 05:11:07 +08:00
|
|
|
SUBTRACT = GL_SUBTRACT_ARB,
|
|
|
|
DOT3_RGB = GL_DOT3_RGB_ARB,
|
|
|
|
DOT3_RGBA = GL_DOT3_RGBA_ARB
|
2002-08-19 23:11:09 +08:00
|
|
|
};
|
|
|
|
|
2002-08-21 02:00:22 +08:00
|
|
|
void setCombine_RGB(GLint cm) { _combine_RGB = cm; }
|
|
|
|
void setCombine_Alpha(GLint cm) { _combine_Alpha = cm; }
|
2002-08-19 23:11:09 +08:00
|
|
|
|
2002-08-21 02:00:22 +08:00
|
|
|
GLint getCombine_RGB() const { return _combine_RGB; }
|
|
|
|
GLint getCombine_Alpha() const { return _combine_Alpha; }
|
2002-08-19 23:11:09 +08:00
|
|
|
|
|
|
|
enum SourceParam
|
|
|
|
{
|
|
|
|
CONSTANT = GL_CONSTANT_ARB,
|
|
|
|
PRIMARY_COLOR = GL_PRIMARY_COLOR_ARB,
|
2002-08-20 22:15:49 +08:00
|
|
|
PREVIOUS = GL_PREVIOUS_ARB,
|
|
|
|
TEXTURE = GL_TEXTURE,
|
2002-08-21 02:00:22 +08:00
|
|
|
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
|
2002-08-19 23:11:09 +08:00
|
|
|
};
|
|
|
|
|
2002-08-20 22:15:49 +08:00
|
|
|
void setSource0_RGB(GLint sp) { _source0_RGB = sp; computeNeedoForTexEnvCombiners(); }
|
|
|
|
void setSource1_RGB(GLint sp) { _source1_RGB = sp; computeNeedoForTexEnvCombiners(); }
|
|
|
|
void setSource2_RGB(GLint sp) { _source2_RGB = sp; computeNeedoForTexEnvCombiners(); }
|
2002-08-19 23:11:09 +08:00
|
|
|
|
2002-08-20 22:15:49 +08:00
|
|
|
void setSource0_Alpha(GLint sp) { _source0_Alpha = sp; computeNeedoForTexEnvCombiners(); }
|
|
|
|
void setSource1_Alpha(GLint sp) { _source1_Alpha = sp; computeNeedoForTexEnvCombiners(); }
|
|
|
|
void setSource2_Alpha(GLint sp) { _source2_Alpha = sp; computeNeedoForTexEnvCombiners(); }
|
2002-08-19 23:11:09 +08:00
|
|
|
|
2002-08-20 03:53:34 +08:00
|
|
|
GLint getSource0_RGB() const { return _source0_RGB; }
|
|
|
|
GLint getSource1_RGB() const { return _source1_RGB; }
|
|
|
|
GLint getSource2_RGB() const { return _source2_RGB; }
|
2002-08-19 23:11:09 +08:00
|
|
|
|
2002-08-20 03:53:34 +08:00
|
|
|
GLint getSource0_Alpha() const { return _source0_Alpha; }
|
|
|
|
GLint getSource1_Alpha() const { return _source1_Alpha; }
|
|
|
|
GLint getSource2_Alpha() const { return _source2_Alpha; }
|
2002-08-19 23:11:09 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
2002-08-20 03:53:34 +08:00
|
|
|
void setOperand0_RGB(GLint op) { _operand0_RGB = op; }
|
|
|
|
void setOperand1_RGB(GLint op) { _operand1_RGB = op; }
|
|
|
|
void setOperand2_RGB(GLint op) { _operand2_RGB = op; }
|
2002-08-19 23:11:09 +08:00
|
|
|
|
2002-08-20 03:53:34 +08:00
|
|
|
void setOperand0_Alpha(GLint op) { _operand0_Alpha = op; }
|
|
|
|
void setOperand1_Alpha(GLint op) { _operand1_Alpha = op; }
|
|
|
|
void setOperand2_Alpha(GLint op) { _operand2_Alpha = op; }
|
2002-08-19 23:11:09 +08:00
|
|
|
|
2002-08-20 03:53:34 +08:00
|
|
|
GLint getOperand0_RGB() const { return _operand0_RGB; }
|
|
|
|
GLint getOperand1_RGB() const { return _operand1_RGB; }
|
|
|
|
GLint getOperand2_RGB() const { return _operand2_RGB; }
|
2002-08-19 23:11:09 +08:00
|
|
|
|
2002-08-20 03:53:34 +08:00
|
|
|
GLint getOperand0_Alpha() const { return _operand0_Alpha; }
|
|
|
|
GLint getOperand1_Alpha() const { return _operand1_Alpha; }
|
|
|
|
GLint getOperand2_Alpha() const { return _operand2_Alpha; }
|
2002-08-19 23:11:09 +08:00
|
|
|
|
|
|
|
|
|
|
|
void setScale_RGB(float scale) { _scale_RGB = scale; }
|
|
|
|
void setScale_Alpha(float scale) { _scale_Alpha = 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; }
|
|
|
|
|
|
|
|
|
|
|
|
virtual void apply(State& state) const;
|
|
|
|
|
|
|
|
protected :
|
|
|
|
|
|
|
|
virtual ~TexEnvCombine();
|
|
|
|
|
2002-08-20 22:15:49 +08:00
|
|
|
inline bool needsTexEnvCombiner(GLint value) const
|
|
|
|
{
|
|
|
|
switch(value)
|
|
|
|
{
|
|
|
|
case(CONSTANT):
|
|
|
|
case(PRIMARY_COLOR):
|
|
|
|
case(PREVIOUS):
|
|
|
|
case(TEXTURE):
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void computeNeedoForTexEnvCombiners()
|
|
|
|
{
|
|
|
|
_needsTexEnvCrossbar = (needsTexEnvCombiner(_source0_RGB) ||
|
|
|
|
needsTexEnvCombiner(_source1_RGB) ||
|
|
|
|
needsTexEnvCombiner(_source2_RGB) ||
|
|
|
|
needsTexEnvCombiner(_source0_Alpha) ||
|
|
|
|
needsTexEnvCombiner(_source1_Alpha) ||
|
|
|
|
needsTexEnvCombiner(_source2_Alpha));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-08-19 23:11:09 +08:00
|
|
|
|
|
|
|
|
2002-08-20 22:15:49 +08:00
|
|
|
bool _needsTexEnvCrossbar;
|
2002-08-19 23:11:09 +08:00
|
|
|
|
2002-08-20 22:15:49 +08:00
|
|
|
GLint _combine_RGB;
|
|
|
|
GLint _combine_Alpha;
|
|
|
|
|
2002-08-20 03:53:34 +08:00
|
|
|
GLint _source0_RGB;
|
|
|
|
GLint _source1_RGB;
|
|
|
|
GLint _source2_RGB;
|
2002-08-19 23:11:09 +08:00
|
|
|
|
2002-08-20 03:53:34 +08:00
|
|
|
GLint _source0_Alpha;
|
|
|
|
GLint _source1_Alpha;
|
|
|
|
GLint _source2_Alpha;
|
2002-08-19 23:11:09 +08:00
|
|
|
|
|
|
|
|
2002-08-20 03:53:34 +08:00
|
|
|
GLint _operand0_RGB;
|
|
|
|
GLint _operand1_RGB;
|
|
|
|
GLint _operand2_RGB;
|
2002-08-19 23:11:09 +08:00
|
|
|
|
2002-08-20 03:53:34 +08:00
|
|
|
GLint _operand0_Alpha;
|
|
|
|
GLint _operand1_Alpha;
|
|
|
|
GLint _operand2_Alpha;
|
2002-08-19 23:11:09 +08:00
|
|
|
|
|
|
|
|
|
|
|
float _scale_RGB;
|
|
|
|
float _scale_Alpha;
|
|
|
|
|
|
|
|
osg::Vec4 _constantColor;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|