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