1 #include <msp/core/algorithm.h>
2 #include <msp/core/maputils.h>
3 #include <msp/strings/format.h>
4 #include "deviceinfo.h"
7 #include "sequencebuilder.h"
8 #include "sequencetemplate.h"
16 SequenceBuilder::SequenceBuilder(const SequenceTemplate &t):
19 for(const SequenceTemplate::Step &s: tmpl.get_steps())
20 renderables[s.slot_name] = s.default_renderable;
21 for(const SequenceTemplate::PostProcessor &p: tmpl.get_postprocessors())
22 if(!p.slot_name.empty())
23 postprocessors[p.slot_name] = 0;
26 void SequenceBuilder::set_renderable(const string &name, Renderable &rend)
28 get_item(renderables, name) = &rend;
31 void SequenceBuilder::set_postprocessor(const string &name, PostProcessor &pproc)
33 get_item(postprocessors, name) = &pproc;
36 void SequenceBuilder::set_debug_name(const string &name)
45 void SequenceBuilder::build(Sequence &sequence) const
48 if(!debug_name.empty())
49 sequence.set_debug_name(debug_name);
52 sequence.set_clear_enabled(tmpl.is_clear_enabled());
54 for(const SequenceTemplate::Step &s: tmpl.get_steps())
56 Renderable *renderable = get_item(renderables, s.slot_name);
60 Sequence::Step &step = sequence.add_step(s.tag, *renderable);
61 step.set_blend(s.blend);
62 step.set_depth_test(s.depth_test);
63 step.set_stencil_test(s.stencil_test);
64 step.set_lighting(s.lighting);
70 for(const SequenceTemplate::PostProcessor &p: tmpl.get_postprocessors())
72 PostProcessor *proc = 0;
73 if(!p.slot_name.empty())
74 proc = get_item(postprocessors, p.slot_name);
76 sequence.add_postprocessor(*proc);
77 else if(p.postprocessor_template)
79 proc = p.postprocessor_template->create(sequence.get_width(), sequence.get_height());
83 if(!debug_name.empty())
84 proc->set_debug_name(format("%s/%d.pproc", debug_name, index++));
86 sequence.add_postprocessor_owned(proc);
92 Sequence *SequenceBuilder::build() const
94 RefPtr<Sequence> sequence = new Sequence();
96 return sequence.release();
99 Sequence *SequenceBuilder::build(unsigned w, unsigned h) const
101 RefPtr<Sequence> sequence = new Sequence(w, h, create_frame_format());
103 return sequence.release();
106 Sequence *SequenceBuilder::build(const View &view) const
108 RefPtr<Sequence> sequence = new Sequence(view.get_width(), view.get_height(), create_frame_format());
110 return sequence.release();
113 Sequence *SequenceBuilder::build(const Framebuffer &fbo) const
115 RefPtr<Sequence> sequence = new Sequence(fbo.get_width(), fbo.get_height(), create_frame_format());
117 return sequence.release();
120 FrameFormat SequenceBuilder::create_frame_format() const
122 unsigned samples = min(tmpl.get_maximum_multisample(), Limits::get_global().max_samples);
123 if(samples<tmpl.get_required_multisample())
124 throw invalid_operation("SequenceBuilder::create_frame_format");
126 PixelComponents color_comp = (tmpl.get_alpha() ? RGBA : RGB);
127 DataType color_type = (tmpl.get_hdr() ? HALF_FLOAT : UNSIGNED_BYTE);
128 PixelFormat color_pf = make_pixelformat(color_comp, color_type);
130 return (COLOR_ATTACHMENT,color_pf, DEPTH_ATTACHMENT).set_samples(samples);