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