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/BlendFunc>
14 #include <osg/GLExtensions>
15 #include <osg/State>
16 #include <osg/Notify>
17
18 using namespace osg;
19
BlendFunc()20 BlendFunc::BlendFunc():
21 _source_factor(SRC_ALPHA),
22 _destination_factor(ONE_MINUS_SRC_ALPHA),
23 _source_factor_alpha(SRC_ALPHA),
24 _destination_factor_alpha(ONE_MINUS_SRC_ALPHA)
25 {
26 }
27
BlendFunc(GLenum source,GLenum destination)28 BlendFunc::BlendFunc(GLenum source, GLenum destination):
29 _source_factor(source),
30 _destination_factor(destination),
31 _source_factor_alpha(source),
32 _destination_factor_alpha(destination)
33 {
34 }
35
BlendFunc(GLenum source,GLenum destination,GLenum source_alpha,GLenum destination_alpha)36 BlendFunc::BlendFunc(GLenum source, GLenum destination, GLenum source_alpha, GLenum destination_alpha):
37 _source_factor(source),
38 _destination_factor(destination),
39 _source_factor_alpha(source_alpha),
40 _destination_factor_alpha(destination_alpha)
41 {
42 }
43
~BlendFunc()44 BlendFunc::~BlendFunc()
45 {
46 }
47
apply(State & state) const48 void BlendFunc::apply(State& state) const
49 {
50 if (_source_factor != _source_factor_alpha ||
51 _destination_factor != _destination_factor_alpha)
52 {
53 const GLExtensions* extensions = state.get<GLExtensions>();
54 if (!extensions->isBlendFuncSeparateSupported)
55 {
56 OSG_WARN<<"Warning: BlendFunc::apply(..) failed, BlendFuncSeparate is not support by OpenGL driver, falling back to BlendFunc."<<std::endl;
57 }
58 else
59 {
60 extensions->glBlendFuncSeparate(_source_factor, _destination_factor, _source_factor_alpha, _destination_factor_alpha);
61 return;
62 }
63 }
64
65 glBlendFunc( _source_factor, _destination_factor );
66 }
67