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()
21 for(const PostProcessor &p: postprocessors)
22 delete p.postprocessor_template;
26 SequenceTemplate::PostProcessorRegistry &SequenceTemplate::get_postprocessor_registry()
28 static PostProcessorRegistry registry;
29 static bool initialized = false;
32 registry.register_type<AmbientOcclusion>("ambient_occlusion");
33 registry.register_type<Bloom>("bloom");
34 registry.register_type<ColorCurve>("colorcurve");
41 SequenceTemplate::PostProcessor::PostProcessor(GL::PostProcessor::Template *ppt):
42 postprocessor_template(ppt)
46 SequenceTemplate::PostProcLoader::PostProcLoader()
48 get_postprocessor_registry().invoke_all(*this);
52 SequenceTemplate::Loader::Loader(SequenceTemplate &t, Collection &c):
53 DataFile::CollectionObjectLoader<SequenceTemplate, Resources>(t, &c)
55 add("hdr", &SequenceTemplate::hdr);
56 add("alpha", &SequenceTemplate::alpha);
57 add("clear", &Loader::clear);
58 add("multisample", &Loader::multisample);
59 add("multisample", &Loader::multisample_range);
60 add("postprocessor", &Loader::postprocessor);
61 add("step", &Loader::step);
62 add("step", &Loader::step_with_slot);
65 add("pass", &Loader::step_with_slot);
68 void SequenceTemplate::Loader::postprocessor_loaded()
70 obj.postprocessors.push_back(get_postprocessor_template());
73 void SequenceTemplate::Loader::clear()
77 obj.clear_enabled = true;
80 void SequenceTemplate::Loader::multisample(unsigned samples)
82 obj.required_multisample = samples;
83 obj.max_multisample = samples;
86 void SequenceTemplate::Loader::multisample_range(unsigned req, unsigned max)
88 obj.required_multisample = req;
89 obj.max_multisample = max;
92 void SequenceTemplate::Loader::postprocessor(const string &slot)
97 pp.postprocessor_template = ldr.get_postprocessor_template();
99 obj.postprocessors.push_back(pp);
102 void SequenceTemplate::Loader::step(const string &tag)
104 step_with_slot(tag, string());
107 void SequenceTemplate::Loader::step_with_slot(const string &tag, const string &rend)
111 stp.slot_name = rend;
112 Step::Loader ldr(stp, *coll);
113 ldr.set_inline_base_name(format("%s/%d.step", get_source(), obj.steps.size()));
116 obj.steps.push_back(stp);
120 SequenceTemplate::ClearLoader::ClearLoader(SequenceTemplate &t):
121 ObjectLoader<SequenceTemplate>(t)
123 add("color", &ClearLoader::color);
124 add("depth", &ClearLoader::depth);
125 add("stencil", &ClearLoader::stencil);
128 void SequenceTemplate::ClearLoader::color(float r, float g, float b, float a)
130 obj.clear_colors.push_back(Color(r, g, b, a));
133 void SequenceTemplate::ClearLoader::depth(float d)
138 void SequenceTemplate::ClearLoader::stencil(int s)
140 obj.clear_stencil = s;
144 SequenceTemplate::Step::Loader::Loader(Step &p, Collection &c):
145 DataFile::CollectionObjectLoader<Step>(p, &c)
147 add("blend", &Loader::blend);
148 add("blend", &Loader::blend_factors);
149 add("depth_test", &Loader::depth_test);
150 add("depth_test", &Loader::depth_compare);
151 add("lighting", &Loader::lighting);
152 add("lighting", &Loader::lighting_inline);
153 add("object", &Loader::object);
154 add("scene", &Loader::scene);
155 add("stencil_test", &Loader::stencil_test);
158 void SequenceTemplate::Step::Loader::set_inline_base_name(const string &n)
160 inline_base_name = n;
163 void SequenceTemplate::Step::Loader::blend()
168 void SequenceTemplate::Step::Loader::blend_factors(BlendFactor src, BlendFactor dest)
170 obj.blend = Blend(src, dest);
173 void SequenceTemplate::Step::Loader::depth_test()
175 load_sub(obj.depth_test);
178 void SequenceTemplate::Step::Loader::depth_compare(Predicate c)
180 obj.depth_test = DepthTest(c);
183 void SequenceTemplate::Step::Loader::lighting_inline()
185 RefPtr<Lighting> lightn = new Lighting;
186 load_sub(*lightn, get_collection());
187 get_collection().add(inline_base_name+".lightn", lightn.get());
188 obj.lighting = lightn.release();
191 void SequenceTemplate::Step::Loader::lighting(const string &name)
193 obj.lighting = &get_collection().get<Lighting>(name);
196 void SequenceTemplate::Step::Loader::object(const string &name)
198 obj.default_renderable = &get_collection().get<GL::Object>(name);
201 void SequenceTemplate::Step::Loader::scene(const string &name)
203 obj.default_renderable = &get_collection().get<Scene>(name);
206 void SequenceTemplate::Step::Loader::stencil_test()
208 load_sub(obj.stencil_test);