]> git.mxchange.org Git - simgear.git/blob - simgear/scene/material/EffectBuilder.cxx
Work around apparent OSG 3.2.0 normal binding bug.
[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 using std::string;
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                          const SGReaderWriterOptions* options)
47 {
48     if (!prop)
49         return string();
50     const SGPropertyNode* useProp = prop->getChild("use");
51     if (!useProp)
52         return string();
53     string propName = useProp->getStringValue();
54     SGPropertyNode_ptr propRoot;
55     if (propName[0] == '/') {
56         return propName;
57     } else if ((propRoot = options->getPropertyNode())) {
58         string result = propRoot->getPath();
59         result.append("/");
60         result.append(propName);
61         return result;
62     } else {
63         throw effect::
64             BuilderException("No property root to use with relative name "
65                              + propName);
66     }
67         
68     return useProp->getStringValue();
69 }
70
71 namespace effect
72 {
73 BuilderException::BuilderException()
74 {
75 }
76
77 BuilderException::BuilderException(const char* message, const char* origin)
78   : sg_exception(message, origin)
79 {
80 }
81
82 BuilderException::BuilderException(const std::string& message,
83                                    const std::string& origin)
84   : sg_exception(message, origin)
85 {
86 }
87
88 BuilderException::~BuilderException() throw()
89 {
90
91 }
92 }
93
94 bool isAttributeActive(Effect* effect, const SGPropertyNode* prop)
95 {
96     const SGPropertyNode* activeProp
97         = getEffectPropertyChild(effect, prop, "active");
98     return !activeProp || activeProp->getValue<bool>();
99 }
100
101 namespace effect
102 {
103 const char* colorFields[] = {"red", "green", "blue", "alpha"};
104 }
105   
106 PassAttributeBuilder::~PassAttributeBuilder()
107 {
108 }
109   
110 } // of namespace simgear
111
112
113
114
115