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/BlendEquation>
14 #include <osg/GLExtensions>
15 #include <osg/State>
16 #include <osg/Notify>
17 #include <osg/buffered_value>
18 
19 
20 using namespace osg;
21 
BlendEquation()22 BlendEquation::BlendEquation():
23     _equationRGB(FUNC_ADD),
24     _equationAlpha(FUNC_ADD)
25 {
26 }
27 
BlendEquation(Equation equation)28 BlendEquation::BlendEquation(Equation equation):
29     _equationRGB(equation),
30     _equationAlpha(equation)
31 {
32 }
33 
BlendEquation(Equation equationRGB,Equation equationAlpha)34 BlendEquation::BlendEquation(Equation equationRGB, Equation equationAlpha):
35     _equationRGB(equationRGB),
36     _equationAlpha(equationAlpha)
37 {
38 }
39 
~BlendEquation()40 BlendEquation::~BlendEquation()
41 {
42 }
43 
apply(State & state) const44 void BlendEquation::apply(State& state) const
45 {
46     const GLExtensions* extensions = state.get<GLExtensions>();
47 
48     if (!extensions->isBlendEquationSupported)
49     {
50         OSG_WARN<<"Warning: BlendEquation::apply(..) failed, BlendEquation is not support by OpenGL driver."<<std::endl;
51         return;
52     }
53 
54     if((_equationRGB == ALPHA_MIN || _equationRGB == ALPHA_MAX) && !extensions->isSGIXMinMaxSupported)
55     {
56         OSG_WARN<<"Warning: BlendEquation::apply(..) failed, SGIX_blend_alpha_minmax extension is not supported by OpenGL driver." << std::endl;
57         return;
58     }
59 
60     if(_equationRGB == LOGIC_OP && !extensions->isLogicOpSupported)
61     {
62         OSG_WARN<<"Warning: BlendEquation::apply(..) failed, EXT_blend_logic_op extension is not supported by OpenGL driver." << std::endl;
63         return;
64     }
65 
66     if (_equationRGB == _equationAlpha)
67     {
68         extensions->glBlendEquation(static_cast<GLenum>(_equationRGB));
69     }
70     else
71     {
72         if (extensions->isBlendEquationSeparateSupported)
73         {
74             extensions->glBlendEquationSeparate(static_cast<GLenum>(_equationRGB), static_cast<GLenum>(_equationAlpha));
75         }
76         else
77         {
78             OSG_WARN<<"Warning: BlendEquation::apply(..) failed, EXT_blend_equation_separate extension is not supported by OpenGL driver." << std::endl;
79             return;
80         }
81     }
82 }
83