]> git.tdb.fi Git - libs/gl.git/blob - source/pipelinebuilder.cpp
Add a speed parameter for animation playback
[libs/gl.git] / source / pipelinebuilder.cpp
1 #include <msp/core/algorithm.h>
2 #include <msp/core/maputils.h>
3 #include "error.h"
4 #include "pipeline.h"
5 #include "pipelinebuilder.h"
6 #include "pipelinetemplate.h"
7 #include "renderbuffer.h"
8
9 using namespace std;
10
11 namespace Msp {
12 namespace GL {
13
14 PipelineBuilder::PipelineBuilder(const PipelineTemplate &t):
15         tmpl(t)
16 {
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 }
21
22 void PipelineBuilder::set_renderable(const string &name, Renderable &rend)
23 {
24         get_item(renderables, name) = &rend;
25 }
26
27 void PipelineBuilder::build(Pipeline &pipeline) const
28 {
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");
33
34         pipeline.set_multisample(samples);
35
36         const PipelineTemplate::PassArray &passes = tmpl.get_passes();
37         for(PipelineTemplate::PassArray::const_iterator i=passes.begin(); i!=passes.end(); ++i)
38         {
39                 Renderable *renderable = get_item(renderables, i->renderable_name);
40                 if(!renderable)
41                         continue;
42
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());
47         }
48
49         const PipelineTemplate::PostProcessorArray &postprocs = tmpl.get_postprocessors();
50         for(PipelineTemplate::PostProcessorArray::const_iterator i=postprocs.begin(); i!=postprocs.end(); ++i)
51         {
52                 PostProcessor *proc = (*i)->create(pipeline.get_width(), pipeline.get_height());
53                 pipeline.add_postprocessor_owned(proc);
54         }
55 }
56
57 Pipeline *PipelineBuilder::build(unsigned w, unsigned h) const
58 {
59         RefPtr<Pipeline> pipeline = new Pipeline(w, h);
60         build(*pipeline);
61         return pipeline.release();
62 }
63
64 Pipeline *PipelineBuilder::build(const View &view) const
65 {
66         RefPtr<Pipeline> pipeline = new Pipeline(view);
67         build(*pipeline);
68         return pipeline.release();
69 }
70
71 Pipeline *PipelineBuilder::build(const Framebuffer &fbo) const
72 {
73         RefPtr<Pipeline> pipeline = new Pipeline(fbo);
74         build(*pipeline);
75         return pipeline.release();
76 }
77
78 } // namespace GL
79 } // namespace Msp