]> git.tdb.fi Git - libs/gl.git/blob - source/builders/sequencetemplate.h
Support effects and subordinate sequences inside sequence templates
[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/dynamicobjectloader.h>
8 #include <msp/datafile/objectloader.h>
9 #include "depthtest.h"
10 #include "effect.h"
11 #include "postprocessor.h"
12 #include "resources.h"
13 #include "stenciltest.h"
14
15 namespace Msp {
16 namespace GL {
17
18 class Lighting;
19 class Renderable;
20
21 class SequenceTemplate
22 {
23 private:
24         template<typename T>
25         class TemplateLoader: public DataFile::DynamicObjectLoader<typename T::Template>
26         {
27                 friend class SequenceTemplate;
28
29         public:
30                 TemplateLoader(typename DataFile::DynamicObjectLoader<typename T::Template>::Collection &c): DataFile::DynamicObjectLoader<typename T::Template>(&c) { }
31
32         private:
33                 virtual typename DataFile::DynamicObjectLoader<typename T::Template>::TypeRegistry &get_type_registry() const { return get_registry<T>(); }
34         };
35
36         template<typename T>
37         using TemplateRegistry = typename TemplateLoader<T>::TypeRegistry;
38
39 public:
40         class Loader: public DataFile::CollectionObjectLoader<SequenceTemplate>
41         {
42         private:
43                 static ActionMap shared_actions;
44
45         public:
46                 Loader(SequenceTemplate &, Collection &);
47         private:
48                 virtual void init_actions();
49
50                 void clear();
51                 void effect(const std::string &);
52                 void multisample(unsigned);
53                 void multisample_range(unsigned, unsigned);
54                 void postprocessor();
55                 void postprocessor_with_slot(const std::string &);
56                 void renderable(const std::string &);
57                 void renderable_with_default(const std::string &, const std::string &);
58                 void sequence(const std::string &, const std::string &);
59                 void step(const std::string &, const std::string &);
60         };
61
62         struct Renderable
63         {
64                 Effect::Template *effect_template = 0;
65                 GL::Renderable *renderable = 0;
66                 SequenceTemplate *sequence_template = 0;
67                 std::map<std::string, std::string> sequence_renderables;
68                 std::string slot_name;
69         };
70
71         struct Step
72         {
73                 class Loader: public DataFile::CollectionObjectLoader<Step>
74                 {
75                 private:
76                         std::string inline_base_name;
77
78                         static ActionMap shared_actions;
79
80                 public:
81                         Loader(Step &, Collection &);
82                 private:
83                         virtual void init_actions();
84
85                 public:
86                         void set_inline_base_name(const std::string &);
87
88                 private:
89                         void depth_test();
90                         void depth_compare(Predicate);
91                         void lighting(const std::string &);
92                         void lighting_inline();
93                         void stencil_test();
94                 };
95
96                 std::string tag;
97                 const Lighting *lighting = 0;
98                 DepthTest depth_test;
99                 StencilTest stencil_test;
100                 std::string renderable_name;
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         class ClearLoader: public DataFile::ObjectLoader<SequenceTemplate>
113         {
114         private:
115                 static ActionMap shared_actions;
116
117         public:
118                 ClearLoader(SequenceTemplate &);
119         private:
120                 virtual void init_actions();
121
122                 void color(float, float, float, float);
123                 void depth(float);
124                 void stencil(int);
125         };
126
127         class SequenceLoader: public DataFile::ObjectLoader<Renderable>
128         {
129         private:
130                 static ActionMap shared_actions;
131
132         public:
133                 SequenceLoader(Renderable &);
134         private:
135                 virtual void init_actions();
136
137                 void renderable(const std::string &, const std::string &);
138         };
139
140         bool hdr = false;
141         bool alpha = false;
142         unsigned required_multisample = 0;
143         unsigned max_multisample = 0;
144         std::vector<Renderable> renderables;
145         std::vector<Step> steps;
146         std::vector<PostProcessor> postprocessors;
147         bool clear_enabled = false;
148         std::vector<Color> clear_colors;
149         float clear_depth = 1.0f;
150         int clear_stencil = 0;
151
152 public:
153         ~SequenceTemplate();
154
155         bool get_hdr() const { return hdr; }
156         bool get_alpha() const { return alpha; }
157         unsigned get_required_multisample() const { return required_multisample; }
158         unsigned get_maximum_multisample() const { return max_multisample; }
159         const std::vector<Renderable> &get_renderables() const { return renderables; }
160         const std::vector<Step> &get_steps() const { return steps; }
161         const std::vector<PostProcessor> &get_postprocessors() const { return postprocessors; }
162         bool is_clear_enabled() const { return clear_enabled; }
163         const std::vector<Color> &get_clear_colors() const { return clear_colors; }
164         float get_clear_depth() const { return clear_depth; }
165         int get_clear_stencil() const { return clear_stencil; }
166
167         template<typename T>
168         static void register_effect(const std::string &);
169
170         template<typename T>
171         static void register_postprocessor(const std::string &);
172
173 private:
174         template<typename T>
175         static TemplateRegistry<T> &get_registry();
176 };
177
178 template<typename T>
179 void SequenceTemplate::register_effect(const std::string &kw)
180 {
181         get_registry<Effect>().register_type<typename T::Template>(kw);
182 }
183
184 template<typename T>
185 void SequenceTemplate::register_postprocessor(const std::string &kw)
186 {
187         get_registry<GL::PostProcessor>().register_type<typename T::Template>(kw);
188 }
189
190 } // namespace GL
191 } // namespace Msp
192
193 #endif