X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fpipelinetemplate.cpp;fp=source%2Fpipelinetemplate.cpp;h=6dbfd0a247721edbb6e4f88521d6bee02a742b45;hp=0000000000000000000000000000000000000000;hb=18240e2bb031551e9c72a55c7d974904d209760a;hpb=e6bd08e977f3138bfcfa3a1b6cc45201c383e016 diff --git a/source/pipelinetemplate.cpp b/source/pipelinetemplate.cpp new file mode 100644 index 00000000..6dbfd0a2 --- /dev/null +++ b/source/pipelinetemplate.cpp @@ -0,0 +1,161 @@ +#include +#include +#include "blend.h" +#include "bloom.h" +#include "colorcurve.h" +#include "lighting.h" +#include "pipelinetemplate.h" +#include "tests.h" + +using namespace std; + +namespace Msp { +namespace GL { + +PipelineTemplate::PipelineTemplate(): + hdr(false), + required_multisample(0), + max_multisample(0) +{ } + + +PipelineTemplate::Pass::~Pass() +{ } + + +PipelineTemplate::Loader::Loader(PipelineTemplate &t): + DataFile::CollectionObjectLoader(t, 0) +{ + init(); +} + +PipelineTemplate::Loader::Loader(PipelineTemplate &t, Collection &c): + DataFile::CollectionObjectLoader(t, &c) +{ + init(); +} + +void PipelineTemplate::Loader::init() +{ + add("bloom", &Loader::postprocessor); + add("colorcurve", &Loader::postprocessor); + add("hdr", &PipelineTemplate::hdr); + add("multisample", &Loader::multisample); + add("multisample", &Loader::multisample_range); + add("pass", &Loader::pass); +} + +void PipelineTemplate::Loader::multisample(unsigned samples) +{ + obj.required_multisample = samples; + obj.max_multisample = samples; +} + +void PipelineTemplate::Loader::multisample_range(unsigned req, unsigned max) +{ + obj.required_multisample = req; + obj.max_multisample = max; +} + +void PipelineTemplate::Loader::pass(const string &tag, const string &rend) +{ + Pass pss;; + pss.tag = tag; + pss.renderable_name = rend; + if(coll) + load_sub(pss, *coll); + else + load_sub(pss); + + obj.passes.push_back(pss); +} + +template +void PipelineTemplate::Loader::postprocessor() +{ + RefPtr postproc = new typename T::Template; + load_sub(*postproc); + obj.postprocessors.push_back(postproc.release()); +} + + +PipelineTemplate::Pass::Loader::Loader(Pass &p): + DataFile::CollectionObjectLoader(p, 0) +{ + init(); +} + +PipelineTemplate::Pass::Loader::Loader(Pass &p, Collection &c): + DataFile::CollectionObjectLoader(p, &c) +{ + init(); +} + +void PipelineTemplate::Pass::Loader::init() +{ + add("blend", &Loader::blend); + add("blend", &Loader::blend_predefined); + add("depth_test", &Loader::depth_test); + add("depth_test", &Loader::depth_test_predefined); + add("lighting", &Loader::lighting); + add("lighting", &Loader::lighting_inline); +} + +void PipelineTemplate::Pass::Loader::blend_predefined(const string &name) +{ + const Blend *blend = 0; + if(name=="alpha") + blend = &Blend::alpha(); + else if(name=="additive") + blend = &Blend::additive(); + else if(name=="additive_alpha") + blend = &Blend::additive_alpha(); + else + throw key_error(name); + + obj.blend = blend; + obj.blend.keep(); +} + +void PipelineTemplate::Pass::Loader::blend(BlendFactor src, BlendFactor dest) +{ + obj.blend = new Blend(src, dest); +} + +void PipelineTemplate::Pass::Loader::depth_test_predefined(const string &name) +{ + const DepthTest *dtest = 0; + if(name=="lequal") + dtest = &DepthTest::lequal(); + else + throw key_error(name); + + obj.depth_test = dtest; + obj.depth_test.keep(); +} + +void PipelineTemplate::Pass::Loader::depth_test(Predicate pred) +{ + obj.depth_test = new DepthTest(pred); +} + +void PipelineTemplate::Pass::Loader::lighting_inline() +{ + RefPtr lightn = new Lighting; + load_sub(*lightn); + obj.lighting = lightn; +} + +void PipelineTemplate::Pass::Loader::lighting(const string &name) +{ + obj.lighting = &get_collection().get(name); + obj.lighting.keep(); +} + +/*void PipelineTemplate::Pass::Loader::scene(const string &name) +{ + obj.default_renderable = get_collection().get(name); +}*/ + +} // namespace GL +} // namespace Msp