]> git.tdb.fi Git - libs/gl.git/blob - source/pipelinetemplate.h
Add the specializations for non-square matrix uniforms
[libs/gl.git] / source / pipelinetemplate.h
1 #ifndef PIPELINETEMPLATE_H_
2 #define PIPELINETEMPLATE_H_
3
4 #include <string>
5 #include <vector>
6 #include <msp/datafile/loadabletyperegistry.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
18 class PipelineTemplate
19 {
20 private:
21         class PostProcLoader: virtual public DataFile::Loader
22         {
23         private:
24                 template<typename T>
25                 struct AddPostProc
26                 {
27                         static void add(PostProcLoader &ldr, const std::string &kw) { ldr.add(kw, &PostProcLoader::postprocessor<T>); }
28                 };
29
30         protected:
31                 RefPtr<PostProcessor::Template> postproc;
32
33         public:
34                 PostProcLoader();
35
36                 PostProcessor::Template *get_postprocessor_template() { return postproc.release(); }
37
38         protected:
39                 virtual void postprocessor_loaded() { }
40
41         private:
42                 template<typename T>
43                 void postprocessor();
44
45                 friend class PipelineTemplate;
46         };
47
48 public:
49         class Loader: public DataFile::CollectionObjectLoader<PipelineTemplate>, public PostProcLoader
50         {
51         public:
52                 Loader(PipelineTemplate &);
53                 Loader(PipelineTemplate &, Collection &);
54         private:
55                 void init();
56
57                 virtual void postprocessor_loaded();
58                 void multisample(unsigned);
59                 void multisample_range(unsigned, unsigned);
60                 void pass(const std::string &, const std::string &);
61                 void postprocessor(const std::string &);
62         };
63
64         struct Pass
65         {
66                 class Loader: public DataFile::CollectionObjectLoader<Pass>
67                 {
68                 public:
69                         Loader(Pass &);
70                         Loader(Pass &, Collection &);
71                 private:
72                         void init();
73
74                         void blend(BlendFactor, BlendFactor);
75                         void blend_predefined(const std::string &);
76                         void depth_test(Predicate);
77                         void depth_test_predefined(const std::string &);
78                         void lighting(const std::string &);
79                         void lighting_inline();
80                         // TODO requires support for scenes in Resources
81                         //void scene(const std::string &);
82                 };
83
84                 std::string tag;
85                 RefPtr<Lighting> lighting;
86                 RefPtr<const DepthTest> depth_test;
87                 RefPtr<const Blend> blend;
88                 std::string renderable_name;
89                 //Renderable *default_renderable;
90
91                 ~Pass();
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         typedef std::vector<Pass> PassArray;
103         typedef std::vector<PostProcessor> PostProcessorArray;
104
105 private:
106         typedef DataFile::LoadableTypeRegistry<PostProcLoader, PostProcLoader::AddPostProc> PostProcessorRegistry;
107
108         bool hdr;
109         bool alpha;
110         unsigned required_multisample;
111         unsigned max_multisample;
112         PassArray passes;
113         PostProcessorArray postprocessors;
114
115 public:
116         PipelineTemplate();
117         ~PipelineTemplate();
118
119         bool get_hdr() const { return hdr; }
120         bool get_alpha() const { return alpha; }
121         unsigned get_required_multisample() const { return required_multisample; }
122         unsigned get_maximum_multisample() const { return max_multisample; }
123         const PassArray &get_passes() const { return passes; }
124         const PostProcessorArray &get_postprocessors() const { return postprocessors; }
125
126         template<typename T>
127         static void register_postprocessor(const std::string &);
128 private:
129         static PostProcessorRegistry &get_postprocessor_registry();
130 };
131
132 template<typename T>
133 void PipelineTemplate::register_postprocessor(const std::string &kw)
134 {
135         get_postprocessor_registry().register_type<T>(kw);
136 }
137
138 template<typename T>
139 void PipelineTemplate::PostProcLoader::postprocessor()
140 {
141         if(postproc)
142                 throw std::logic_error("Only one postprocessor allowed per slot");
143         RefPtr<typename T::Template> pp = new typename T::Template;
144         load_sub(*pp);
145         postproc = pp;
146         pp = 0;
147         postprocessor_loaded();
148 }
149
150 } // namespace GL
151 } // namespace Msp
152
153 #endif