1 #include <msp/core/maputils.h>
2 #include <msp/datafile/collection.h>
3 #include <msp/strings/format.h>
4 #include "ambientocclusion.h"
7 #include "colorcurve.h"
10 #include "resources.h"
12 #include "sequencetemplate.h"
19 SequenceTemplate::SequenceTemplate():
22 required_multisample(0),
29 SequenceTemplate::~SequenceTemplate()
31 for(const PostProcessor &p: postprocessors)
32 delete p.postprocessor_template;
36 SequenceTemplate::PostProcessorRegistry &SequenceTemplate::get_postprocessor_registry()
38 static PostProcessorRegistry registry;
39 static bool initialized = false;
42 registry.register_type<AmbientOcclusion>("ambient_occlusion");
43 registry.register_type<Bloom>("bloom");
44 registry.register_type<ColorCurve>("colorcurve");
51 SequenceTemplate::Step::~Step()
55 SequenceTemplate::PostProcessor::PostProcessor(GL::PostProcessor::Template *ppt):
56 postprocessor_template(ppt)
60 SequenceTemplate::PostProcLoader::PostProcLoader()
62 get_postprocessor_registry().invoke_all(*this);
66 SequenceTemplate::Loader::Loader(SequenceTemplate &t, Collection &c):
67 DataFile::CollectionObjectLoader<SequenceTemplate, Resources>(t, &c)
69 add("hdr", &SequenceTemplate::hdr);
70 add("alpha", &SequenceTemplate::alpha);
71 add("clear", &Loader::clear);
72 add("multisample", &Loader::multisample);
73 add("multisample", &Loader::multisample_range);
74 add("postprocessor", &Loader::postprocessor);
75 add("step", &Loader::step);
76 add("step", &Loader::step_with_slot);
79 add("pass", &Loader::step_with_slot);
82 void SequenceTemplate::Loader::postprocessor_loaded()
84 obj.postprocessors.push_back(get_postprocessor_template());
87 void SequenceTemplate::Loader::clear()
91 obj.clear_enabled = true;
94 void SequenceTemplate::Loader::multisample(unsigned samples)
96 obj.required_multisample = samples;
97 obj.max_multisample = samples;
100 void SequenceTemplate::Loader::multisample_range(unsigned req, unsigned max)
102 obj.required_multisample = req;
103 obj.max_multisample = max;
106 void SequenceTemplate::Loader::postprocessor(const string &slot)
111 pp.postprocessor_template = ldr.get_postprocessor_template();
113 obj.postprocessors.push_back(pp);
116 void SequenceTemplate::Loader::step(const string &tag)
118 step_with_slot(tag, string());
121 void SequenceTemplate::Loader::step_with_slot(const string &tag, const string &rend)
125 stp.slot_name = rend;
128 Step::Loader ldr(stp, *coll);
129 ldr.set_inline_base_name(format("%s/%d.step", get_source(), obj.steps.size()));
135 obj.steps.push_back(stp);
139 SequenceTemplate::ClearLoader::ClearLoader(SequenceTemplate &t):
140 ObjectLoader<SequenceTemplate>(t)
142 add("color", &ClearLoader::color);
143 add("depth", &ClearLoader::depth);
144 add("stencil", &ClearLoader::stencil);
147 void SequenceTemplate::ClearLoader::color(float r, float g, float b, float a)
149 obj.clear_colors.push_back(Color(r, g, b, a));
152 void SequenceTemplate::ClearLoader::depth(float d)
157 void SequenceTemplate::ClearLoader::stencil(int s)
159 obj.clear_stencil = s;
163 SequenceTemplate::Step::Loader::Loader(Step &p, Collection *c):
164 DataFile::CollectionObjectLoader<Step>(p, c)
166 add("blend", &Loader::blend);
167 add("blend", &Loader::blend_factors);
168 add("depth_test", &Loader::depth_test);
169 add("depth_test", &Loader::depth_compare);
170 add("lighting", &Loader::lighting);
171 add("lighting", &Loader::lighting_inline);
172 add("object", &Loader::object);
173 add("scene", &Loader::scene);
174 add("stencil_test", &Loader::stencil_test);
177 void SequenceTemplate::Step::Loader::set_inline_base_name(const string &n)
179 inline_base_name = n;
182 void SequenceTemplate::Step::Loader::blend()
187 void SequenceTemplate::Step::Loader::blend_factors(BlendFactor src, BlendFactor dest)
189 obj.blend = Blend(src, dest);
192 void SequenceTemplate::Step::Loader::depth_test()
194 load_sub(obj.depth_test);
197 void SequenceTemplate::Step::Loader::depth_compare(Predicate c)
199 obj.depth_test = DepthTest(c);
202 void SequenceTemplate::Step::Loader::lighting_inline()
204 RefPtr<Lighting> lightn = new Lighting;
206 get_collection().add(inline_base_name+".lightn", lightn.get());
207 obj.lighting = lightn.release();
210 void SequenceTemplate::Step::Loader::lighting(const string &name)
212 obj.lighting = &get_collection().get<Lighting>(name);
215 void SequenceTemplate::Step::Loader::object(const string &name)
217 obj.default_renderable = &get_collection().get<GL::Object>(name);
220 void SequenceTemplate::Step::Loader::scene(const string &name)
222 obj.default_renderable = &get_collection().get<Scene>(name);
225 void SequenceTemplate::Step::Loader::stencil_test()
227 load_sub(obj.stencil_test);