]> git.mxchange.org Git - simgear.git/blob - simgear/scene/material/EffectBuilder.cxx
Remove redundant inclusion of math/SGMath.hxx
[simgear.git] / simgear / scene / material / EffectBuilder.cxx
1 #ifdef HAVE_CONFIG_H
2 #  include <simgear_config.h>
3 #endif
4
5 #include <simgear/scene/util/SGReaderWriterOptions.hxx>
6 #include <simgear/scene/tgdb/userdata.hxx>
7
8 #include "EffectBuilder.hxx"
9 #include "Effect.hxx"
10
11 namespace simgear
12 {
13
14 // Given a property node from a pass, get its value either from it or
15 // from the effect parameters.
16 const SGPropertyNode* getEffectPropertyNode(Effect* effect,
17                                             const SGPropertyNode* prop)
18 {
19     if (!prop)
20         return 0;
21     if (prop->nChildren() > 0) {
22         const SGPropertyNode* useProp = prop->getChild("use");
23         if (!useProp || !effect->parametersProp)
24             return prop;
25         return effect->parametersProp->getNode(useProp->getStringValue());
26     }
27     return prop;
28 }
29
30 // Get a named child property from pass parameters or effect
31 // parameters.
32 const SGPropertyNode* getEffectPropertyChild(Effect* effect,
33                                              const SGPropertyNode* prop,
34                                              const char* name)
35 {
36     const SGPropertyNode* child = prop->getChild(name);
37     if (!child)
38         return 0;
39     else
40         return getEffectPropertyNode(effect, child);
41 }
42
43 string getGlobalProperty(const SGPropertyNode* prop,
44                          const SGReaderWriterOptions* options)
45 {
46     if (!prop)
47         return string();
48     const SGPropertyNode* useProp = prop->getChild("use");
49     if (!useProp)
50         return string();
51     string propName = useProp->getStringValue();
52     SGPropertyNode_ptr propRoot;
53     if (propName[0] == '/') {
54         return propName;
55     } else if ((propRoot = options->getPropertyNode())) {
56         string result = propRoot->getPath();
57         result.append("/");
58         result.append(propName);
59         return result;
60     } else {
61         throw effect::
62             BuilderException("No property root to use with relative name "
63                              + propName);
64     }
65         
66     return useProp->getStringValue();
67 }
68
69 namespace effect
70 {
71 BuilderException::BuilderException()
72 {
73 }
74
75 BuilderException::BuilderException(const char* message, const char* origin)
76   : sg_exception(message, origin)
77 {
78 }
79
80 BuilderException::BuilderException(const std::string& message,
81                                    const std::string& origin)
82   : sg_exception(message, origin)
83 {
84 }
85
86 BuilderException::~BuilderException() throw()
87 {
88
89 }
90 }
91
92 bool isAttributeActive(Effect* effect, const SGPropertyNode* prop)
93 {
94     const SGPropertyNode* activeProp
95         = getEffectPropertyChild(effect, prop, "active");
96     return !activeProp || activeProp->getValue<bool>();
97 }
98
99 namespace effect
100 {
101 const char* colorFields[] = {"red", "green", "blue", "alpha"};
102 }
103   
104 PassAttributeBuilder::~PassAttributeBuilder()
105 {
106 }
107   
108 } // of namespace simgear
109
110
111
112
113