]> git.tdb.fi Git - libs/gl.git/blob - source/builders/sequencebuilder.cpp
Remove outdated includes
[libs/gl.git] / source / builders / sequencebuilder.cpp
1 #include <msp/core/algorithm.h>
2 #include <msp/core/maputils.h>
3 #include <msp/strings/format.h>
4 #include "deviceinfo.h"
5 #include "error.h"
6 #include "renderbuffer.h"
7 #include "sequence.h"
8 #include "sequencebuilder.h"
9 #include "sequencetemplate.h"
10
11 using namespace std;
12
13 namespace Msp {
14 namespace GL {
15
16 SequenceBuilder::SequenceBuilder(const SequenceTemplate &t):
17         tmpl(t)
18 {
19         const vector<SequenceTemplate::Step> &steps = tmpl.get_steps();
20         for(vector<SequenceTemplate::Step>::const_iterator i=steps.begin(); i!=steps.end(); ++i)
21                 renderables[i->slot_name] = i->default_renderable;
22         const vector<SequenceTemplate::PostProcessor> &postprocs = tmpl.get_postprocessors();
23         for(SequenceTemplate::PostProcessorArray::const_iterator i=postprocs.begin(); i!=postprocs.end(); ++i)
24                 if(!i->slot_name.empty())
25                         postprocessors[i->slot_name] = 0;
26 }
27
28 void SequenceBuilder::set_renderable(const string &name, Renderable &rend)
29 {
30         get_item(renderables, name) = &rend;
31 }
32
33 void SequenceBuilder::set_postprocessor(const string &name, PostProcessor &pproc)
34 {
35         get_item(postprocessors, name) = &pproc;
36 }
37
38 void SequenceBuilder::set_debug_name(const string &name)
39 {
40 #ifdef DEBUG
41         debug_name = name;
42 #else
43         (void)name;
44 #endif
45 }
46
47 void SequenceBuilder::build(Sequence &sequence) const
48 {
49 #ifdef DEBUG
50         if(!debug_name.empty())
51                 sequence.set_debug_name(debug_name);
52 #endif
53
54         sequence.set_hdr(tmpl.get_hdr());
55         sequence.set_alpha(tmpl.get_alpha());
56         unsigned samples = min(tmpl.get_maximum_multisample(), Limits::get_global().max_samples);
57         if(samples<tmpl.get_required_multisample())
58                 throw invalid_operation("SequenceBuilder::build");
59
60         sequence.set_multisample(samples);
61
62         const vector<SequenceTemplate::Step> &steps = tmpl.get_steps();
63         for(vector<SequenceTemplate::Step>::const_iterator i=steps.begin(); i!=steps.end(); ++i)
64         {
65                 Renderable *renderable = get_item(renderables, i->slot_name);
66                 if(!renderable)
67                         continue;
68
69                 Sequence::Step &step = sequence.add_step(i->tag, *renderable);
70                 step.set_blend(i->blend);
71                 step.set_depth_test(i->depth_test);
72                 step.set_stencil_test(i->stencil_test);
73                 step.set_lighting(i->lighting);
74         }
75
76         const SequenceTemplate::PostProcessorArray &postprocs = tmpl.get_postprocessors();
77         for(SequenceTemplate::PostProcessorArray::const_iterator i=postprocs.begin(); i!=postprocs.end(); ++i)
78         {
79                 PostProcessor *proc = 0;
80                 if(!i->slot_name.empty())
81                         proc = get_item(postprocessors, i->slot_name);
82                 if(proc)
83                         sequence.add_postprocessor(*proc);
84                 else if(i->postprocessor_template)
85                 {
86                         proc = i->postprocessor_template->create(sequence.get_width(), sequence.get_height());
87                         if(proc)
88                         {
89 #ifdef DEBUG
90                                 if(!debug_name.empty())
91                                         proc->set_debug_name(format("%s/%d.pproc", debug_name, i-postprocs.begin()));
92 #endif
93                                 sequence.add_postprocessor_owned(proc);
94                         }
95                 }
96         }
97 }
98
99 Sequence *SequenceBuilder::build(unsigned w, unsigned h) const
100 {
101         RefPtr<Sequence> sequence = new Sequence(w, h);
102         build(*sequence);
103         return sequence.release();
104 }
105
106 Sequence *SequenceBuilder::build(const View &view) const
107 {
108         RefPtr<Sequence> sequence = new Sequence(view);
109         build(*sequence);
110         return sequence.release();
111 }
112
113 Sequence *SequenceBuilder::build(const Framebuffer &fbo) const
114 {
115         RefPtr<Sequence> sequence = new Sequence(fbo);
116         build(*sequence);
117         return sequence.release();
118 }
119
120 } // namespace GL
121 } // namespace Msp