X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fbuilders%2Fpipelinebuilder.cpp;fp=source%2Fbuilders%2Fpipelinebuilder.cpp;h=51e9cc855f8b73d1cb7b4cd49f616a4cc3faea58;hb=7aaec9a70b8d7733429bec043f8e33e02956f266;hp=0000000000000000000000000000000000000000;hpb=bec07999d95b76f4b47cffcc564d0cd0afc0435e;p=libs%2Fgl.git diff --git a/source/builders/pipelinebuilder.cpp b/source/builders/pipelinebuilder.cpp new file mode 100644 index 00000000..51e9cc85 --- /dev/null +++ b/source/builders/pipelinebuilder.cpp @@ -0,0 +1,98 @@ +#include +#include +#include "error.h" +#include "pipeline.h" +#include "pipelinebuilder.h" +#include "pipelinetemplate.h" +#include "renderbuffer.h" + +using namespace std; + +namespace Msp { +namespace GL { + +PipelineBuilder::PipelineBuilder(const PipelineTemplate &t): + tmpl(t) +{ + const vector &passes = tmpl.get_passes(); + for(vector::const_iterator i=passes.begin(); i!=passes.end(); ++i) + renderables[i->renderable_name] = 0; + const vector &postprocs = tmpl.get_postprocessors(); + for(PipelineTemplate::PostProcessorArray::const_iterator i=postprocs.begin(); i!=postprocs.end(); ++i) + if(!i->slot_name.empty()) + postprocessors[i->slot_name] = 0; +} + +void PipelineBuilder::set_renderable(const string &name, Renderable &rend) +{ + get_item(renderables, name) = &rend; +} + +void PipelineBuilder::set_postprocessor(const string &name, PostProcessor &pproc) +{ + get_item(postprocessors, name) = &pproc; +} + +void PipelineBuilder::build(Pipeline &pipeline) const +{ + pipeline.set_hdr(tmpl.get_hdr()); + pipeline.set_alpha(tmpl.get_alpha()); + unsigned samples = min(tmpl.get_maximum_multisample(), Renderbuffer::get_max_samples()); + if(samplesrenderable_name); + if(!renderable) + continue; + + Pipeline::Pass &pass = pipeline.add_pass(i->tag, *renderable); + pass.set_blend(i->blend.get()); + pass.set_depth_test(i->depth_test.get()); + pass.set_lighting(i->lighting.get()); + } + + const PipelineTemplate::PostProcessorArray &postprocs = tmpl.get_postprocessors(); + for(PipelineTemplate::PostProcessorArray::const_iterator i=postprocs.begin(); i!=postprocs.end(); ++i) + { + PostProcessor *proc = 0; + if(!i->slot_name.empty()) + proc = get_item(postprocessors, i->slot_name); + if(proc) + pipeline.add_postprocessor(*proc); + else if(i->postprocessor_template) + { + proc = i->postprocessor_template->create(pipeline.get_width(), pipeline.get_height()); + if(proc) + pipeline.add_postprocessor_owned(proc); + } + } +} + +Pipeline *PipelineBuilder::build(unsigned w, unsigned h) const +{ + RefPtr pipeline = new Pipeline(w, h); + build(*pipeline); + return pipeline.release(); +} + +Pipeline *PipelineBuilder::build(const View &view) const +{ + RefPtr pipeline = new Pipeline(view); + build(*pipeline); + return pipeline.release(); +} + +Pipeline *PipelineBuilder::build(const Framebuffer &fbo) const +{ + RefPtr pipeline = new Pipeline(fbo); + build(*pipeline); + return pipeline.release(); +} + +} // namespace GL +} // namespace Msp