]> git.tdb.fi Git - libs/gl.git/blob - source/pipeline.h
Simplify Pipeline pass management
[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 "renderable.h"
7
8 namespace Msp {
9 namespace GL {
10
11 class Blend;
12 class Camera;
13 class DepthTest;
14 class Framebuffer;
15 class Lighting;
16 class PostProcessor;
17 class Renderbuffer;
18 class Texture2D;
19
20 class Pipeline: public Renderable
21 {
22 public:
23         class Pass
24         {
25         private:
26                 Tag tag;
27                 const Lighting *lighting;
28                 const DepthTest *depth_test;
29                 const Blend *blend;
30
31         public:
32                 Pass(const Tag &);
33
34                 const Tag &get_tag() const { return tag; }
35
36                 void set_lighting(const Lighting *);
37                 void set_depth_test(const DepthTest *);
38                 void set_blend(const Blend *);
39                 const Lighting *get_lighting() const { return lighting; }
40                 const DepthTest *get_depth_test() const { return depth_test; }
41                 const Blend *get_blend() const { return blend; }
42         };
43
44 private:
45         struct Slot
46         {
47                 const Renderable *renderable;
48                 std::set<Tag> passes;
49
50                 Slot(const Renderable *);
51         };
52
53         typedef std::list<Pass> PassList;
54
55         PassList passes;
56         const Camera *camera;
57         std::vector<Slot> renderables;
58         std::vector<PostProcessor *> postproc;
59         unsigned width;
60         unsigned height;
61         bool hdr;
62         unsigned samples;
63         Framebuffer *fbo;
64         Texture2D *color_buf;
65         Texture2D *depth_buf;
66         Framebuffer *fbo_ms;
67         Renderbuffer *color_buf_ms;
68         Renderbuffer *depth_buf_ms;
69
70 public:
71         Pipeline(unsigned, unsigned, bool = false);
72         ~Pipeline();
73
74         void set_hdr(bool);
75         void set_multisample(unsigned);
76         void set_camera(const Camera *);
77
78         Pass &add_pass(const Tag &tag);
79
80         void add_renderable(const Renderable &);
81         void add_renderable_for_pass(const Renderable &, const Tag &);
82         void remove_renderable(const Renderable &);
83         void add_postprocessor(PostProcessor &);
84
85         virtual void render(const Tag &tag = Tag()) const;
86         virtual void render(Renderer &, const Tag &tag = Tag()) const;
87
88 private:
89         void create_fbos();
90 };
91
92 } // namespace GL
93 } // namespace Msp
94
95 #endif