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"
8 #include "environmentmap.h"
11 #include "resources.h"
13 #include "sequencetemplate.h"
14 #include "shadowmap.h"
22 SequenceTemplate::~SequenceTemplate()
24 for(const Renderable &r: renderables)
25 delete r.effect_template;
26 for(const PostProcessor &p: postprocessors)
27 delete p.postprocessor_template;
31 SequenceTemplate::TemplateRegistry<GL::PostProcessor> &SequenceTemplate::get_registry<GL::PostProcessor>()
33 static TemplateRegistry<GL::PostProcessor> registry;
34 static bool initialized = false;
37 registry.register_type<AmbientOcclusion::Template>("ambient_occlusion");
38 registry.register_type<Bloom::Template>("bloom");
39 registry.register_type<ColorCurve::Template>("colorcurve");
46 SequenceTemplate::TemplateRegistry<Effect> &SequenceTemplate::get_registry<Effect>()
48 static TemplateRegistry<Effect> registry;
49 static bool initialized = false;
52 registry.register_type<EnvironmentMap::Template>("environment_map");
53 registry.register_type<ShadowMap::Template>("shadow_map");
54 registry.register_type<Sky::Template>("sky");
61 SequenceTemplate::PostProcessor::PostProcessor(GL::PostProcessor::Template *ppt):
62 postprocessor_template(ppt)
66 DataFile::Loader::ActionMap SequenceTemplate::Loader::shared_actions;
68 SequenceTemplate::Loader::Loader(SequenceTemplate &t, Collection &c):
69 CollectionObjectLoader<SequenceTemplate>(t, &c)
71 set_actions(shared_actions);
74 void SequenceTemplate::Loader::init_actions()
76 add("hdr", &SequenceTemplate::hdr);
77 add("clear", &Loader::clear);
78 add("effect", &Loader::effect);
79 add("multisample", &Loader::multisample);
80 add("multisample", &Loader::multisample_range);
81 add("postprocessor", &Loader::postprocessor);
82 add("postprocessor", &Loader::postprocessor_with_slot);
83 add("renderable", &Loader::renderable);
84 add("renderable", &Loader::renderable_with_default);
85 add("sequence", &Loader::sequence);
86 add("step", &Loader::step);
89 void SequenceTemplate::Loader::clear()
93 obj.clear_enabled = true;
96 void SequenceTemplate::Loader::effect(const string &slot)
98 TemplateLoader<Effect> ldr(get_collection());
101 rend.slot_name = slot;
102 rend.effect_template = ldr.get_object();
103 obj.renderables.push_back(rend);
106 void SequenceTemplate::Loader::multisample(unsigned samples)
108 obj.required_multisample = samples;
109 obj.max_multisample = samples;
112 void SequenceTemplate::Loader::multisample_range(unsigned req, unsigned max)
114 obj.required_multisample = req;
115 obj.max_multisample = max;
118 void SequenceTemplate::Loader::postprocessor()
120 postprocessor_with_slot(string());
123 void SequenceTemplate::Loader::postprocessor_with_slot(const string &slot)
125 TemplateLoader<GL::PostProcessor> ldr(get_collection());
128 pp.postprocessor_template = ldr.get_object();
130 obj.postprocessors.push_back(pp);
133 void SequenceTemplate::Loader::renderable(const string &slot)
136 rend.slot_name = slot;
137 obj.renderables.push_back(rend);
140 void SequenceTemplate::Loader::renderable_with_default(const string &slot, const string &name)
143 rend.renderable = &get_collection().get<GL::Renderable>(name);
144 rend.slot_name = slot;
145 obj.renderables.push_back(rend);
148 void SequenceTemplate::Loader::sequence(const string &slot, const string &name)
151 rend.sequence_template = &get_collection().get<SequenceTemplate>(name);
152 rend.slot_name = slot;
153 SequenceLoader ldr(rend);
155 obj.renderables.push_back(rend);
158 void SequenceTemplate::Loader::step(const string &tag, const string &rend)
162 stp.renderable_name = rend;
163 Step::Loader ldr(stp, get_collection());
164 ldr.set_inline_base_name(format("%s/%d.step", get_source(), obj.steps.size()));
167 obj.steps.push_back(stp);
171 DataFile::Loader::ActionMap SequenceTemplate::ClearLoader::shared_actions;
173 SequenceTemplate::ClearLoader::ClearLoader(SequenceTemplate &t):
174 ObjectLoader<SequenceTemplate>(t)
176 set_actions(shared_actions);
179 void SequenceTemplate::ClearLoader::init_actions()
181 add("color", &ClearLoader::color);
182 add("depth", &ClearLoader::depth);
183 add("stencil", &ClearLoader::stencil);
186 void SequenceTemplate::ClearLoader::color(float r, float g, float b, float a)
188 obj.clear_colors.emplace_back(r, g, b, a);
191 void SequenceTemplate::ClearLoader::depth(float d)
196 void SequenceTemplate::ClearLoader::stencil(int s)
198 obj.clear_stencil = s;
202 DataFile::Loader::ActionMap SequenceTemplate::SequenceLoader::shared_actions;
204 SequenceTemplate::SequenceLoader::SequenceLoader(Renderable &r):
205 ObjectLoader<Renderable>(r)
207 set_actions(shared_actions);
210 void SequenceTemplate::SequenceLoader::init_actions()
212 add("renderable", &SequenceLoader::renderable);
215 void SequenceTemplate::SequenceLoader::renderable(const string &slot, const string &name)
217 obj.sequence_renderables[slot] = name;
221 DataFile::Loader::ActionMap SequenceTemplate::Step::Loader::shared_actions;
223 SequenceTemplate::Step::Loader::Loader(Step &p, Collection &c):
224 DataFile::CollectionObjectLoader<Step>(p, &c)
226 set_actions(shared_actions);
229 void SequenceTemplate::Step::Loader::init_actions()
231 add("depth_test", &Loader::depth_test);
232 add("depth_test", &Loader::depth_compare);
233 add("lighting", &Loader::lighting);
234 add("lighting", &Loader::lighting_inline);
235 add("stencil_test", &Loader::stencil_test);
238 void SequenceTemplate::Step::Loader::set_inline_base_name(const string &n)
240 inline_base_name = n;
243 void SequenceTemplate::Step::Loader::depth_test()
245 load_sub(obj.depth_test);
248 void SequenceTemplate::Step::Loader::depth_compare(Predicate c)
250 obj.depth_test = DepthTest(c);
253 void SequenceTemplate::Step::Loader::lighting_inline()
255 RefPtr<Lighting> lightn = new Lighting;
256 load_sub(*lightn, get_collection());
257 get_collection().add(inline_base_name+".lightn", lightn.get());
258 obj.lighting = lightn.release();
261 void SequenceTemplate::Step::Loader::lighting(const string &name)
263 obj.lighting = &get_collection().get<Lighting>(name);
266 void SequenceTemplate::Step::Loader::stencil_test()
268 load_sub(obj.stencil_test);