]> git.tdb.fi Git - libs/gl.git/blob - source/builders/sequencetemplate.h
Use shared actions in SequenceTemplate loaders
[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 "postprocessor.h"
11 #include "resources.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         template<typename T>
24         class TemplateLoader: public DataFile::DynamicObjectLoader<typename T::Template>
25         {
26                 friend class SequenceTemplate;
27
28         public:
29                 TemplateLoader(typename DataFile::DynamicObjectLoader<typename T::Template>::Collection &c): DataFile::DynamicObjectLoader<typename T::Template>(&c) { }
30
31         private:
32                 virtual typename DataFile::DynamicObjectLoader<typename T::Template>::TypeRegistry &get_type_registry() const { return get_registry<T>(); }
33         };
34
35         template<typename T>
36         using TemplateRegistry = typename TemplateLoader<T>::TypeRegistry;
37
38 public:
39         class Loader: public DataFile::CollectionObjectLoader<SequenceTemplate>
40         {
41         private:
42                 static ActionMap shared_actions;
43
44         public:
45                 Loader(SequenceTemplate &, Collection &);
46         private:
47                 virtual void init_actions();
48
49                 void clear();
50                 void multisample(unsigned);
51                 void multisample_range(unsigned, unsigned);
52                 void postprocessor();
53                 void postprocessor_with_slot(const std::string &);
54                 void renderable(const std::string &);
55                 void renderable_with_default(const std::string &, const std::string &);
56                 void step(const std::string &, const std::string &);
57         };
58
59         struct Renderable
60         {
61                 GL::Renderable *renderable = 0;
62                 std::string slot_name;
63         };
64
65         struct Step
66         {
67                 class Loader: public DataFile::CollectionObjectLoader<Step>
68                 {
69                 private:
70                         std::string inline_base_name;
71
72                         static ActionMap shared_actions;
73
74                 public:
75                         Loader(Step &, Collection &);
76                 private:
77                         virtual void init_actions();
78
79                 public:
80                         void set_inline_base_name(const std::string &);
81
82                 private:
83                         void depth_test();
84                         void depth_compare(Predicate);
85                         void lighting(const std::string &);
86                         void lighting_inline();
87                         void stencil_test();
88                 };
89
90                 std::string tag;
91                 const Lighting *lighting = 0;
92                 DepthTest depth_test;
93                 StencilTest stencil_test;
94                 std::string renderable_name;
95         };
96
97         struct PostProcessor
98         {
99                 GL::PostProcessor::Template *postprocessor_template;
100                 std::string slot_name;
101
102                 PostProcessor(GL::PostProcessor::Template * = 0);
103         };
104
105 private:
106         class ClearLoader: public DataFile::ObjectLoader<SequenceTemplate>
107         {
108         private:
109                 static ActionMap shared_actions;
110
111         public:
112                 ClearLoader(SequenceTemplate &);
113         private:
114                 virtual void init_actions();
115
116                 void color(float, float, float, float);
117                 void depth(float);
118                 void stencil(int);
119         };
120
121         bool hdr = false;
122         bool alpha = false;
123         unsigned required_multisample = 0;
124         unsigned max_multisample = 0;
125         std::vector<Renderable> renderables;
126         std::vector<Step> steps;
127         std::vector<PostProcessor> postprocessors;
128         bool clear_enabled = false;
129         std::vector<Color> clear_colors;
130         float clear_depth = 1.0f;
131         int clear_stencil = 0;
132
133 public:
134         ~SequenceTemplate();
135
136         bool get_hdr() const { return hdr; }
137         bool get_alpha() const { return alpha; }
138         unsigned get_required_multisample() const { return required_multisample; }
139         unsigned get_maximum_multisample() const { return max_multisample; }
140         const std::vector<Renderable> &get_renderables() const { return renderables; }
141         const std::vector<Step> &get_steps() const { return steps; }
142         const std::vector<PostProcessor> &get_postprocessors() const { return postprocessors; }
143         bool is_clear_enabled() const { return clear_enabled; }
144         const std::vector<Color> &get_clear_colors() const { return clear_colors; }
145         float get_clear_depth() const { return clear_depth; }
146         int get_clear_stencil() const { return clear_stencil; }
147
148         template<typename T>
149         static void register_postprocessor(const std::string &);
150
151 private:
152         template<typename T>
153         static TemplateRegistry<T> &get_registry();
154 };
155
156 template<typename T>
157 void SequenceTemplate::register_postprocessor(const std::string &kw)
158 {
159         get_registry<GL::PostProcessor>().register_type<typename T::Template>(kw);
160 }
161
162 } // namespace GL
163 } // namespace Msp
164
165 #endif