1 // Parse osg::BlendFunc from property nodes
3 // Copyright (C) 2008 - 2010 Tim Moore timoore33@gmail.com
4 // Copyright (C) 2013 Thomas Geymayer <tomgey@gmail.com>
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Library General Public
8 // License as published by the Free Software Foundation; either
9 // version 2 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Library General Public License for more details.
16 // You should have received a copy of the GNU Library General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "parseBlendFunc.hxx"
21 #include "EffectBuilder.hxx"
22 #include <simgear/scene/util/StateAttributeFactory.hxx>
23 #include <osg/BlendFunc>
30 //----------------------------------------------------------------------------
31 extern effect::EffectPropertyMap<BlendFunc::BlendFuncMode> blendFuncModes;
33 //----------------------------------------------------------------------------
34 bool parseBlendFunc( osg::StateSet* ss,
35 const SGPropertyNode* src,
36 const SGPropertyNode* dest,
37 const SGPropertyNode* src_rgb,
38 const SGPropertyNode* dest_rgb,
39 const SGPropertyNode* src_alpha,
40 const SGPropertyNode* dest_alpha )
45 BlendFunc::BlendFuncMode src_mode = BlendFunc::ONE;
46 BlendFunc::BlendFuncMode dest_mode = BlendFunc::ZERO;
49 findAttr(blendFuncModes, src, src_mode);
51 findAttr(blendFuncModes, dest, dest_mode);
54 && !(src_rgb || src_alpha || dest_rgb || dest_alpha)
55 && src_mode == BlendFunc::SRC_ALPHA
56 && dest_mode == BlendFunc::ONE_MINUS_SRC_ALPHA )
58 ss->setAttributeAndModes(
59 StateAttributeFactory::instance()->getStandardBlendFunc()
64 BlendFunc* blend_func = new BlendFunc;
66 blend_func->setSource(src_mode);
68 blend_func->setDestination(dest_mode);
72 BlendFunc::BlendFuncMode sourceRGBMode;
73 findAttr(blendFuncModes, src_rgb, sourceRGBMode);
74 blend_func->setSourceRGB(sourceRGBMode);
78 BlendFunc::BlendFuncMode destRGBMode;
79 findAttr(blendFuncModes, dest_rgb, destRGBMode);
80 blend_func->setDestinationRGB(destRGBMode);
84 BlendFunc::BlendFuncMode sourceAlphaMode;
85 findAttr(blendFuncModes, src_alpha, sourceAlphaMode);
86 blend_func->setSourceAlpha(sourceAlphaMode);
90 BlendFunc::BlendFuncMode destAlphaMode;
91 findAttr(blendFuncModes, dest_alpha, destAlphaMode);
92 blend_func->setDestinationAlpha(destAlphaMode);
94 ss->setAttributeAndModes(blend_func);
98 } // namespace simgear