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());
53 if(tmpl.is_clear_enabled())
55 sequence.set_clear_colors(tmpl.get_clear_colors());
56 sequence.set_clear_depth(tmpl.get_clear_depth());
57 sequence.set_clear_stencil(tmpl.get_clear_stencil());
60 for(const SequenceTemplate::Step &s: tmpl.get_steps())
62 Renderable *renderable = get_item(renderables, s.slot_name);
66 Sequence::Step &step = sequence.add_step(s.tag, *renderable);
67 step.set_blend(s.blend);
68 step.set_depth_test(s.depth_test);
69 step.set_stencil_test(s.stencil_test);
70 step.set_lighting(s.lighting);
76 for(const SequenceTemplate::PostProcessor &p: tmpl.get_postprocessors())
78 PostProcessor *proc = 0;
79 if(!p.slot_name.empty())
80 proc = get_item(postprocessors, p.slot_name);
82 sequence.add_postprocessor(*proc);
83 else if(p.postprocessor_template)
85 proc = p.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, index++));
92 sequence.add_postprocessor_owned(proc);
98 Sequence *SequenceBuilder::build() const
100 RefPtr<Sequence> sequence = new Sequence();
102 return sequence.release();
105 Sequence *SequenceBuilder::build(unsigned w, unsigned h) const
107 RefPtr<Sequence> sequence = new Sequence(w, h, create_frame_format());
109 return sequence.release();
112 Sequence *SequenceBuilder::build(const View &view) const
114 RefPtr<Sequence> sequence = new Sequence(view.get_width(), view.get_height(), create_frame_format());
116 return sequence.release();
119 Sequence *SequenceBuilder::build(const Framebuffer &fbo) const
121 RefPtr<Sequence> sequence = new Sequence(fbo.get_width(), fbo.get_height(), create_frame_format());
123 return sequence.release();
126 FrameFormat SequenceBuilder::create_frame_format() const
128 unsigned samples = min(tmpl.get_maximum_multisample(), DeviceInfo::get_global().limits.max_samples);
129 if(samples<tmpl.get_required_multisample())
130 throw invalid_operation("SequenceBuilder::create_frame_format");
132 PixelComponents color_comp = (tmpl.get_alpha() ? RGBA : RGB);
133 DataType color_type = (tmpl.get_hdr() ? HALF_FLOAT : UNSIGNED_BYTE);
134 PixelFormat color_pf = make_pixelformat(color_comp, color_type);
136 return (COLOR_ATTACHMENT,color_pf, DEPTH_ATTACHMENT).set_samples(samples);