1 #include <msp/core/maputils.h>
2 #include <msp/datafile/collection.h>
3 #include "ambientocclusion.h"
6 #include "colorcurve.h"
8 #include "pipelinetemplate.h"
16 PipelineTemplate::PipelineTemplate():
18 required_multisample(0),
22 PipelineTemplate::~PipelineTemplate()
24 for(PostProcessorArray::iterator i=postprocessors.begin(); i!=postprocessors.end(); ++i)
25 delete i->postprocessor_template;
29 PipelineTemplate::PostProcessorRegistry &PipelineTemplate::get_postprocessor_registry()
31 static PostProcessorRegistry registry;
32 static bool initialized = false;
35 registry.register_type<AmbientOcclusion>("ambient_occlusion");
36 registry.register_type<Bloom>("bloom");
37 registry.register_type<ColorCurve>("colorcurve");
44 PipelineTemplate::Pass::~Pass()
48 PipelineTemplate::PostProcessor::PostProcessor(GL::PostProcessor::Template *ppt):
49 postprocessor_template(ppt)
53 PipelineTemplate::PostProcLoader::PostProcLoader()
55 get_postprocessor_registry().add_all(*this);
59 PipelineTemplate::Loader::Loader(PipelineTemplate &t):
60 DataFile::CollectionObjectLoader<PipelineTemplate>(t, 0)
65 PipelineTemplate::Loader::Loader(PipelineTemplate &t, Collection &c):
66 DataFile::CollectionObjectLoader<PipelineTemplate>(t, &c)
71 void PipelineTemplate::Loader::init()
73 add("hdr", &PipelineTemplate::hdr);
74 add("multisample", &Loader::multisample);
75 add("multisample", &Loader::multisample_range);
76 add("pass", &Loader::pass);
77 add("postprocessor", &Loader::postprocessor);
80 void PipelineTemplate::Loader::postprocessor_loaded()
82 obj.postprocessors.push_back(get_postprocessor_template());
85 void PipelineTemplate::Loader::multisample(unsigned samples)
87 obj.required_multisample = samples;
88 obj.max_multisample = samples;
91 void PipelineTemplate::Loader::multisample_range(unsigned req, unsigned max)
93 obj.required_multisample = req;
94 obj.max_multisample = max;
97 void PipelineTemplate::Loader::pass(const string &tag, const string &rend)
101 pss.renderable_name = rend;
103 load_sub(pss, *coll);
107 obj.passes.push_back(pss);
110 void PipelineTemplate::Loader::postprocessor(const std::string &slot)
115 pp.postprocessor_template = ldr.get_postprocessor_template();
117 obj.postprocessors.push_back(pp);
121 PipelineTemplate::Pass::Loader::Loader(Pass &p):
122 DataFile::CollectionObjectLoader<Pass>(p, 0)
127 PipelineTemplate::Pass::Loader::Loader(Pass &p, Collection &c):
128 DataFile::CollectionObjectLoader<Pass>(p, &c)
133 void PipelineTemplate::Pass::Loader::init()
135 add("blend", &Loader::blend);
136 add("blend", &Loader::blend_predefined);
137 add("depth_test", &Loader::depth_test);
138 add("depth_test", &Loader::depth_test_predefined);
139 add("lighting", &Loader::lighting);
140 add("lighting", &Loader::lighting_inline);
143 void PipelineTemplate::Pass::Loader::blend_predefined(const string &name)
145 const Blend *bln = 0;
147 bln = &Blend::alpha();
148 else if(name=="additive")
149 bln = &Blend::additive();
150 else if(name=="additive_alpha")
151 bln = &Blend::additive_alpha();
153 throw key_error(name);
159 void PipelineTemplate::Pass::Loader::blend(BlendFactor src, BlendFactor dest)
161 obj.blend = new Blend(src, dest);
164 void PipelineTemplate::Pass::Loader::depth_test_predefined(const string &name)
166 const DepthTest *dtest = 0;
168 dtest = &DepthTest::lequal();
170 throw key_error(name);
172 obj.depth_test = dtest;
173 obj.depth_test.keep();
176 void PipelineTemplate::Pass::Loader::depth_test(Predicate pred)
178 obj.depth_test = new DepthTest(pred);
181 void PipelineTemplate::Pass::Loader::lighting_inline()
183 RefPtr<Lighting> lightn = new Lighting;
185 obj.lighting = lightn;
188 void PipelineTemplate::Pass::Loader::lighting(const string &name)
190 obj.lighting = &get_collection().get<Lighting>(name);
194 /*void PipelineTemplate::Pass::Loader::scene(const string &name)
196 obj.default_renderable = get_collection().get<Scene>(name);