]> git.tdb.fi Git - libs/gl.git/blob - source/pipelinetemplate.cpp
Remove sized L and LA pixel formats
[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         alpha(false),
19         required_multisample(0),
20         max_multisample(0)
21 { }
22
23 PipelineTemplate::~PipelineTemplate()
24 {
25         for(PostProcessorArray::iterator i=postprocessors.begin(); i!=postprocessors.end(); ++i)
26                 delete i->postprocessor_template;
27 }
28
29
30 PipelineTemplate::PostProcessorRegistry &PipelineTemplate::get_postprocessor_registry()
31 {
32         static PostProcessorRegistry registry;
33         static bool initialized = false;
34         if(!initialized)
35         {
36                 registry.register_type<AmbientOcclusion>("ambient_occlusion");
37                 registry.register_type<Bloom>("bloom");
38                 registry.register_type<ColorCurve>("colorcurve");
39                 initialized = true;
40         }
41         return registry;
42 }
43
44
45 PipelineTemplate::Pass::~Pass()
46 { }
47
48
49 PipelineTemplate::PostProcessor::PostProcessor(GL::PostProcessor::Template *ppt):
50         postprocessor_template(ppt)
51 { }
52
53
54 PipelineTemplate::PostProcLoader::PostProcLoader()
55 {
56         get_postprocessor_registry().add_all(*this);
57 }
58
59
60 PipelineTemplate::Loader::Loader(PipelineTemplate &t):
61         DataFile::CollectionObjectLoader<PipelineTemplate>(t, 0)
62 {
63         init();
64 }
65
66 PipelineTemplate::Loader::Loader(PipelineTemplate &t, Collection &c):
67         DataFile::CollectionObjectLoader<PipelineTemplate>(t, &c)
68 {
69         init();
70 }
71
72 void PipelineTemplate::Loader::init()
73 {
74         add("hdr", &PipelineTemplate::hdr);
75         add("alpha", &PipelineTemplate::alpha);
76         add("multisample", &Loader::multisample);
77         add("multisample", &Loader::multisample_range);
78         add("pass", &Loader::pass);
79         add("postprocessor", &Loader::postprocessor);
80 }
81
82 void PipelineTemplate::Loader::postprocessor_loaded()
83 {
84         obj.postprocessors.push_back(get_postprocessor_template());
85 }
86
87 void PipelineTemplate::Loader::multisample(unsigned samples)
88 {
89         obj.required_multisample = samples;
90         obj.max_multisample = samples;
91 }
92
93 void PipelineTemplate::Loader::multisample_range(unsigned req, unsigned max)
94 {
95         obj.required_multisample = req;
96         obj.max_multisample = max;
97 }
98
99 void PipelineTemplate::Loader::pass(const string &tag, const string &rend)
100 {
101         Pass pss;;
102         pss.tag = tag;
103         pss.renderable_name = rend;
104         if(coll)
105                 load_sub(pss, *coll);
106         else
107                 load_sub(pss);
108
109         obj.passes.push_back(pss);
110 }
111
112 void PipelineTemplate::Loader::postprocessor(const std::string &slot)
113 {
114         PostProcLoader ldr;
115         load_sub_with(ldr);
116         PostProcessor pp;
117         pp.postprocessor_template = ldr.get_postprocessor_template();
118         pp.slot_name = slot;
119         obj.postprocessors.push_back(pp);
120 }
121
122
123 PipelineTemplate::Pass::Loader::Loader(Pass &p):
124         DataFile::CollectionObjectLoader<Pass>(p, 0)
125 {
126         init();
127 }
128
129 PipelineTemplate::Pass::Loader::Loader(Pass &p, Collection &c):
130         DataFile::CollectionObjectLoader<Pass>(p, &c)
131 {
132         init();
133 }
134
135 void PipelineTemplate::Pass::Loader::init()
136 {
137         add("blend", &Loader::blend);
138         add("blend", &Loader::blend_predefined);
139         add("depth_test", &Loader::depth_test);
140         add("depth_test", &Loader::depth_test_predefined);
141         add("lighting", &Loader::lighting);
142         add("lighting", &Loader::lighting_inline);
143 }
144
145 void PipelineTemplate::Pass::Loader::blend_predefined(const string &name)
146 {
147         const Blend *bln = 0;
148         if(name=="alpha")
149                 bln = &Blend::alpha();
150         else if(name=="additive")
151                 bln = &Blend::additive();
152         else if(name=="additive_alpha")
153                 bln = &Blend::additive_alpha();
154         else
155                 throw key_error(name);
156
157         obj.blend = bln;
158         obj.blend.keep();
159 }
160
161 void PipelineTemplate::Pass::Loader::blend(BlendFactor src, BlendFactor dest)
162 {
163         obj.blend = new Blend(src, dest);
164 }
165
166 void PipelineTemplate::Pass::Loader::depth_test_predefined(const string &name)
167 {
168         const DepthTest *dtest = 0;
169         if(name=="lequal")
170                 dtest = &DepthTest::lequal();
171         else
172                 throw key_error(name);
173
174         obj.depth_test = dtest;
175         obj.depth_test.keep();
176 }
177
178 void PipelineTemplate::Pass::Loader::depth_test(Predicate pred)
179 {
180         obj.depth_test = new DepthTest(pred);
181 }
182
183 void PipelineTemplate::Pass::Loader::lighting_inline()
184 {
185         RefPtr<Lighting> lightn = new Lighting;
186         load_sub(*lightn);
187         obj.lighting = lightn;
188 }
189
190 void PipelineTemplate::Pass::Loader::lighting(const string &name)
191 {
192         obj.lighting = &get_collection().get<Lighting>(name);
193         obj.lighting.keep();
194 }
195
196 /*void PipelineTemplate::Pass::Loader::scene(const string &name)
197 {
198         obj.default_renderable = get_collection().get<Scene>(name);
199 }*/
200
201 } // namespace GL
202 } // namespace Msp