]> git.tdb.fi Git - libs/gl.git/blob - source/pipelinetemplate.cpp
Fix shadowing warnings from older gcc versions
[libs/gl.git] / source / pipelinetemplate.cpp
1 #include <msp/core/maputils.h>
2 #include <msp/datafile/collection.h>
3 #include "ambientocclusion.h"
4 #include "blend.h"
5 #include "bloom.h"
6 #include "colorcurve.h"
7 #include "lighting.h"
8 #include "pipelinetemplate.h"
9 #include "tests.h"
10
11 using namespace std;
12
13 namespace Msp {
14 namespace GL {
15
16 PipelineTemplate::PipelineTemplate():
17         hdr(false),
18         required_multisample(0),
19         max_multisample(0)
20 { }
21
22 PipelineTemplate::~PipelineTemplate()
23 {
24         for(PostProcessorArray::iterator i=postprocessors.begin(); i!=postprocessors.end(); ++i)
25                 delete *i;
26 }
27
28
29 PipelineTemplate::Pass::~Pass()
30 { }
31
32
33 PipelineTemplate::Loader::Loader(PipelineTemplate &t):
34         DataFile::CollectionObjectLoader<PipelineTemplate>(t, 0)
35 {
36         init();
37 }
38
39 PipelineTemplate::Loader::Loader(PipelineTemplate &t, Collection &c):
40         DataFile::CollectionObjectLoader<PipelineTemplate>(t, &c)
41 {
42         init();
43 }
44
45 void PipelineTemplate::Loader::init()
46 {
47         add("ambient_occlusion", &Loader::postprocessor<AmbientOcclusion>);
48         add("bloom", &Loader::postprocessor<Bloom>);
49         add("colorcurve", &Loader::postprocessor<ColorCurve>);
50         add("hdr", &PipelineTemplate::hdr);
51         add("multisample", &Loader::multisample);
52         add("multisample", &Loader::multisample_range);
53         add("pass", &Loader::pass);
54 }
55
56 void PipelineTemplate::Loader::multisample(unsigned samples)
57 {
58         obj.required_multisample = samples;
59         obj.max_multisample = samples;
60 }
61
62 void PipelineTemplate::Loader::multisample_range(unsigned req, unsigned max)
63 {
64         obj.required_multisample = req;
65         obj.max_multisample = max;
66 }
67
68 void PipelineTemplate::Loader::pass(const string &tag, const string &rend)
69 {
70         Pass pss;;
71         pss.tag = tag;
72         pss.renderable_name = rend;
73         if(coll)
74                 load_sub(pss, *coll);
75         else
76                 load_sub(pss);
77
78         obj.passes.push_back(pss);
79 }
80
81 template<typename T>
82 void PipelineTemplate::Loader::postprocessor()
83 {
84         RefPtr<typename T::Template> postproc = new typename T::Template;
85         load_sub(*postproc);
86         obj.postprocessors.push_back(postproc.release());
87 }
88
89
90 PipelineTemplate::Pass::Loader::Loader(Pass &p):
91         DataFile::CollectionObjectLoader<Pass>(p, 0)
92 {
93         init();
94 }
95
96 PipelineTemplate::Pass::Loader::Loader(Pass &p, Collection &c):
97         DataFile::CollectionObjectLoader<Pass>(p, &c)
98 {
99         init();
100 }
101
102 void PipelineTemplate::Pass::Loader::init()
103 {
104         add("blend", &Loader::blend);
105         add("blend", &Loader::blend_predefined);
106         add("depth_test", &Loader::depth_test);
107         add("depth_test", &Loader::depth_test_predefined);
108         add("lighting", &Loader::lighting);
109         add("lighting", &Loader::lighting_inline);
110 }
111
112 void PipelineTemplate::Pass::Loader::blend_predefined(const string &name)
113 {
114         const Blend *bln = 0;
115         if(name=="alpha")
116                 bln = &Blend::alpha();
117         else if(name=="additive")
118                 bln = &Blend::additive();
119         else if(name=="additive_alpha")
120                 bln = &Blend::additive_alpha();
121         else
122                 throw key_error(name);
123
124         obj.blend = bln;
125         obj.blend.keep();
126 }
127
128 void PipelineTemplate::Pass::Loader::blend(BlendFactor src, BlendFactor dest)
129 {
130         obj.blend = new Blend(src, dest);
131 }
132
133 void PipelineTemplate::Pass::Loader::depth_test_predefined(const string &name)
134 {
135         const DepthTest *dtest = 0;
136         if(name=="lequal")
137                 dtest = &DepthTest::lequal();
138         else
139                 throw key_error(name);
140
141         obj.depth_test = dtest;
142         obj.depth_test.keep();
143 }
144
145 void PipelineTemplate::Pass::Loader::depth_test(Predicate pred)
146 {
147         obj.depth_test = new DepthTest(pred);
148 }
149
150 void PipelineTemplate::Pass::Loader::lighting_inline()
151 {
152         RefPtr<Lighting> lightn = new Lighting;
153         load_sub(*lightn);
154         obj.lighting = lightn;
155 }
156
157 void PipelineTemplate::Pass::Loader::lighting(const string &name)
158 {
159         obj.lighting = &get_collection().get<Lighting>(name);
160         obj.lighting.keep();
161 }
162
163 /*void PipelineTemplate::Pass::Loader::scene(const string &name)
164 {
165         obj.default_renderable = get_collection().get<Scene>(name);
166 }*/
167
168 } // namespace GL
169 } // namespace Msp