]> git.tdb.fi Git - libs/gl.git/blob - source/pipelinetemplate.cpp
Apply FunctionResolver again after DeclarationReorderer
[libs/gl.git] / source / pipelinetemplate.cpp
1 #include <msp/core/maputils.h>
2 #include <msp/datafile/collection.h>
3 #include "blend.h"
4 #include "bloom.h"
5 #include "colorcurve.h"
6 #include "lighting.h"
7 #include "pipelinetemplate.h"
8 #include "tests.h"
9
10 using namespace std;
11
12 namespace Msp {
13 namespace GL {
14
15 PipelineTemplate::PipelineTemplate():
16         hdr(false),
17         required_multisample(0),
18         max_multisample(0)
19 { }
20
21
22 PipelineTemplate::Pass::~Pass()
23 { }
24
25
26 PipelineTemplate::Loader::Loader(PipelineTemplate &t):
27         DataFile::CollectionObjectLoader<PipelineTemplate>(t, 0)
28 {
29         init();
30 }
31
32 PipelineTemplate::Loader::Loader(PipelineTemplate &t, Collection &c):
33         DataFile::CollectionObjectLoader<PipelineTemplate>(t, &c)
34 {
35         init();
36 }
37
38 void PipelineTemplate::Loader::init()
39 {
40         add("bloom", &Loader::postprocessor<Bloom>);
41         add("colorcurve", &Loader::postprocessor<ColorCurve>);
42         add("hdr", &PipelineTemplate::hdr);
43         add("multisample", &Loader::multisample);
44         add("multisample", &Loader::multisample_range);
45         add("pass", &Loader::pass);
46 }
47
48 void PipelineTemplate::Loader::multisample(unsigned samples)
49 {
50         obj.required_multisample = samples;
51         obj.max_multisample = samples;
52 }
53
54 void PipelineTemplate::Loader::multisample_range(unsigned req, unsigned max)
55 {
56         obj.required_multisample = req;
57         obj.max_multisample = max;
58 }
59
60 void PipelineTemplate::Loader::pass(const string &tag, const string &rend)
61 {
62         Pass pss;;
63         pss.tag = tag;
64         pss.renderable_name = rend;
65         if(coll)
66                 load_sub(pss, *coll);
67         else
68                 load_sub(pss);
69
70         obj.passes.push_back(pss);
71 }
72
73 template<typename T>
74 void PipelineTemplate::Loader::postprocessor()
75 {
76         RefPtr<typename T::Template> postproc = new typename T::Template;
77         load_sub(*postproc);
78         obj.postprocessors.push_back(postproc.release());
79 }
80
81
82 PipelineTemplate::Pass::Loader::Loader(Pass &p):
83         DataFile::CollectionObjectLoader<Pass>(p, 0)
84 {
85         init();
86 }
87
88 PipelineTemplate::Pass::Loader::Loader(Pass &p, Collection &c):
89         DataFile::CollectionObjectLoader<Pass>(p, &c)
90 {
91         init();
92 }
93
94 void PipelineTemplate::Pass::Loader::init()
95 {
96         add("blend", &Loader::blend);
97         add("blend", &Loader::blend_predefined);
98         add("depth_test", &Loader::depth_test);
99         add("depth_test", &Loader::depth_test_predefined);
100         add("lighting", &Loader::lighting);
101         add("lighting", &Loader::lighting_inline);
102 }
103
104 void PipelineTemplate::Pass::Loader::blend_predefined(const string &name)
105 {
106         const Blend *blend = 0;
107         if(name=="alpha")
108                 blend = &Blend::alpha();
109         else if(name=="additive")
110                 blend = &Blend::additive();
111         else if(name=="additive_alpha")
112                 blend = &Blend::additive_alpha();
113         else
114                 throw key_error(name);
115
116         obj.blend = blend;
117         obj.blend.keep();
118 }
119
120 void PipelineTemplate::Pass::Loader::blend(BlendFactor src, BlendFactor dest)
121 {
122         obj.blend = new Blend(src, dest);
123 }
124
125 void PipelineTemplate::Pass::Loader::depth_test_predefined(const string &name)
126 {
127         const DepthTest *dtest = 0;
128         if(name=="lequal")
129                 dtest = &DepthTest::lequal();
130         else
131                 throw key_error(name);
132
133         obj.depth_test = dtest;
134         obj.depth_test.keep();
135 }
136
137 void PipelineTemplate::Pass::Loader::depth_test(Predicate pred)
138 {
139         obj.depth_test = new DepthTest(pred);
140 }
141
142 void PipelineTemplate::Pass::Loader::lighting_inline()
143 {
144         RefPtr<Lighting> lightn = new Lighting;
145         load_sub(*lightn);
146         obj.lighting = lightn;
147 }
148
149 void PipelineTemplate::Pass::Loader::lighting(const string &name)
150 {
151         obj.lighting = &get_collection().get<Lighting>(name);
152         obj.lighting.keep();
153 }
154
155 /*void PipelineTemplate::Pass::Loader::scene(const string &name)
156 {
157         obj.default_renderable = get_collection().get<Scene>(name);
158 }*/
159
160 } // namespace GL
161 } // namespace Msp