]> git.tdb.fi Git - libs/gl.git/blob - source/builders/sequencetemplate.h
Restore missing private access specifier
[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 "depthtest.h"
9 #include "postprocessor.h"
10 #include "resources.h"
11 #include "stenciltest.h"
12
13 namespace Msp {
14 namespace GL {
15
16 class Lighting;
17 class Renderable;
18
19 class SequenceTemplate
20 {
21 private:
22         class PostProcLoader: virtual public DataFile::Loader
23         {
24         private:
25                 template<typename T>
26                 struct AddPostProc
27                 {
28                         void operator()(const std::string &kw, PostProcLoader &ldr) const { ldr.add(kw, &PostProcLoader::postprocessor<T>); }
29                 };
30
31         protected:
32                 RefPtr<PostProcessor::Template> postproc;
33
34         public:
35                 PostProcLoader();
36
37                 PostProcessor::Template *get_postprocessor_template() { return postproc.release(); }
38
39         protected:
40                 virtual void postprocessor_loaded() { }
41
42         private:
43                 template<typename T>
44                 void postprocessor();
45
46                 friend class SequenceTemplate;
47         };
48
49 public:
50         class Loader: public DataFile::CollectionObjectLoader<SequenceTemplate, Resources>, public PostProcLoader
51         {
52         public:
53                 Loader(SequenceTemplate &, Collection &);
54
55         private:
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 depth_test();
79                         void depth_compare(Predicate);
80                         void lighting(const std::string &);
81                         void lighting_inline();
82                         void object(const std::string &);
83                         void scene(const std::string &);
84                         void stencil_test();
85                 };
86
87                 std::string tag;
88                 const Lighting *lighting = 0;
89                 DepthTest depth_test;
90                 StencilTest stencil_test;
91                 std::string slot_name;
92                 Renderable *default_renderable = 0;
93         };
94
95         struct PostProcessor
96         {
97                 GL::PostProcessor::Template *postprocessor_template;
98                 std::string slot_name;
99
100                 PostProcessor(GL::PostProcessor::Template * = 0);
101         };
102
103 private:
104         class ClearLoader: public DataFile::ObjectLoader<SequenceTemplate>
105         {
106         public:
107                 ClearLoader(SequenceTemplate &);
108
109         private:
110                 void color(float, float, float, float);
111                 void depth(float);
112                 void stencil(int);
113         };
114
115         typedef TypeRegistry<PostProcLoader::AddPostProc, PostProcLoader &> PostProcessorRegistry;
116
117         bool hdr = false;
118         bool alpha = false;
119         unsigned required_multisample = 0;
120         unsigned max_multisample = 0;
121         std::vector<Step> steps;
122         std::vector<PostProcessor> postprocessors;
123         bool clear_enabled = false;
124         std::vector<Color> clear_colors;
125         float clear_depth = 1.0f;
126         int clear_stencil = 0;
127
128 public:
129         ~SequenceTemplate();
130
131         bool get_hdr() const { return hdr; }
132         bool get_alpha() const { return alpha; }
133         unsigned get_required_multisample() const { return required_multisample; }
134         unsigned get_maximum_multisample() const { return max_multisample; }
135         const std::vector<Step> &get_steps() const { return steps; }
136         const std::vector<PostProcessor> &get_postprocessors() const { return postprocessors; }
137         bool is_clear_enabled() const { return clear_enabled; }
138         const std::vector<Color> &get_clear_colors() const { return clear_colors; }
139         float get_clear_depth() const { return clear_depth; }
140         int get_clear_stencil() const { return clear_stencil; }
141
142         template<typename T>
143         static void register_postprocessor(const std::string &);
144 private:
145         static PostProcessorRegistry &get_postprocessor_registry();
146 };
147
148 template<typename T>
149 void SequenceTemplate::register_postprocessor(const std::string &kw)
150 {
151         get_postprocessor_registry().register_type<T>(kw);
152 }
153
154 template<typename T>
155 void SequenceTemplate::PostProcLoader::postprocessor()
156 {
157         if(postproc)
158                 throw std::logic_error("Only one postprocessor allowed per slot");
159         RefPtr<typename T::Template> pp = new typename T::Template;
160         load_sub(*pp);
161         postproc = pp;
162         pp = 0;
163         postprocessor_loaded();
164 }
165
166 } // namespace GL
167 } // namespace Msp
168
169 #endif