2006-07-18 23:21:48 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
|
|
|
* 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
|
|
|
#include <osg/GLExtensions>
|
2002-08-25 03:39:39 +08:00
|
|
|
#include <osg/TexEnvCombine>
|
2005-04-26 21:15:27 +08:00
|
|
|
#include <osg/State>
|
2003-12-04 05:45:32 +08:00
|
|
|
#include <osg/Notify>
|
2002-08-19 23:11:09 +08:00
|
|
|
|
|
|
|
using namespace osg;
|
|
|
|
|
2002-08-20 03:53:34 +08:00
|
|
|
TexEnvCombine::TexEnvCombine():
|
2002-08-20 22:15:49 +08:00
|
|
|
_needsTexEnvCrossbar(false),
|
2002-08-20 03:53:34 +08:00
|
|
|
_combine_RGB(GL_MODULATE),
|
|
|
|
_combine_Alpha(GL_MODULATE),
|
|
|
|
_source0_RGB(GL_TEXTURE),
|
|
|
|
_source1_RGB(GL_PREVIOUS_ARB),
|
|
|
|
_source2_RGB(GL_CONSTANT_ARB),
|
|
|
|
_source0_Alpha(GL_TEXTURE),
|
|
|
|
_source1_Alpha(GL_PREVIOUS_ARB),
|
|
|
|
_source2_Alpha(GL_CONSTANT_ARB),
|
|
|
|
_operand0_RGB(GL_SRC_COLOR),
|
|
|
|
_operand1_RGB(GL_SRC_COLOR),
|
|
|
|
_operand2_RGB(GL_SRC_ALPHA),
|
|
|
|
_operand0_Alpha(GL_SRC_ALPHA),
|
|
|
|
_operand1_Alpha(GL_SRC_ALPHA),
|
|
|
|
_operand2_Alpha(GL_SRC_ALPHA),
|
|
|
|
_scale_RGB(1.0),
|
|
|
|
_scale_Alpha(1.0),
|
|
|
|
_constantColor(0.0f,0.0f,0.0f,0.0f)
|
2002-08-19 23:11:09 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
TexEnvCombine::~TexEnvCombine()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2005-04-26 21:15:27 +08:00
|
|
|
void TexEnvCombine::apply(State& state) const
|
2002-08-19 23:11:09 +08:00
|
|
|
{
|
2009-10-23 21:19:57 +08:00
|
|
|
#ifdef OSG_GL_FIXED_FUNCTION_AVAILABLE
|
2005-04-26 21:15:27 +08:00
|
|
|
unsigned int contextID = state.getContextID();
|
|
|
|
|
2002-08-25 05:11:07 +08:00
|
|
|
static bool s_isTexEnvCombineSupported =
|
2005-04-26 21:15:27 +08:00
|
|
|
isGLExtensionSupported(contextID,"GL_ARB_texture_env_combine");
|
2002-08-19 23:11:09 +08:00
|
|
|
|
2002-08-25 05:11:07 +08:00
|
|
|
static bool s_isTexEnvCrossbarSupported =
|
2005-04-26 21:15:27 +08:00
|
|
|
isGLExtensionSupported(contextID,"GL_ARB_texture_env_crossbar");
|
2002-08-20 22:15:49 +08:00
|
|
|
|
2003-06-24 23:40:09 +08:00
|
|
|
static bool s_isNVTexEnvCrossbarSupported =
|
2005-04-26 21:15:27 +08:00
|
|
|
isGLExtensionSupported(contextID,"GL_NV_texture_env_combine4");
|
2003-06-24 23:40:09 +08:00
|
|
|
|
2002-08-25 05:11:07 +08:00
|
|
|
static bool s_isTexEnvDot3Supported =
|
2005-04-26 21:15:27 +08:00
|
|
|
isGLExtensionSupported(contextID,"GL_ARB_texture_env_dot3");
|
2002-08-25 05:11:07 +08:00
|
|
|
|
2003-06-24 23:40:09 +08:00
|
|
|
|
2002-08-25 05:11:07 +08:00
|
|
|
bool needsTexEnvDot3 = (_combine_RGB==DOT3_RGB) ||
|
|
|
|
(_combine_RGB==DOT3_RGBA);
|
|
|
|
|
|
|
|
bool supported = s_isTexEnvCombineSupported;
|
2003-06-24 23:40:09 +08:00
|
|
|
if (_needsTexEnvCrossbar && !(s_isTexEnvCrossbarSupported || s_isNVTexEnvCrossbarSupported)) supported = false;
|
2002-08-25 05:11:07 +08:00
|
|
|
if (needsTexEnvDot3 && !s_isTexEnvDot3Supported) supported = false;
|
|
|
|
|
|
|
|
if (supported)
|
2002-08-19 23:11:09 +08:00
|
|
|
{
|
|
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
|
|
|
|
|
|
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, _combine_RGB);
|
2002-08-25 05:11:07 +08:00
|
|
|
|
|
|
|
if (_combine_RGB!=DOT3_RGBA)
|
|
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, _combine_Alpha);
|
2002-08-19 23:11:09 +08:00
|
|
|
|
|
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB,_source0_RGB );
|
|
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, _source1_RGB);
|
|
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB,_source2_RGB );
|
|
|
|
|
|
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, _source0_Alpha);
|
|
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_ARB, _source1_Alpha);
|
|
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE2_ALPHA_ARB, _source2_Alpha);
|
|
|
|
|
|
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, _operand0_RGB);
|
|
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, _operand1_RGB);
|
|
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, _operand2_RGB);
|
|
|
|
|
|
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, _operand0_Alpha);
|
|
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_ARB, _operand1_Alpha);
|
|
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND2_ALPHA_ARB, _operand2_Alpha);
|
|
|
|
|
|
|
|
glTexEnvf( GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, _scale_RGB);
|
|
|
|
glTexEnvf( GL_TEXTURE_ENV, GL_ALPHA_SCALE, _scale_Alpha);
|
|
|
|
|
|
|
|
glTexEnvfv( GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, _constantColor.ptr());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// what is the best fallback when the tex env combine is not supported??
|
|
|
|
// we will resort the settung the OpenGL default of GL_MODULATE.
|
|
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
|
|
|
}
|
2009-10-23 21:19:57 +08:00
|
|
|
#else
|
2010-05-28 23:47:52 +08:00
|
|
|
OSG_NOTICE<<"Warning: TexEnvCombine::apply(State&) - not supported."<<std::endl;
|
2009-10-23 21:19:57 +08:00
|
|
|
#endif
|
2002-08-19 23:11:09 +08:00
|
|
|
}
|
2003-12-04 05:45:32 +08:00
|
|
|
void TexEnvCombine::setCombine_RGB(GLint cm) { _combine_RGB = cm; }
|
|
|
|
void TexEnvCombine::setCombine_Alpha(GLint cm) { _combine_Alpha = cm; }
|
|
|
|
|
2007-07-11 23:51:17 +08:00
|
|
|
void TexEnvCombine::setSource0_RGB(GLint sp) { _source0_RGB = sp; computeNeedForTexEnvCombiners(); }
|
|
|
|
void TexEnvCombine::setSource1_RGB(GLint sp) { _source1_RGB = sp; computeNeedForTexEnvCombiners(); }
|
|
|
|
void TexEnvCombine::setSource2_RGB(GLint sp) { _source2_RGB = sp; computeNeedForTexEnvCombiners(); }
|
2003-12-04 05:45:32 +08:00
|
|
|
|
2007-07-11 23:51:17 +08:00
|
|
|
void TexEnvCombine::setSource0_Alpha(GLint sp) { _source0_Alpha = sp; computeNeedForTexEnvCombiners(); }
|
|
|
|
void TexEnvCombine::setSource1_Alpha(GLint sp) { _source1_Alpha = sp; computeNeedForTexEnvCombiners(); }
|
|
|
|
void TexEnvCombine::setSource2_Alpha(GLint sp) { _source2_Alpha = sp; computeNeedForTexEnvCombiners(); }
|
2003-12-04 05:45:32 +08:00
|
|
|
|
|
|
|
void TexEnvCombine::setOperand0_RGB(GLint op) { _operand0_RGB = op; }
|
|
|
|
void TexEnvCombine::setOperand1_RGB(GLint op) { _operand1_RGB = op; }
|
|
|
|
void TexEnvCombine::setOperand2_RGB(GLint op) { _operand2_RGB = op; }
|
|
|
|
|
|
|
|
static GLint Valid_Operand_Alpha(GLint op, const char* functionName)
|
|
|
|
{
|
|
|
|
if (op==TexEnvCombine::SRC_ALPHA || op==TexEnvCombine::ONE_MINUS_SRC_ALPHA) return op;
|
|
|
|
|
2010-05-28 23:47:52 +08:00
|
|
|
OSG_WARN<<"Warning:: TexEnvCombine::"<<functionName<<"("<<op<<") invalid parameter value,"<<std::endl<<
|
2003-12-04 05:45:32 +08:00
|
|
|
" must be SRC_ALPHA or ONE_MINUS_SRC_ALPHA, resetting to SRC_ALPHA."<<std::endl;
|
|
|
|
return TexEnvCombine::SRC_ALPHA;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TexEnvCombine::setOperand0_Alpha(GLint op)
|
|
|
|
{
|
|
|
|
_operand0_Alpha = Valid_Operand_Alpha(op,"setOperand0_Alpha");
|
|
|
|
}
|
|
|
|
void TexEnvCombine::setOperand1_Alpha(GLint op)
|
|
|
|
{
|
|
|
|
_operand1_Alpha = Valid_Operand_Alpha(op,"setOperand1_Alpha");
|
|
|
|
}
|
|
|
|
void TexEnvCombine::setOperand2_Alpha(GLint op)
|
|
|
|
{
|
|
|
|
_operand2_Alpha = Valid_Operand_Alpha(op,"setOperand2_Alpha");
|
|
|
|
}
|
|
|
|
|
|
|
|
void TexEnvCombine::setScale_RGB(float scale) { _scale_RGB = scale; }
|
|
|
|
void TexEnvCombine::setScale_Alpha(float scale) { _scale_Alpha = scale; }
|