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"
15 SequenceBuilder::SequenceBuilder(const SequenceTemplate &t):
18 for(const SequenceTemplate::Step &s: tmpl.get_steps())
19 renderables[s.slot_name] = s.default_renderable;
20 for(const SequenceTemplate::PostProcessor &p: tmpl.get_postprocessors())
21 if(!p.slot_name.empty())
22 postprocessors[p.slot_name] = 0;
25 void SequenceBuilder::set_renderable(const string &name, Renderable &rend)
27 get_item(renderables, name) = &rend;
30 void SequenceBuilder::set_postprocessor(const string &name, PostProcessor &pproc)
32 get_item(postprocessors, name) = &pproc;
35 void SequenceBuilder::set_debug_name(const string &name)
44 void SequenceBuilder::build(Sequence &sequence) const
47 if(!debug_name.empty())
48 sequence.set_debug_name(debug_name);
51 for(const SequenceTemplate::Step &s: tmpl.get_steps())
53 Renderable *renderable = get_item(renderables, s.slot_name);
57 Sequence::Step &step = sequence.add_step(s.tag, *renderable);
58 step.set_blend(s.blend);
59 step.set_depth_test(s.depth_test);
60 step.set_stencil_test(s.stencil_test);
61 step.set_lighting(s.lighting);
67 for(const SequenceTemplate::PostProcessor &p: tmpl.get_postprocessors())
69 PostProcessor *proc = 0;
70 if(!p.slot_name.empty())
71 proc = get_item(postprocessors, p.slot_name);
73 sequence.add_postprocessor(*proc);
74 else if(p.postprocessor_template)
76 proc = p.postprocessor_template->create(sequence.get_width(), sequence.get_height());
80 if(!debug_name.empty())
81 proc->set_debug_name(format("%s/%d.pproc", debug_name, index++));
83 sequence.add_postprocessor_owned(proc);
89 Sequence *SequenceBuilder::build(unsigned w, unsigned h) const
91 RefPtr<Sequence> sequence = new Sequence(w, h, create_frame_format());
93 return sequence.release();
96 Sequence *SequenceBuilder::build(const View &view) const
98 RefPtr<Sequence> sequence = new Sequence(view, create_frame_format());
100 return sequence.release();
103 Sequence *SequenceBuilder::build(const Framebuffer &fbo) const
105 RefPtr<Sequence> sequence = new Sequence(fbo, create_frame_format());
107 return sequence.release();
110 FrameFormat SequenceBuilder::create_frame_format() const
112 unsigned samples = min(tmpl.get_maximum_multisample(), Limits::get_global().max_samples);
113 if(samples<tmpl.get_required_multisample())
114 throw invalid_operation("SequenceBuilder::create_frame_format");
116 PixelComponents color_comp = (tmpl.get_alpha() ? RGBA : RGB);
117 DataType color_type = (tmpl.get_hdr() ? HALF_FLOAT : UNSIGNED_BYTE);
118 PixelFormat color_pf = make_pixelformat(color_comp, color_type);
120 return (COLOR_ATTACHMENT,color_pf, DEPTH_ATTACHMENT).set_samples(samples);