]> git.tdb.fi Git - libs/gl.git/blob - source/builders/sequencetemplate.h
Use C++11 features with containers
[libs/gl.git] / source / builders / sequencetemplate.h
1 #ifndef SEQUENCETEMPLATE_H_
2 #define SEQUENCETEMPLATE_H_
3
4 #include <string>
5 #include <vector>
6 #include <msp/core/typeregistry.h>
7 #include <msp/datafile/objectloader.h>
8 #include "blend.h"
9 #include "depthtest.h"
10 #include "postprocessor.h"
11 #include "predicate.h"
12 #include "stenciltest.h"
13
14 namespace Msp {
15 namespace GL {
16
17 class Lighting;
18 class Renderable;
19
20 class SequenceTemplate
21 {
22 private:
23         class PostProcLoader: virtual public DataFile::Loader
24         {
25         private:
26                 template<typename T>
27                 struct AddPostProc
28                 {
29                         void operator()(const std::string &kw, PostProcLoader &ldr) const { ldr.add(kw, &PostProcLoader::postprocessor<T>); }
30                 };
31
32         protected:
33                 RefPtr<PostProcessor::Template> postproc;
34
35         public:
36                 PostProcLoader();
37
38                 PostProcessor::Template *get_postprocessor_template() { return postproc.release(); }
39
40         protected:
41                 virtual void postprocessor_loaded() { }
42
43         private:
44                 template<typename T>
45                 void postprocessor();
46
47                 friend class SequenceTemplate;
48         };
49
50 public:
51         class Loader: public DataFile::CollectionObjectLoader<SequenceTemplate, Resources>, public PostProcLoader
52         {
53         public:
54                 Loader(SequenceTemplate &, Collection &);
55
56                 virtual void postprocessor_loaded();
57                 void multisample(unsigned);
58                 void multisample_range(unsigned, unsigned);
59                 void postprocessor(const std::string &);
60                 void step(const std::string &);
61                 void step_with_slot(const std::string &, const std::string &);
62         };
63
64         struct Step
65         {
66                 class Loader: public DataFile::CollectionObjectLoader<Step>
67                 {
68                 private:
69                         std::string inline_base_name;
70
71                 public:
72                         Loader(Step &);
73                         Loader(Step &, Collection &);
74                 private:
75                         void init();
76
77                 public:
78                         void set_inline_base_name(const std::string &);
79
80                 private:
81                         void blend();
82                         void blend_factors(BlendFactor, BlendFactor);
83                         void depth_test();
84                         void depth_compare(Predicate);
85                         void lighting(const std::string &);
86                         void lighting_inline();
87                         void object(const std::string &);
88                         void scene(const std::string &);
89                         void stencil_test();
90                 };
91
92                 std::string tag;
93                 const Lighting *lighting;
94                 DepthTest depth_test;
95                 StencilTest stencil_test;
96                 Blend blend;
97                 std::string slot_name;
98                 Renderable *default_renderable;
99
100                 ~Step();
101         };
102
103         struct PostProcessor
104         {
105                 GL::PostProcessor::Template *postprocessor_template;
106                 std::string slot_name;
107
108                 PostProcessor(GL::PostProcessor::Template * = 0);
109         };
110
111 private:
112         typedef TypeRegistry<PostProcLoader::AddPostProc, PostProcLoader &> PostProcessorRegistry;
113
114         bool hdr;
115         bool alpha;
116         unsigned required_multisample;
117         unsigned max_multisample;
118         std::vector<Step> steps;
119         std::vector<PostProcessor> postprocessors;
120
121 public:
122         SequenceTemplate();
123         ~SequenceTemplate();
124
125         bool get_hdr() const { return hdr; }
126         bool get_alpha() const { return alpha; }
127         unsigned get_required_multisample() const { return required_multisample; }
128         unsigned get_maximum_multisample() const { return max_multisample; }
129         const std::vector<Step> &get_steps() const { return steps; }
130         const std::vector<PostProcessor> &get_postprocessors() const { return postprocessors; }
131
132         template<typename T>
133         static void register_postprocessor(const std::string &);
134 private:
135         static PostProcessorRegistry &get_postprocessor_registry();
136 };
137
138 template<typename T>
139 void SequenceTemplate::register_postprocessor(const std::string &kw)
140 {
141         get_postprocessor_registry().register_type<T>(kw);
142 }
143
144 template<typename T>
145 void SequenceTemplate::PostProcLoader::postprocessor()
146 {
147         if(postproc)
148                 throw std::logic_error("Only one postprocessor allowed per slot");
149         RefPtr<typename T::Template> pp = new typename T::Template;
150         load_sub(*pp);
151         postproc = pp;
152         pp = 0;
153         postprocessor_loaded();
154 }
155
156 } // namespace GL
157 } // namespace Msp
158
159 #endif