]> git.tdb.fi Git - libs/gl.git/blob - source/pipeline.h
Use two FBOs in Pipeline when necessary
[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 DepthTest;
17 class Lighting;
18 class PostProcessor;
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         struct RenderTarget
54         {
55                 Framebuffer fbo;
56                 Texture2D color;
57                 Texture2D depth;
58
59                 RenderTarget(unsigned, unsigned, PixelFormat);
60         };
61
62         struct MultisampleTarget
63         {
64                 Framebuffer fbo;
65                 Renderbuffer color;
66                 Renderbuffer depth;
67
68                 MultisampleTarget(unsigned, unsigned, unsigned, PixelFormat);
69         };
70
71         typedef std::list<Pass> PassList;
72
73         PassList passes;
74         const Camera *camera;
75         std::vector<Slot> renderables;
76         std::vector<PostProcessor *> postproc;
77         unsigned width;
78         unsigned height;
79         bool hdr;
80         unsigned samples;
81         RenderTarget *target[2];
82         MultisampleTarget *target_ms;
83
84 public:
85         Pipeline(unsigned, unsigned, bool = false);
86         ~Pipeline();
87
88         void set_hdr(bool);
89         void set_multisample(unsigned);
90         void set_camera(const Camera *);
91
92         Pass &add_pass(const Tag &tag);
93
94         void add_renderable(const Renderable &);
95         void add_renderable_for_pass(const Renderable &, const Tag &);
96         void remove_renderable(const Renderable &);
97         void add_postprocessor(PostProcessor &);
98
99         virtual void render(const Tag &tag = Tag()) const;
100         virtual void render(Renderer &, const Tag &tag = Tag()) const;
101
102 private:
103         void create_targets(bool);
104 };
105
106 } // namespace GL
107 } // namespace Msp
108
109 #endif