1 #include <msp/core/maputils.h>
2 #include <msp/datafile/collection.h>
3 #include "ambientocclusion.h"
6 #include "colorcurve.h"
8 #include "pipelinetemplate.h"
17 PipelineTemplate::PipelineTemplate():
21 required_multisample(0),
25 PipelineTemplate::~PipelineTemplate()
27 for(PostProcessorArray::iterator i=postprocessors.begin(); i!=postprocessors.end(); ++i)
28 delete i->postprocessor_template;
31 Resources &PipelineTemplate::get_resources() const
34 throw logic_error("no resources");
39 PipelineTemplate::PostProcessorRegistry &PipelineTemplate::get_postprocessor_registry()
41 static PostProcessorRegistry registry;
42 static bool initialized = false;
45 registry.register_type<AmbientOcclusion>("ambient_occlusion");
46 registry.register_type<Bloom>("bloom");
47 registry.register_type<ColorCurve>("colorcurve");
54 PipelineTemplate::Pass::~Pass()
58 PipelineTemplate::PostProcessor::PostProcessor(GL::PostProcessor::Template *ppt):
59 postprocessor_template(ppt)
63 PipelineTemplate::PostProcLoader::PostProcLoader()
65 get_postprocessor_registry().invoke_all(*this);
69 PipelineTemplate::Loader::Loader(PipelineTemplate &t, Collection &c):
70 DataFile::CollectionObjectLoader<PipelineTemplate, Resources>(t, &c)
72 add("hdr", &PipelineTemplate::hdr);
73 add("alpha", &PipelineTemplate::alpha);
74 add("multisample", &Loader::multisample);
75 add("multisample", &Loader::multisample_range);
76 add("pass", &Loader::pass);
77 add("postprocessor", &Loader::postprocessor);
82 void PipelineTemplate::Loader::postprocessor_loaded()
84 obj.postprocessors.push_back(get_postprocessor_template());
87 void PipelineTemplate::Loader::multisample(unsigned samples)
89 obj.required_multisample = samples;
90 obj.max_multisample = samples;
93 void PipelineTemplate::Loader::multisample_range(unsigned req, unsigned max)
95 obj.required_multisample = req;
96 obj.max_multisample = max;
99 void PipelineTemplate::Loader::pass(const string &tag, const string &rend)
103 pss.renderable_name = rend;
105 load_sub(pss, *coll);
109 obj.passes.push_back(pss);
112 void PipelineTemplate::Loader::postprocessor(const string &slot)
117 pp.postprocessor_template = ldr.get_postprocessor_template();
119 obj.postprocessors.push_back(pp);
123 PipelineTemplate::Pass::Loader::Loader(Pass &p):
124 DataFile::CollectionObjectLoader<Pass>(p, 0)
129 PipelineTemplate::Pass::Loader::Loader(Pass &p, Collection &c):
130 DataFile::CollectionObjectLoader<Pass>(p, &c)
135 void PipelineTemplate::Pass::Loader::init()
137 add("blend", &Loader::blend);
138 add("blend", &Loader::blend_predefined);
139 add("depth_test", &Loader::depth_test);
140 add("depth_test", &Loader::depth_test_predefined);
141 add("lighting", &Loader::lighting);
142 add("lighting", &Loader::lighting_inline);
145 void PipelineTemplate::Pass::Loader::blend_predefined(const string &name)
147 const Blend *bln = 0;
149 bln = &Blend::alpha();
150 else if(name=="additive")
151 bln = &Blend::additive();
152 else if(name=="additive_alpha")
153 bln = &Blend::additive_alpha();
155 throw key_error(name);
161 void PipelineTemplate::Pass::Loader::blend(BlendFactor src, BlendFactor dest)
163 obj.blend = new Blend(src, dest);
166 void PipelineTemplate::Pass::Loader::depth_test_predefined(const string &name)
168 const DepthTest *dtest = 0;
170 dtest = &DepthTest::lequal();
172 throw key_error(name);
174 obj.depth_test = dtest;
175 obj.depth_test.keep();
178 void PipelineTemplate::Pass::Loader::depth_test(Predicate pred)
180 obj.depth_test = new DepthTest(pred);
183 void PipelineTemplate::Pass::Loader::lighting_inline()
185 RefPtr<Lighting> lightn = new Lighting;
187 obj.lighting = lightn;
190 void PipelineTemplate::Pass::Loader::lighting(const string &name)
192 obj.lighting = &get_collection().get<Lighting>(name);
196 /*void PipelineTemplate::Pass::Loader::scene(const string &name)
198 obj.default_renderable = get_collection().get<Scene>(name);