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