1 #include <msp/core/algorithm.h>
2 #include <msp/core/maputils.h>
3 #include <msp/strings/format.h>
5 #include "renderbuffer.h"
7 #include "sequencebuilder.h"
8 #include "sequencetemplate.h"
15 SequenceBuilder::SequenceBuilder(const SequenceTemplate &t):
18 const vector<SequenceTemplate::Step> &steps = tmpl.get_steps();
19 for(vector<SequenceTemplate::Step>::const_iterator i=steps.begin(); i!=steps.end(); ++i)
20 renderables[i->slot_name] = i->default_renderable;
21 const vector<SequenceTemplate::PostProcessor> &postprocs = tmpl.get_postprocessors();
22 for(SequenceTemplate::PostProcessorArray::const_iterator i=postprocs.begin(); i!=postprocs.end(); ++i)
23 if(!i->slot_name.empty())
24 postprocessors[i->slot_name] = 0;
27 void SequenceBuilder::set_renderable(const string &name, Renderable &rend)
29 get_item(renderables, name) = &rend;
32 void SequenceBuilder::set_postprocessor(const string &name, PostProcessor &pproc)
34 get_item(postprocessors, name) = &pproc;
37 void SequenceBuilder::set_debug_name(const string &name)
46 void SequenceBuilder::build(Sequence &sequence) const
49 if(!debug_name.empty())
50 sequence.set_debug_name(debug_name);
53 sequence.set_hdr(tmpl.get_hdr());
54 sequence.set_alpha(tmpl.get_alpha());
55 unsigned samples = min(tmpl.get_maximum_multisample(), Renderbuffer::get_max_samples());
56 if(samples<tmpl.get_required_multisample())
57 throw invalid_operation("SequenceBuilder::build");
59 sequence.set_multisample(samples);
61 const vector<SequenceTemplate::Step> &steps = tmpl.get_steps();
62 for(vector<SequenceTemplate::Step>::const_iterator i=steps.begin(); i!=steps.end(); ++i)
64 Renderable *renderable = get_item(renderables, i->slot_name);
68 Sequence::Step &step = sequence.add_step(i->tag, *renderable);
69 step.set_blend(i->blend.get());
70 step.set_depth_test(i->depth_test.get());
71 step.set_lighting(i->lighting);
74 const SequenceTemplate::PostProcessorArray &postprocs = tmpl.get_postprocessors();
75 for(SequenceTemplate::PostProcessorArray::const_iterator i=postprocs.begin(); i!=postprocs.end(); ++i)
77 PostProcessor *proc = 0;
78 if(!i->slot_name.empty())
79 proc = get_item(postprocessors, i->slot_name);
81 sequence.add_postprocessor(*proc);
82 else if(i->postprocessor_template)
84 proc = i->postprocessor_template->create(sequence.get_width(), sequence.get_height());
88 if(!debug_name.empty())
89 proc->set_debug_name(format("%s/%d.pproc", debug_name, i-postprocs.begin()));
91 sequence.add_postprocessor_owned(proc);
97 Sequence *SequenceBuilder::build(unsigned w, unsigned h) const
99 RefPtr<Sequence> sequence = new Sequence(w, h);
101 return sequence.release();
104 Sequence *SequenceBuilder::build(const View &view) const
106 RefPtr<Sequence> sequence = new Sequence(view);
108 return sequence.release();
111 Sequence *SequenceBuilder::build(const Framebuffer &fbo) const
113 RefPtr<Sequence> sequence = new Sequence(fbo);
115 return sequence.release();