1 #include <msp/core/algorithm.h>
2 #include <msp/core/maputils.h>
5 #include "pipelinebuilder.h"
6 #include "pipelinetemplate.h"
7 #include "renderbuffer.h"
14 PipelineBuilder::PipelineBuilder(const PipelineTemplate &t):
17 const vector<PipelineTemplate::Pass> &passes = tmpl.get_passes();
18 for(vector<PipelineTemplate::Pass>::const_iterator i=passes.begin(); i!=passes.end(); ++i)
19 renderables[i->renderable_name] = 0;
20 const vector<PipelineTemplate::PostProcessor> &postprocs = tmpl.get_postprocessors();
21 for(PipelineTemplate::PostProcessorArray::const_iterator i=postprocs.begin(); i!=postprocs.end(); ++i)
22 if(!i->slot_name.empty())
23 postprocessors[i->slot_name] = 0;
26 void PipelineBuilder::set_renderable(const string &name, Renderable &rend)
28 get_item(renderables, name) = &rend;
31 void PipelineBuilder::set_postprocessor(const string &name, PostProcessor &pproc)
33 get_item(postprocessors, name) = &pproc;
36 void PipelineBuilder::build(Pipeline &pipeline) const
38 pipeline.set_hdr(tmpl.get_hdr());
39 unsigned samples = min(tmpl.get_maximum_multisample(), Renderbuffer::get_max_samples());
40 if(samples<tmpl.get_required_multisample())
41 throw invalid_operation("PipelineBuilder::build");
43 pipeline.set_multisample(samples);
45 const PipelineTemplate::PassArray &passes = tmpl.get_passes();
46 for(PipelineTemplate::PassArray::const_iterator i=passes.begin(); i!=passes.end(); ++i)
48 Renderable *renderable = get_item(renderables, i->renderable_name);
52 Pipeline::Pass &pass = pipeline.add_pass(i->tag, *renderable);
53 pass.set_blend(i->blend.get());
54 pass.set_depth_test(i->depth_test.get());
55 pass.set_lighting(i->lighting.get());
58 const PipelineTemplate::PostProcessorArray &postprocs = tmpl.get_postprocessors();
59 for(PipelineTemplate::PostProcessorArray::const_iterator i=postprocs.begin(); i!=postprocs.end(); ++i)
61 PostProcessor *proc = 0;
62 if(!i->slot_name.empty())
63 proc = get_item(postprocessors, i->slot_name);
65 pipeline.add_postprocessor(*proc);
66 else if(i->postprocessor_template)
68 proc = i->postprocessor_template->create(pipeline.get_width(), pipeline.get_height());
70 pipeline.add_postprocessor_owned(proc);
75 Pipeline *PipelineBuilder::build(unsigned w, unsigned h) const
77 RefPtr<Pipeline> pipeline = new Pipeline(w, h);
79 return pipeline.release();
82 Pipeline *PipelineBuilder::build(const View &view) const
84 RefPtr<Pipeline> pipeline = new Pipeline(view);
86 return pipeline.release();
89 Pipeline *PipelineBuilder::build(const Framebuffer &fbo) const
91 RefPtr<Pipeline> pipeline = new Pipeline(fbo);
93 return pipeline.release();