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 pipeline.set_alpha(tmpl.get_alpha());
40 unsigned samples = min(tmpl.get_maximum_multisample(), Renderbuffer::get_max_samples());
41 if(samples<tmpl.get_required_multisample())
42 throw invalid_operation("PipelineBuilder::build");
44 pipeline.set_multisample(samples);
46 const PipelineTemplate::PassArray &passes = tmpl.get_passes();
47 for(PipelineTemplate::PassArray::const_iterator i=passes.begin(); i!=passes.end(); ++i)
49 Renderable *renderable = get_item(renderables, i->renderable_name);
53 Pipeline::Pass &pass = pipeline.add_pass(i->tag, *renderable);
54 pass.set_blend(i->blend.get());
55 pass.set_depth_test(i->depth_test.get());
56 pass.set_lighting(i->lighting.get());
59 const PipelineTemplate::PostProcessorArray &postprocs = tmpl.get_postprocessors();
60 for(PipelineTemplate::PostProcessorArray::const_iterator i=postprocs.begin(); i!=postprocs.end(); ++i)
62 PostProcessor *proc = 0;
63 if(!i->slot_name.empty())
64 proc = get_item(postprocessors, i->slot_name);
66 pipeline.add_postprocessor(*proc);
67 else if(i->postprocessor_template)
69 proc = i->postprocessor_template->create(pipeline.get_width(), pipeline.get_height());
71 pipeline.add_postprocessor_owned(proc);
76 Pipeline *PipelineBuilder::build(unsigned w, unsigned h) const
78 RefPtr<Pipeline> pipeline = new Pipeline(w, h);
80 return pipeline.release();
83 Pipeline *PipelineBuilder::build(const View &view) const
85 RefPtr<Pipeline> pipeline = new Pipeline(view);
87 return pipeline.release();
90 Pipeline *PipelineBuilder::build(const Framebuffer &fbo) const
92 RefPtr<Pipeline> pipeline = new Pipeline(fbo);
94 return pipeline.release();