]> git.mxchange.org Git - simgear.git/blob - simgear/scene/material/parseBlendFunc_test.cxx
Work around apparent OSG 3.2.0 normal binding bug.
[simgear.git] / simgear / scene / material / parseBlendFunc_test.cxx
1 #include <simgear/compiler.h>
2
3 #include "parseBlendFunc.hxx"
4 #include <simgear/props/props.hxx>
5 #include <osg/BlendFunc>
6
7 #include <iostream>
8
9 #define COMPARE(a, b) \
10   if( (a) != (b) ) \
11   { \
12     std::cerr << "line " << __LINE__ << ": failed: "\
13               << #a << " != " << #b << std::endl; \
14     return 1; \
15   }
16
17 #define VERIFY(a) \
18   if( !(a) ) \
19   { \
20     std::cerr << "line " << __LINE__ << ": failed: "\
21               << #a << std::endl; \
22     return 1; \
23   }
24     
25 int main (int ac, char ** av)
26 {
27   osg::ref_ptr<osg::StateSet> ss = new osg::StateSet;
28
29   // default blendfunc
30   VERIFY( simgear::parseBlendFunc(ss) );
31
32   osg::BlendFunc* bf = dynamic_cast<osg::BlendFunc*>(
33     ss->getAttribute(osg::StateAttribute::BLENDFUNC)
34   );
35
36   VERIFY( bf );
37   COMPARE(bf->getSource(),      osg::BlendFunc::SRC_ALPHA);
38   COMPARE(bf->getDestination(), osg::BlendFunc::ONE_MINUS_SRC_ALPHA);
39   COMPARE(bf->getSource(),      bf->getSourceAlpha());
40   COMPARE(bf->getDestination(), bf->getDestinationAlpha());
41
42   // now set some values
43   SGPropertyNode_ptr src = new SGPropertyNode,
44                      dest = new SGPropertyNode;
45
46   src->setStringValue("src-alpha");
47   dest->setStringValue("constant-color");
48
49   VERIFY( simgear::parseBlendFunc(ss, src, dest) );
50
51   bf = dynamic_cast<osg::BlendFunc*>(
52       ss->getAttribute(osg::StateAttribute::BLENDFUNC)
53   );
54
55   VERIFY( bf );
56   COMPARE(bf->getSource(),      osg::BlendFunc::SRC_ALPHA);
57   COMPARE(bf->getDestination(), osg::BlendFunc::CONSTANT_COLOR);
58   COMPARE(bf->getSource(),      bf->getSourceAlpha());
59   COMPARE(bf->getDestination(), bf->getDestinationAlpha());
60
61   std::cout << "all tests passed successfully!" << std::endl;
62   return 0;
63 }