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