root/OpenSceneGraph/trunk/src/osg/TexEnvCombine.cpp @ 13041

Revision 13041, 6.0 kB (checked in by robert, 2 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
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#include <osg/GLExtensions>
14#include <osg/TexEnvCombine>
15#include <osg/State>
16#include <osg/Notify>
17
18using namespace osg;
19
20TexEnvCombine::TexEnvCombine():
21            _needsTexEnvCrossbar(false),
22            _combine_RGB(GL_MODULATE),
23            _combine_Alpha(GL_MODULATE),
24            _source0_RGB(GL_TEXTURE),
25            _source1_RGB(GL_PREVIOUS_ARB),
26            _source2_RGB(GL_CONSTANT_ARB),
27            _source0_Alpha(GL_TEXTURE),
28            _source1_Alpha(GL_PREVIOUS_ARB),
29            _source2_Alpha(GL_CONSTANT_ARB),
30            _operand0_RGB(GL_SRC_COLOR),
31            _operand1_RGB(GL_SRC_COLOR),
32            _operand2_RGB(GL_SRC_ALPHA),
33            _operand0_Alpha(GL_SRC_ALPHA),
34            _operand1_Alpha(GL_SRC_ALPHA),
35            _operand2_Alpha(GL_SRC_ALPHA),
36            _scale_RGB(1.0),
37            _scale_Alpha(1.0),
38            _constantColor(0.0f,0.0f,0.0f,0.0f)
39{
40}
41
42TexEnvCombine::~TexEnvCombine()
43{
44}
45
46void TexEnvCombine::apply(State& state) const
47{
48#ifdef OSG_GL_FIXED_FUNCTION_AVAILABLE
49    unsigned int contextID = state.getContextID();
50
51    static bool s_isTexEnvCombineSupported =
52        isGLExtensionSupported(contextID,"GL_ARB_texture_env_combine");
53
54    static bool s_isTexEnvCrossbarSupported =
55        isGLExtensionSupported(contextID,"GL_ARB_texture_env_crossbar");
56
57    static bool s_isNVTexEnvCrossbarSupported =
58        isGLExtensionSupported(contextID,"GL_NV_texture_env_combine4");
59
60    static bool s_isTexEnvDot3Supported =
61        isGLExtensionSupported(contextID,"GL_ARB_texture_env_dot3");
62
63
64    bool needsTexEnvDot3 = (_combine_RGB==DOT3_RGB) ||
65                           (_combine_RGB==DOT3_RGBA);
66
67    bool supported = s_isTexEnvCombineSupported;
68    if (_needsTexEnvCrossbar && !(s_isTexEnvCrossbarSupported || s_isNVTexEnvCrossbarSupported)) supported = false;
69    if (needsTexEnvDot3 && !s_isTexEnvDot3Supported) supported = false;
70
71    if (supported)
72    {
73        glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
74
75        glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, _combine_RGB);
76
77        if (_combine_RGB!=DOT3_RGBA)
78            glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, _combine_Alpha);
79
80        glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB,_source0_RGB );
81        glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, _source1_RGB);
82        glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB,_source2_RGB );
83
84        glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, _source0_Alpha);
85        glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_ARB, _source1_Alpha);
86        glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE2_ALPHA_ARB, _source2_Alpha);
87
88        glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, _operand0_RGB);
89        glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, _operand1_RGB);
90        glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, _operand2_RGB);
91
92        glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, _operand0_Alpha);
93        glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_ARB, _operand1_Alpha);
94        glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND2_ALPHA_ARB, _operand2_Alpha);
95
96        glTexEnvf( GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, _scale_RGB);
97        glTexEnvf( GL_TEXTURE_ENV, GL_ALPHA_SCALE, _scale_Alpha);
98
99        glTexEnvfv( GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, _constantColor.ptr());
100    }
101    else
102    {
103        // what is the best fallback when the tex env combine is not supported??
104        // we will resort the settung the OpenGL default of GL_MODULATE.
105        glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
106    }
107#else
108    OSG_NOTICE<<"Warning: TexEnvCombine::apply(State&) - not supported."<<std::endl;
109#endif
110}
111void TexEnvCombine::setCombine_RGB(GLint cm) { _combine_RGB = cm; }
112void TexEnvCombine::setCombine_Alpha(GLint cm) { _combine_Alpha = cm; }
113
114void TexEnvCombine::setSource0_RGB(GLint sp) { _source0_RGB = sp; computeNeedForTexEnvCombiners(); }
115void TexEnvCombine::setSource1_RGB(GLint sp) { _source1_RGB = sp; computeNeedForTexEnvCombiners(); }
116void TexEnvCombine::setSource2_RGB(GLint sp) { _source2_RGB = sp; computeNeedForTexEnvCombiners(); }
117
118void TexEnvCombine::setSource0_Alpha(GLint sp) { _source0_Alpha = sp; computeNeedForTexEnvCombiners(); }
119void TexEnvCombine::setSource1_Alpha(GLint sp) { _source1_Alpha = sp; computeNeedForTexEnvCombiners(); }
120void TexEnvCombine::setSource2_Alpha(GLint sp) { _source2_Alpha = sp; computeNeedForTexEnvCombiners(); }
121
122void TexEnvCombine::setOperand0_RGB(GLint op) { _operand0_RGB = op; }
123void TexEnvCombine::setOperand1_RGB(GLint op) { _operand1_RGB = op; }
124void TexEnvCombine::setOperand2_RGB(GLint op) { _operand2_RGB = op; }
125
126static GLint Valid_Operand_Alpha(GLint op, const char* functionName)
127{
128    if (op==TexEnvCombine::SRC_ALPHA || op==TexEnvCombine::ONE_MINUS_SRC_ALPHA) return op;
129
130    OSG_WARN<<"Warning:: TexEnvCombine::"<<functionName<<"("<<op<<") invalid parameter value,"<<std::endl<<
131                  "          must be SRC_ALPHA or ONE_MINUS_SRC_ALPHA, resetting to SRC_ALPHA."<<std::endl;
132    return TexEnvCombine::SRC_ALPHA;
133}
134
135void TexEnvCombine::setOperand0_Alpha(GLint op)
136{
137    _operand0_Alpha = Valid_Operand_Alpha(op,"setOperand0_Alpha");
138}
139void TexEnvCombine::setOperand1_Alpha(GLint op)
140{
141    _operand1_Alpha = Valid_Operand_Alpha(op,"setOperand1_Alpha");
142}
143void TexEnvCombine::setOperand2_Alpha(GLint op)
144{
145    _operand2_Alpha = Valid_Operand_Alpha(op,"setOperand2_Alpha");
146}
147
148void TexEnvCombine::setScale_RGB(float scale) { _scale_RGB = scale; }
149void TexEnvCombine::setScale_Alpha(float scale) { _scale_Alpha = scale; }
Note: See TracBrowser for help on using the browser.