]> git.tdb.fi Git - libs/gl.git/blob - source/builders/pipelinebuilder.cpp
Include only tangent in mesh data and calculate binormal on the fly
[libs/gl.git] / source / builders / 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         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;
24 }
25
26 void PipelineBuilder::set_renderable(const string &name, Renderable &rend)
27 {
28         get_item(renderables, name) = &rend;
29 }
30
31 void PipelineBuilder::set_postprocessor(const string &name, PostProcessor &pproc)
32 {
33         get_item(postprocessors, name) = &pproc;
34 }
35
36 void PipelineBuilder::build(Pipeline &pipeline) const
37 {
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");
43
44         pipeline.set_multisample(samples);
45
46         const PipelineTemplate::PassArray &passes = tmpl.get_passes();
47         for(PipelineTemplate::PassArray::const_iterator i=passes.begin(); i!=passes.end(); ++i)
48         {
49                 Renderable *renderable = get_item(renderables, i->renderable_name);
50                 if(!renderable)
51                         continue;
52
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());
57         }
58
59         const PipelineTemplate::PostProcessorArray &postprocs = tmpl.get_postprocessors();
60         for(PipelineTemplate::PostProcessorArray::const_iterator i=postprocs.begin(); i!=postprocs.end(); ++i)
61         {
62                 PostProcessor *proc = 0;
63                 if(!i->slot_name.empty())
64                         proc = get_item(postprocessors, i->slot_name);
65                 if(proc)
66                         pipeline.add_postprocessor(*proc);
67                 else if(i->postprocessor_template)
68                 {
69                         proc = i->postprocessor_template->create(tmpl.get_resources(), pipeline.get_width(), pipeline.get_height());
70                         if(proc)
71                                 pipeline.add_postprocessor_owned(proc);
72                 }
73         }
74 }
75
76 Pipeline *PipelineBuilder::build(unsigned w, unsigned h) const
77 {
78         RefPtr<Pipeline> pipeline = new Pipeline(w, h);
79         build(*pipeline);
80         return pipeline.release();
81 }
82
83 Pipeline *PipelineBuilder::build(const View &view) const
84 {
85         RefPtr<Pipeline> pipeline = new Pipeline(view);
86         build(*pipeline);
87         return pipeline.release();
88 }
89
90 Pipeline *PipelineBuilder::build(const Framebuffer &fbo) const
91 {
92         RefPtr<Pipeline> pipeline = new Pipeline(fbo);
93         build(*pipeline);
94         return pipeline.release();
95 }
96
97 } // namespace GL
98 } // namespace Msp