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