]> git.tdb.fi Git - libs/gl.git/blob - source/pipeline.h
Associate camera and setup/finish_frame calls with View
[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 Top-level content class.  Typically a Pipeline is used as the content
24 Renderable for a View or effects such as ShadowMap or EnvironmentMap.
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.
29
30 PostProcessors can be applied after all of the passes in the Pipeline have been
31 rendered.  Framebuffer objects are automatically used to pass render results to
32 the PostProcessors.  High dynamic range and multisample rendering can be
33 requested for increased quality.
34 */
35 class Pipeline: public Renderable
36 {
37 public:
38         class Pass
39         {
40         private:
41                 Tag tag;
42                 const Lighting *lighting;
43                 const DepthTest *depth_test;
44                 const Blend *blend;
45                 const Clipping *clipping;
46                 const Renderable *renderable;
47
48         public:
49                 Pass(const Tag &, const Renderable *);
50
51                 const Tag &get_tag() const { return tag; }
52
53                 void set_lighting(const Lighting *);
54                 void set_depth_test(const DepthTest *);
55                 void set_blend(const Blend *);
56                 void set_clipping(const Clipping *);
57                 const Lighting *get_lighting() const { return lighting; }
58                 const DepthTest *get_depth_test() const { return depth_test; }
59                 const Blend *get_blend() const { return blend; }
60                 const Clipping *get_clipping() const { return clipping; }
61                 const Renderable *get_renderable() const { return renderable; }
62         };
63
64 private:
65         struct Slot
66         {
67                 const Renderable *renderable;
68                 std::set<Tag> passes;
69
70                 Slot(const Renderable *);
71         };
72
73         typedef std::list<Pass> PassList;
74
75         PassList passes;
76         const Camera *camera;
77         std::vector<Slot> renderables;
78         std::vector<PostProcessor *> postproc;
79         unsigned width;
80         unsigned height;
81         bool hdr;
82         unsigned samples;
83         RenderTarget *target[2];
84         RenderTarget *target_ms;
85
86 public:
87         Pipeline(unsigned, unsigned, bool = false);
88         ~Pipeline();
89
90         void set_hdr(bool);
91         void set_multisample(unsigned);
92
93         // Deprecated
94         void set_camera(const Camera *);
95         Pass &add_pass(const Tag &tag);
96         void add_renderable(const Renderable &);
97         void add_renderable_for_pass(const Renderable &, const Tag &);
98         void remove_renderable(const Renderable &);
99
100         /** Adds a pass to the pipeline.  It's permissible to add the same
101         Renderable multiple times. */
102         Pass &add_pass(const Tag &, const Renderable &);
103
104         /** Adds a postprocessor to the pipeline. */
105         void add_postprocessor(PostProcessor &);
106
107         virtual void setup_frame() const;
108         virtual void finish_frame() const;
109
110         virtual void render(const Tag &tag = Tag()) const;
111         virtual void render(Renderer &, const Tag &tag = Tag()) const;
112
113 private:
114         void create_targets(unsigned);
115 };
116
117 } // namespace GL
118 } // namespace Msp
119
120 #endif