]> git.tdb.fi Git - libs/gl.git/blob - source/builders/sequencetemplate.h
Set color write mask if no blending is used
[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         unsigned required_multisample = 0;
142         unsigned max_multisample = 0;
143         std::vector<Renderable> renderables;
144         std::vector<Step> steps;
145         std::vector<PostProcessor> postprocessors;
146         bool clear_enabled = false;
147         std::vector<Color> clear_colors;
148         float clear_depth = 1.0f;
149         int clear_stencil = 0;
150
151 public:
152         ~SequenceTemplate();
153
154         bool get_hdr() const { return hdr; }
155         unsigned get_required_multisample() const { return required_multisample; }
156         unsigned get_maximum_multisample() const { return max_multisample; }
157         const std::vector<Renderable> &get_renderables() const { return renderables; }
158         const std::vector<Step> &get_steps() const { return steps; }
159         const std::vector<PostProcessor> &get_postprocessors() const { return postprocessors; }
160         bool is_clear_enabled() const { return clear_enabled; }
161         const std::vector<Color> &get_clear_colors() const { return clear_colors; }
162         float get_clear_depth() const { return clear_depth; }
163         int get_clear_stencil() const { return clear_stencil; }
164
165         template<typename T>
166         static void register_effect(const std::string &);
167
168         template<typename T>
169         static void register_postprocessor(const std::string &);
170
171 private:
172         template<typename T>
173         static TemplateRegistry<T> &get_registry();
174 };
175
176 template<typename T>
177 void SequenceTemplate::register_effect(const std::string &kw)
178 {
179         get_registry<Effect>().register_type<typename T::Template>(kw);
180 }
181
182 template<typename T>
183 void SequenceTemplate::register_postprocessor(const std::string &kw)
184 {
185         get_registry<GL::PostProcessor>().register_type<typename T::Template>(kw);
186 }
187
188 } // namespace GL
189 } // namespace Msp
190
191 #endif