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("alpha", &SequenceTemplate::alpha);
78 add("clear", &Loader::clear);
79 add("effect", &Loader::effect);
80 add("multisample", &Loader::multisample);
81 add("multisample", &Loader::multisample_range);
82 add("postprocessor", &Loader::postprocessor);
83 add("postprocessor", &Loader::postprocessor_with_slot);
84 add("renderable", &Loader::renderable);
85 add("renderable", &Loader::renderable_with_default);
86 add("sequence", &Loader::sequence);
87 add("step", &Loader::step);
90 void SequenceTemplate::Loader::clear()
94 obj.clear_enabled = true;
97 void SequenceTemplate::Loader::effect(const string &slot)
99 TemplateLoader<Effect> ldr(get_collection());
102 rend.slot_name = slot;
103 rend.effect_template = ldr.get_object();
104 obj.renderables.push_back(rend);
107 void SequenceTemplate::Loader::multisample(unsigned samples)
109 obj.required_multisample = samples;
110 obj.max_multisample = samples;
113 void SequenceTemplate::Loader::multisample_range(unsigned req, unsigned max)
115 obj.required_multisample = req;
116 obj.max_multisample = max;
119 void SequenceTemplate::Loader::postprocessor()
121 postprocessor_with_slot(string());
124 void SequenceTemplate::Loader::postprocessor_with_slot(const string &slot)
126 TemplateLoader<GL::PostProcessor> ldr(get_collection());
129 pp.postprocessor_template = ldr.get_object();
131 obj.postprocessors.push_back(pp);
134 void SequenceTemplate::Loader::renderable(const string &slot)
137 rend.slot_name = slot;
138 obj.renderables.push_back(rend);
141 void SequenceTemplate::Loader::renderable_with_default(const string &slot, const string &name)
144 rend.renderable = &get_collection().get<GL::Renderable>(name);
145 rend.slot_name = slot;
146 obj.renderables.push_back(rend);
149 void SequenceTemplate::Loader::sequence(const string &slot, const string &name)
152 rend.sequence_template = &get_collection().get<SequenceTemplate>(name);
153 rend.slot_name = slot;
154 SequenceLoader ldr(rend);
156 obj.renderables.push_back(rend);
159 void SequenceTemplate::Loader::step(const string &tag, const string &rend)
163 stp.renderable_name = rend;
164 Step::Loader ldr(stp, get_collection());
165 ldr.set_inline_base_name(format("%s/%d.step", get_source(), obj.steps.size()));
168 obj.steps.push_back(stp);
172 DataFile::Loader::ActionMap SequenceTemplate::ClearLoader::shared_actions;
174 SequenceTemplate::ClearLoader::ClearLoader(SequenceTemplate &t):
175 ObjectLoader<SequenceTemplate>(t)
177 set_actions(shared_actions);
180 void SequenceTemplate::ClearLoader::init_actions()
182 add("color", &ClearLoader::color);
183 add("depth", &ClearLoader::depth);
184 add("stencil", &ClearLoader::stencil);
187 void SequenceTemplate::ClearLoader::color(float r, float g, float b, float a)
189 obj.clear_colors.push_back(Color(r, g, b, a));
192 void SequenceTemplate::ClearLoader::depth(float d)
197 void SequenceTemplate::ClearLoader::stencil(int s)
199 obj.clear_stencil = s;
203 DataFile::Loader::ActionMap SequenceTemplate::SequenceLoader::shared_actions;
205 SequenceTemplate::SequenceLoader::SequenceLoader(Renderable &r):
206 ObjectLoader<Renderable>(r)
208 set_actions(shared_actions);
211 void SequenceTemplate::SequenceLoader::init_actions()
213 add("renderable", &SequenceLoader::renderable);
216 void SequenceTemplate::SequenceLoader::renderable(const string &slot, const string &name)
218 obj.sequence_renderables[slot] = name;
222 DataFile::Loader::ActionMap SequenceTemplate::Step::Loader::shared_actions;
224 SequenceTemplate::Step::Loader::Loader(Step &p, Collection &c):
225 DataFile::CollectionObjectLoader<Step>(p, &c)
227 set_actions(shared_actions);
230 void SequenceTemplate::Step::Loader::init_actions()
232 add("depth_test", &Loader::depth_test);
233 add("depth_test", &Loader::depth_compare);
234 add("lighting", &Loader::lighting);
235 add("lighting", &Loader::lighting_inline);
236 add("stencil_test", &Loader::stencil_test);
239 void SequenceTemplate::Step::Loader::set_inline_base_name(const string &n)
241 inline_base_name = n;
244 void SequenceTemplate::Step::Loader::depth_test()
246 load_sub(obj.depth_test);
249 void SequenceTemplate::Step::Loader::depth_compare(Predicate c)
251 obj.depth_test = DepthTest(c);
254 void SequenceTemplate::Step::Loader::lighting_inline()
256 RefPtr<Lighting> lightn = new Lighting;
257 load_sub(*lightn, get_collection());
258 get_collection().add(inline_base_name+".lightn", lightn.get());
259 obj.lighting = lightn.release();
262 void SequenceTemplate::Step::Loader::lighting(const string &name)
264 obj.lighting = &get_collection().get<Lighting>(name);
267 void SequenceTemplate::Step::Loader::stencil_test()
269 load_sub(obj.stencil_test);