]> git.tdb.fi Git - libs/gl.git/blob - source/builders/sequencetemplate.h
Add inline data items to the collection
[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 "postprocessor.h"
10 #include "predicate.h"
11
12 namespace Msp {
13 namespace GL {
14
15 class DepthTest;
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                 virtual void postprocessor_loaded();
56                 void multisample(unsigned);
57                 void multisample_range(unsigned, unsigned);
58                 void postprocessor(const std::string &);
59                 void step(const std::string &);
60                 void step_with_slot(const std::string &, const std::string &);
61         };
62
63         struct Step
64         {
65                 class Loader: public DataFile::CollectionObjectLoader<Step>
66                 {
67                 private:
68                         std::string inline_base_name;
69
70                 public:
71                         Loader(Step &);
72                         Loader(Step &, Collection &);
73                 private:
74                         void init();
75
76                 public:
77                         void set_inline_base_name(const std::string &);
78
79                 private:
80                         void blend(BlendFactor, BlendFactor);
81                         void blend_predefined(const std::string &);
82                         void depth_test(Predicate);
83                         void depth_test_predefined(const std::string &);
84                         void lighting(const std::string &);
85                         void lighting_inline();
86                         void object(const std::string &);
87                         void scene(const std::string &);
88                 };
89
90                 std::string tag;
91                 const Lighting *lighting;
92                 RefPtr<const DepthTest> depth_test;
93                 RefPtr<const Blend> blend;
94                 std::string slot_name;
95                 Renderable *default_renderable;
96
97                 ~Step();
98         };
99
100         struct PostProcessor
101         {
102                 GL::PostProcessor::Template *postprocessor_template;
103                 std::string slot_name;
104
105                 PostProcessor(GL::PostProcessor::Template * = 0);
106         };
107
108         typedef std::vector<PostProcessor> PostProcessorArray;
109
110 private:
111         typedef TypeRegistry<PostProcLoader::AddPostProc, PostProcLoader &> PostProcessorRegistry;
112
113         bool hdr;
114         bool alpha;
115         unsigned required_multisample;
116         unsigned max_multisample;
117         std::vector<Step> steps;
118         PostProcessorArray postprocessors;
119
120 public:
121         SequenceTemplate();
122         ~SequenceTemplate();
123
124         bool get_hdr() const { return hdr; }
125         bool get_alpha() const { return alpha; }
126         unsigned get_required_multisample() const { return required_multisample; }
127         unsigned get_maximum_multisample() const { return max_multisample; }
128         const std::vector<Step> &get_steps() const { return steps; }
129         const PostProcessorArray &get_postprocessors() const { return postprocessors; }
130
131         template<typename T>
132         static void register_postprocessor(const std::string &);
133 private:
134         static PostProcessorRegistry &get_postprocessor_registry();
135 };
136
137 template<typename T>
138 void SequenceTemplate::register_postprocessor(const std::string &kw)
139 {
140         get_postprocessor_registry().register_type<T>(kw);
141 }
142
143 template<typename T>
144 void SequenceTemplate::PostProcLoader::postprocessor()
145 {
146         if(postproc)
147                 throw std::logic_error("Only one postprocessor allowed per slot");
148         RefPtr<typename T::Template> pp = new typename T::Template;
149         load_sub(*pp);
150         postproc = pp;
151         pp = 0;
152         postprocessor_loaded();
153 }
154
155 } // namespace GL
156 } // namespace Msp
157
158 #endif