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;
22 void PipelineBuilder::set_renderable(const string &name, Renderable &rend)
24 get_item(renderables, name) = &rend;
27 void PipelineBuilder::build(Pipeline &pipeline) const
29 pipeline.set_hdr(tmpl.get_hdr());
30 unsigned samples = min(tmpl.get_maximum_multisample(), Renderbuffer::get_max_samples());
31 if(samples<tmpl.get_required_multisample())
32 throw invalid_operation("PipelineBuilder::build");
34 pipeline.set_multisample(samples);
36 const PipelineTemplate::PassArray &passes = tmpl.get_passes();
37 for(PipelineTemplate::PassArray::const_iterator i=passes.begin(); i!=passes.end(); ++i)
39 Renderable *renderable = get_item(renderables, i->renderable_name);
43 Pipeline::Pass &pass = pipeline.add_pass(i->tag, *renderable);
44 pass.set_blend(i->blend.get());
45 pass.set_depth_test(i->depth_test.get());
46 pass.set_lighting(i->lighting.get());
49 const PipelineTemplate::PostProcessorArray &postprocs = tmpl.get_postprocessors();
50 for(PipelineTemplate::PostProcessorArray::const_iterator i=postprocs.begin(); i!=postprocs.end(); ++i)
52 PostProcessor *proc = (*i)->create(pipeline.get_width(), pipeline.get_height());
53 pipeline.add_postprocessor_owned(proc);
57 Pipeline *PipelineBuilder::build(unsigned w, unsigned h) const
59 RefPtr<Pipeline> pipeline = new Pipeline(w, h);
61 return pipeline.release();
64 Pipeline *PipelineBuilder::build(const View &view) const
66 RefPtr<Pipeline> pipeline = new Pipeline(view);
68 return pipeline.release();
71 Pipeline *PipelineBuilder::build(const Framebuffer &fbo) const
73 RefPtr<Pipeline> pipeline = new Pipeline(fbo);
75 return pipeline.release();