]> git.tdb.fi Git - libs/gl.git/blob - source/pipelinetemplate.h
Use RED format for ambient occlusion render target
[libs/gl.git] / source / pipelinetemplate.h
1 #ifndef PIPELINETEMPLATE_H_
2 #define PIPELINETEMPLATE_H_
3
4 #include <string>
5 #include <vector>
6 #include <msp/datafile/loadabletyperegistry.h>
7 #include <msp/datafile/objectloader.h>
8 #include "blend.h"
9 #include "postprocessor.h"
10 #include "predicate.h"
11
12 namespace Msp {
13 namespace GL {
14
15 class DepthTest;
16 class Lighting;
17
18 class PipelineTemplate
19 {
20 public:
21         class Loader: public DataFile::CollectionObjectLoader<PipelineTemplate>
22         {
23         private:
24                 template<typename T>
25                 struct AddPostProc
26                 {
27                         static void add(Loader &ldr, const std::string &kw) { ldr.add(kw, &Loader::postprocessor<T>); }
28                 };
29
30         public:
31                 Loader(PipelineTemplate &);
32                 Loader(PipelineTemplate &, Collection &);
33         private:
34                 void init();
35
36                 void multisample(unsigned);
37                 void multisample_range(unsigned, unsigned);
38                 void pass(const std::string &, const std::string &);
39
40                 template<typename T>
41                 void postprocessor();
42
43                 friend class PipelineTemplate;
44         };
45
46         struct Pass
47         {
48                 class Loader: public DataFile::CollectionObjectLoader<Pass>
49                 {
50                 public:
51                         Loader(Pass &);
52                         Loader(Pass &, Collection &);
53                 private:
54                         void init();
55
56                         void blend(BlendFactor, BlendFactor);
57                         void blend_predefined(const std::string &);
58                         void depth_test(Predicate);
59                         void depth_test_predefined(const std::string &);
60                         void lighting(const std::string &);
61                         void lighting_inline();
62                         // TODO requires support for scenes in Resources
63                         //void scene(const std::string &);
64                 };
65
66                 std::string tag;
67                 RefPtr<Lighting> lighting;
68                 RefPtr<const DepthTest> depth_test;
69                 RefPtr<const Blend> blend;
70                 std::string renderable_name;
71                 //Renderable *default_renderable;
72
73                 ~Pass();
74         };
75
76         typedef std::vector<Pass> PassArray;
77         typedef std::vector<PostProcessor::Template *> PostProcessorArray;
78
79 private:
80         typedef DataFile::LoadableTypeRegistry<Loader, Loader::AddPostProc> PostProcessorRegistry;
81
82         bool hdr;
83         unsigned required_multisample;
84         unsigned max_multisample;
85         PassArray passes;
86         PostProcessorArray postprocessors;
87
88 public:
89         PipelineTemplate();
90         ~PipelineTemplate();
91
92         bool get_hdr() const { return hdr; }
93         unsigned get_required_multisample() const { return required_multisample; }
94         unsigned get_maximum_multisample() const { return max_multisample; }
95         const PassArray &get_passes() const { return passes; }
96         const PostProcessorArray &get_postprocessors() const { return postprocessors; }
97
98         template<typename T>
99         static void register_postprocessor(const std::string &);
100 private:
101         static PostProcessorRegistry &get_postprocessor_registry();
102 };
103
104 template<typename T>
105 void PipelineTemplate::register_postprocessor(const std::string &kw)
106 {
107         get_postprocessor_registry().register_type<T>(kw);
108 }
109
110 template<typename T>
111 void PipelineTemplate::Loader::postprocessor()
112 {
113         RefPtr<typename T::Template> postproc = new typename T::Template;
114         load_sub(*postproc);
115         obj.postprocessors.push_back(postproc.release());
116 }
117
118 } // namespace GL
119 } // namespace Msp
120
121 #endif