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():
19 required_multisample(0),
23 PipelineTemplate::~PipelineTemplate()
25 for(PostProcessorArray::iterator i=postprocessors.begin(); i!=postprocessors.end(); ++i)
26 delete i->postprocessor_template;
30 PipelineTemplate::PostProcessorRegistry &PipelineTemplate::get_postprocessor_registry()
32 static PostProcessorRegistry registry;
33 static bool initialized = false;
36 registry.register_type<AmbientOcclusion>("ambient_occlusion");
37 registry.register_type<Bloom>("bloom");
38 registry.register_type<ColorCurve>("colorcurve");
45 PipelineTemplate::Pass::~Pass()
49 PipelineTemplate::PostProcessor::PostProcessor(GL::PostProcessor::Template *ppt):
50 postprocessor_template(ppt)
54 PipelineTemplate::PostProcLoader::PostProcLoader()
56 get_postprocessor_registry().add_all(*this);
60 PipelineTemplate::Loader::Loader(PipelineTemplate &t):
61 DataFile::CollectionObjectLoader<PipelineTemplate>(t, 0)
66 PipelineTemplate::Loader::Loader(PipelineTemplate &t, Collection &c):
67 DataFile::CollectionObjectLoader<PipelineTemplate>(t, &c)
72 void PipelineTemplate::Loader::init()
74 add("hdr", &PipelineTemplate::hdr);
75 add("alpha", &PipelineTemplate::alpha);
76 add("multisample", &Loader::multisample);
77 add("multisample", &Loader::multisample_range);
78 add("pass", &Loader::pass);
79 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 std::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);