]> git.tdb.fi Git - libs/gl.git/blobdiff - source/pipelinetemplate.h
Use RED format for ambient occlusion render target
[libs/gl.git] / source / pipelinetemplate.h
index cdf73ac7c01c465764464863218e2ff5cc67db6b..d98633539e06dff0dac89b3ef71d5f1478243676 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <string>
 #include <vector>
+#include <msp/datafile/loadabletyperegistry.h>
 #include <msp/datafile/objectloader.h>
 #include "blend.h"
 #include "postprocessor.h"
@@ -19,6 +20,13 @@ class PipelineTemplate
 public:
        class Loader: public DataFile::CollectionObjectLoader<PipelineTemplate>
        {
+       private:
+               template<typename T>
+               struct AddPostProc
+               {
+                       static void add(Loader &ldr, const std::string &kw) { ldr.add(kw, &Loader::postprocessor<T>); }
+               };
+
        public:
                Loader(PipelineTemplate &);
                Loader(PipelineTemplate &, Collection &);
@@ -31,6 +39,8 @@ public:
 
                template<typename T>
                void postprocessor();
+
+               friend class PipelineTemplate;
        };
 
        struct Pass
@@ -67,6 +77,8 @@ public:
        typedef std::vector<PostProcessor::Template *> PostProcessorArray;
 
 private:
+       typedef DataFile::LoadableTypeRegistry<Loader, Loader::AddPostProc> PostProcessorRegistry;
+
        bool hdr;
        unsigned required_multisample;
        unsigned max_multisample;
@@ -82,8 +94,27 @@ public:
        unsigned get_maximum_multisample() const { return max_multisample; }
        const PassArray &get_passes() const { return passes; }
        const PostProcessorArray &get_postprocessors() const { return postprocessors; }
+
+       template<typename T>
+       static void register_postprocessor(const std::string &);
+private:
+       static PostProcessorRegistry &get_postprocessor_registry();
 };
 
+template<typename T>
+void PipelineTemplate::register_postprocessor(const std::string &kw)
+{
+       get_postprocessor_registry().register_type<T>(kw);
+}
+
+template<typename T>
+void PipelineTemplate::Loader::postprocessor()
+{
+       RefPtr<typename T::Template> postproc = new typename T::Template;
+       load_sub(*postproc);
+       obj.postprocessors.push_back(postproc.release());
+}
+
 } // namespace GL
 } // namespace Msp