]> git.tdb.fi Git - libs/gl.git/blob - source/builders/sequencetemplate.h
Use default member initializers for simple types
[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 "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         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 clear();
58                 void multisample(unsigned);
59                 void multisample_range(unsigned, unsigned);
60                 void postprocessor(const std::string &);
61                 void step(const std::string &);
62                 void step_with_slot(const std::string &, const std::string &);
63         };
64
65         struct Step
66         {
67                 class Loader: public DataFile::CollectionObjectLoader<Step>
68                 {
69                 private:
70                         std::string inline_base_name;
71
72                 public:
73                         Loader(Step &, Collection &);
74
75                         void set_inline_base_name(const std::string &);
76
77                 private:
78                         void blend();
79                         void blend_factors(BlendFactor, BlendFactor);
80                         void depth_test();
81                         void depth_compare(Predicate);
82                         void lighting(const std::string &);
83                         void lighting_inline();
84                         void object(const std::string &);
85                         void scene(const std::string &);
86                         void stencil_test();
87                 };
88
89                 std::string tag;
90                 const Lighting *lighting = 0;
91                 DepthTest depth_test;
92                 StencilTest stencil_test;
93                 Blend blend;
94                 std::string slot_name;
95                 Renderable *default_renderable = 0;
96         };
97
98         struct PostProcessor
99         {
100                 GL::PostProcessor::Template *postprocessor_template;
101                 std::string slot_name;
102
103                 PostProcessor(GL::PostProcessor::Template * = 0);
104         };
105
106 private:
107         class ClearLoader: public DataFile::ObjectLoader<SequenceTemplate>
108         {
109         public:
110                 ClearLoader(SequenceTemplate &);
111
112         private:
113                 void color(float, float, float, float);
114                 void depth(float);
115                 void stencil(int);
116         };
117
118         typedef TypeRegistry<PostProcLoader::AddPostProc, PostProcLoader &> PostProcessorRegistry;
119
120         bool hdr = false;
121         bool alpha = false;
122         unsigned required_multisample = 0;
123         unsigned max_multisample = 0;
124         std::vector<Step> steps;
125         std::vector<PostProcessor> postprocessors;
126         bool clear_enabled = false;
127         std::vector<Color> clear_colors;
128         float clear_depth = 1.0f;
129         int clear_stencil = 0;
130
131 public:
132         ~SequenceTemplate();
133
134         bool get_hdr() const { return hdr; }
135         bool get_alpha() const { return alpha; }
136         unsigned get_required_multisample() const { return required_multisample; }
137         unsigned get_maximum_multisample() const { return max_multisample; }
138         const std::vector<Step> &get_steps() const { return steps; }
139         const std::vector<PostProcessor> &get_postprocessors() const { return postprocessors; }
140         bool is_clear_enabled() const { return clear_enabled; }
141         const std::vector<Color> &get_clear_colors() const { return clear_colors; }
142         float get_clear_depth() const { return clear_depth; }
143         int get_clear_stencil() const { return clear_stencil; }
144
145         template<typename T>
146         static void register_postprocessor(const std::string &);
147 private:
148         static PostProcessorRegistry &get_postprocessor_registry();
149 };
150
151 template<typename T>
152 void SequenceTemplate::register_postprocessor(const std::string &kw)
153 {
154         get_postprocessor_registry().register_type<T>(kw);
155 }
156
157 template<typename T>
158 void SequenceTemplate::PostProcLoader::postprocessor()
159 {
160         if(postproc)
161                 throw std::logic_error("Only one postprocessor allowed per slot");
162         RefPtr<typename T::Template> pp = new typename T::Template;
163         load_sub(*pp);
164         postproc = pp;
165         pp = 0;
166         postprocessor_loaded();
167 }
168
169 } // namespace GL
170 } // namespace Msp
171
172 #endif