]> git.tdb.fi Git - libs/gl.git/blob - source/pipeline.h
Remove dynamic allocation from VertexFormat
[libs/gl.git] / source / pipeline.h
1 #ifndef MSP_GL_PIPELINE_H_
2 #define MSP_GL_PIPELINE_H_
3
4 #include <map>
5 #include <set>
6 #include "framebuffer.h"
7 #include "renderable.h"
8 #include "renderbuffer.h"
9 #include "texture2d.h"
10
11 namespace Msp {
12 namespace GL {
13
14 class Blend;
15 class Camera;
16 class Clipping;
17 class DepthTest;
18 class Lighting;
19 class PostProcessor;
20
21 /**
22 Encapsulates all of the information used to produce a complete image in the
23 framebuffer.  This is the highest level rendering class.
24
25 A Pipeline contains a sequence of passes.  Each pass has a Renderable along
26 with Lighting, Clipping, DepthTest and Blend states.  Scenes can be used to
27 organize Renderables within a pass.  A Camera can be specified for the entire
28 Pipeline.
29
30 A Pipeline is also a Renderable itself.  It will only respond to the default
31 pass.  The Renderables within the Pipeline will be invoked with whatever tags
32 were specified when adding them.
33
34 A Pipeline's render method should normally be called without a Renderer; it
35 will create one itself, using the camera specified for the Pipeline.  If a
36 Renderer is passed, its camera will be used instead.
37
38 PostProcessors can be applied after all of the passes in the Pipeline have been
39 rendered.  Framebuffer objects are automatically used to pass render results to
40 the PostProcessors.  High dynamic range and multisample rendering can be
41 requested for increased quality.
42 */
43 class Pipeline: public Renderable
44 {
45 public:
46         class Pass
47         {
48         private:
49                 Tag tag;
50                 const Lighting *lighting;
51                 const DepthTest *depth_test;
52                 const Blend *blend;
53                 const Clipping *clipping;
54                 const Renderable *renderable;
55
56         public:
57                 Pass(const Tag &, const Renderable *);
58
59                 const Tag &get_tag() const { return tag; }
60
61                 void set_lighting(const Lighting *);
62                 void set_depth_test(const DepthTest *);
63                 void set_blend(const Blend *);
64                 void set_clipping(const Clipping *);
65                 const Lighting *get_lighting() const { return lighting; }
66                 const DepthTest *get_depth_test() const { return depth_test; }
67                 const Blend *get_blend() const { return blend; }
68                 const Clipping *get_clipping() const { return clipping; }
69                 const Renderable *get_renderable() const { return renderable; }
70         };
71
72 private:
73         struct Slot
74         {
75                 const Renderable *renderable;
76                 std::set<Tag> passes;
77
78                 Slot(const Renderable *);
79         };
80
81         struct RenderTarget
82         {
83                 Framebuffer fbo;
84                 Texture2D color;
85                 Texture2D depth;
86
87                 RenderTarget(unsigned, unsigned, PixelFormat);
88         };
89
90         struct MultisampleTarget
91         {
92                 Framebuffer fbo;
93                 Renderbuffer color;
94                 Renderbuffer depth;
95
96                 MultisampleTarget(unsigned, unsigned, unsigned, PixelFormat);
97         };
98
99         typedef std::list<Pass> PassList;
100
101         PassList passes;
102         const Camera *camera;
103         std::vector<Slot> renderables;
104         std::vector<PostProcessor *> postproc;
105         unsigned width;
106         unsigned height;
107         bool hdr;
108         unsigned samples;
109         RenderTarget *target[2];
110         MultisampleTarget *target_ms;
111         mutable bool in_frame;
112
113 public:
114         Pipeline(unsigned, unsigned, bool = false);
115         ~Pipeline();
116
117         void set_hdr(bool);
118         void set_multisample(unsigned);
119         void set_camera(const Camera *);
120
121         // Deprecated
122         Pass &add_pass(const Tag &tag);
123         void add_renderable(const Renderable &);
124         void add_renderable_for_pass(const Renderable &, const Tag &);
125         void remove_renderable(const Renderable &);
126
127         /** Adds a pass to the pipeline.  It's permissible to add the same
128         Renderable multiple times. */
129         Pass &add_pass(const Tag &, const Renderable &);
130
131         /** Adds a postprocessor to the pipeline. */
132         void add_postprocessor(PostProcessor &);
133
134         virtual void setup_frame() const;
135         virtual void finish_frame() const;
136
137         virtual void render(const Tag &tag = Tag()) const;
138         virtual void render(Renderer &, const Tag &tag = Tag()) const;
139
140 private:
141         void create_targets(unsigned);
142 };
143
144 } // namespace GL
145 } // namespace Msp
146
147 #endif