]> git.mxchange.org Git - simgear.git/blob - simgear/scene/material/EffectBuilder.cxx
Merge branch 'zan/stencil'
[simgear.git] / simgear / scene / material / EffectBuilder.cxx
1 #ifdef HAVE_CONFIG_H
2 #  include <simgear_config.h>
3 #endif
4
5 #include <simgear/scene/tgdb/userdata.hxx>
6
7 #include <simgear/math/SGMath.hxx>
8
9 #include "EffectBuilder.hxx"
10 #include "Effect.hxx"
11
12 namespace simgear
13 {
14
15 // Given a property node from a pass, get its value either from it or
16 // from the effect parameters.
17 const SGPropertyNode* getEffectPropertyNode(Effect* effect,
18                                             const SGPropertyNode* prop)
19 {
20     if (!prop)
21         return 0;
22     if (prop->nChildren() > 0) {
23         const SGPropertyNode* useProp = prop->getChild("use");
24         if (!useProp || !effect->parametersProp)
25             return prop;
26         return effect->parametersProp->getNode(useProp->getStringValue());
27     }
28     return prop;
29 }
30
31 // Get a named child property from pass parameters or effect
32 // parameters.
33 const SGPropertyNode* getEffectPropertyChild(Effect* effect,
34                                              const SGPropertyNode* prop,
35                                              const char* name)
36 {
37     const SGPropertyNode* child = prop->getChild(name);
38     if (!child)
39         return 0;
40     else
41         return getEffectPropertyNode(effect, child);
42 }
43
44 string getGlobalProperty(const SGPropertyNode* prop)
45 {
46     if (!prop)
47         return string();
48     const SGPropertyNode* useProp = prop->getChild("use");
49     if (!useProp)
50         return string();
51     return useProp->getStringValue();
52 }
53
54 namespace effect
55 {
56 BuilderException::BuilderException()
57 {
58 }
59
60 BuilderException::BuilderException(const char* message, const char* origin)
61   : sg_exception(message, origin)
62 {
63 }
64
65 BuilderException::BuilderException(const std::string& message,
66                                    const std::string& origin)
67   : sg_exception(message, origin)
68 {
69 }
70
71 BuilderException::~BuilderException() throw()
72 {
73
74 }
75 }
76
77 bool isAttributeActive(Effect* effect, const SGPropertyNode* prop)
78 {
79     const SGPropertyNode* activeProp
80         = getEffectPropertyChild(effect, prop, "active");
81     return !activeProp || activeProp->getValue<bool>();
82 }
83
84 namespace effect
85 {
86 const char* colorFields[] = {"red", "green", "blue", "alpha"};
87 }
88 }