1 #include <msp/core/algorithm.h>
2 #include <msp/core/maputils.h>
3 #include <msp/strings/format.h>
4 #include "deviceinfo.h"
6 #include "renderbuffer.h"
8 #include "sequencebuilder.h"
9 #include "sequencetemplate.h"
16 SequenceBuilder::SequenceBuilder(const SequenceTemplate &t):
19 const vector<SequenceTemplate::Step> &steps = tmpl.get_steps();
20 for(vector<SequenceTemplate::Step>::const_iterator i=steps.begin(); i!=steps.end(); ++i)
21 renderables[i->slot_name] = i->default_renderable;
22 const vector<SequenceTemplate::PostProcessor> &postprocs = tmpl.get_postprocessors();
23 for(SequenceTemplate::PostProcessorArray::const_iterator i=postprocs.begin(); i!=postprocs.end(); ++i)
24 if(!i->slot_name.empty())
25 postprocessors[i->slot_name] = 0;
28 void SequenceBuilder::set_renderable(const string &name, Renderable &rend)
30 get_item(renderables, name) = &rend;
33 void SequenceBuilder::set_postprocessor(const string &name, PostProcessor &pproc)
35 get_item(postprocessors, name) = &pproc;
38 void SequenceBuilder::set_debug_name(const string &name)
47 void SequenceBuilder::build(Sequence &sequence) const
50 if(!debug_name.empty())
51 sequence.set_debug_name(debug_name);
54 sequence.set_hdr(tmpl.get_hdr());
55 sequence.set_alpha(tmpl.get_alpha());
56 unsigned samples = min(tmpl.get_maximum_multisample(), Limits::get_global().max_samples);
57 if(samples<tmpl.get_required_multisample())
58 throw invalid_operation("SequenceBuilder::build");
60 sequence.set_multisample(samples);
62 const vector<SequenceTemplate::Step> &steps = tmpl.get_steps();
63 for(vector<SequenceTemplate::Step>::const_iterator i=steps.begin(); i!=steps.end(); ++i)
65 Renderable *renderable = get_item(renderables, i->slot_name);
69 Sequence::Step &step = sequence.add_step(i->tag, *renderable);
70 step.set_blend(i->blend.get());
71 step.set_depth_test(i->depth_test.get());
72 step.set_lighting(i->lighting);
75 const SequenceTemplate::PostProcessorArray &postprocs = tmpl.get_postprocessors();
76 for(SequenceTemplate::PostProcessorArray::const_iterator i=postprocs.begin(); i!=postprocs.end(); ++i)
78 PostProcessor *proc = 0;
79 if(!i->slot_name.empty())
80 proc = get_item(postprocessors, i->slot_name);
82 sequence.add_postprocessor(*proc);
83 else if(i->postprocessor_template)
85 proc = i->postprocessor_template->create(sequence.get_width(), sequence.get_height());
89 if(!debug_name.empty())
90 proc->set_debug_name(format("%s/%d.pproc", debug_name, i-postprocs.begin()));
92 sequence.add_postprocessor_owned(proc);
98 Sequence *SequenceBuilder::build(unsigned w, unsigned h) const
100 RefPtr<Sequence> sequence = new Sequence(w, h);
102 return sequence.release();
105 Sequence *SequenceBuilder::build(const View &view) const
107 RefPtr<Sequence> sequence = new Sequence(view);
109 return sequence.release();
112 Sequence *SequenceBuilder::build(const Framebuffer &fbo) const
114 RefPtr<Sequence> sequence = new Sequence(fbo);
116 return sequence.release();