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);
71 step.set_depth_test(i->depth_test);
72 step.set_stencil_test(i->stencil_test);
73 step.set_lighting(i->lighting);
76 const SequenceTemplate::PostProcessorArray &postprocs = tmpl.get_postprocessors();
77 for(SequenceTemplate::PostProcessorArray::const_iterator i=postprocs.begin(); i!=postprocs.end(); ++i)
79 PostProcessor *proc = 0;
80 if(!i->slot_name.empty())
81 proc = get_item(postprocessors, i->slot_name);
83 sequence.add_postprocessor(*proc);
84 else if(i->postprocessor_template)
86 proc = i->postprocessor_template->create(sequence.get_width(), sequence.get_height());
90 if(!debug_name.empty())
91 proc->set_debug_name(format("%s/%d.pproc", debug_name, i-postprocs.begin()));
93 sequence.add_postprocessor_owned(proc);
99 Sequence *SequenceBuilder::build(unsigned w, unsigned h) const
101 RefPtr<Sequence> sequence = new Sequence(w, h);
103 return sequence.release();
106 Sequence *SequenceBuilder::build(const View &view) const
108 RefPtr<Sequence> sequence = new Sequence(view);
110 return sequence.release();
113 Sequence *SequenceBuilder::build(const Framebuffer &fbo) const
115 RefPtr<Sequence> sequence = new Sequence(fbo);
117 return sequence.release();