]> git.tdb.fi Git - libs/gl.git/blob - source/pipeline.h
Handle clipping in Pipeline and Renderer
[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, combining Renderables
24 with a camera, lights and some other influential objects.
25
26 A Pipeline is also a Renderable itself.  Externally, it only exposes the
27 default pass.  Internally, it can hold any number of passes, which are invoked
28 in sequence when rendering the default pass is requested.  Each pass can have a
29 Lighting, a DepthTest and a Blend to control how it is rendered.
30
31 A Pipeline's render method should normally be called without a Renderer; it
32 will create one itself, using the camera specified for the Pipeline.  If a
33 Renderer is passed, its camera will be used instead.
34
35 Renderables are rendered in the order they were added to the Pipeline.  While
36 it's possible to remove renderables as well, using a Scene is recommended if
37 frequent add/remove operations are needed.
38
39 Pipelines may have post-processors to apply full-screen effects. Framebuffer
40 objects are automatically used to pass render results to the post-processors.
41 High dynamic range and multisample rendering can also be used.
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
55         public:
56                 Pass(const Tag &);
57
58                 const Tag &get_tag() const { return tag; }
59
60                 void set_lighting(const Lighting *);
61                 void set_depth_test(const DepthTest *);
62                 void set_blend(const Blend *);
63                 void set_clipping(const Clipping *);
64                 const Lighting *get_lighting() const { return lighting; }
65                 const DepthTest *get_depth_test() const { return depth_test; }
66                 const Blend *get_blend() const { return blend; }
67                 const Clipping *get_clipping() const { return clipping; }
68         };
69
70 private:
71         struct Slot
72         {
73                 const Renderable *renderable;
74                 std::set<Tag> passes;
75
76                 Slot(const Renderable *);
77         };
78
79         struct RenderTarget
80         {
81                 Framebuffer fbo;
82                 Texture2D color;
83                 Texture2D depth;
84
85                 RenderTarget(unsigned, unsigned, PixelFormat);
86         };
87
88         struct MultisampleTarget
89         {
90                 Framebuffer fbo;
91                 Renderbuffer color;
92                 Renderbuffer depth;
93
94                 MultisampleTarget(unsigned, unsigned, unsigned, PixelFormat);
95         };
96
97         typedef std::list<Pass> PassList;
98
99         PassList passes;
100         const Camera *camera;
101         std::vector<Slot> renderables;
102         std::vector<PostProcessor *> postproc;
103         unsigned width;
104         unsigned height;
105         bool hdr;
106         unsigned samples;
107         RenderTarget *target[2];
108         MultisampleTarget *target_ms;
109         mutable bool in_frame;
110
111 public:
112         Pipeline(unsigned, unsigned, bool = false);
113         ~Pipeline();
114
115         void set_hdr(bool);
116         void set_multisample(unsigned);
117         void set_camera(const Camera *);
118
119         Pass &add_pass(const Tag &tag);
120
121         void add_renderable(const Renderable &);
122         void add_renderable_for_pass(const Renderable &, const Tag &);
123         void remove_renderable(const Renderable &);
124         void add_postprocessor(PostProcessor &);
125
126         virtual void setup_frame() const;
127         virtual void finish_frame() const;
128
129         virtual void render(const Tag &tag = Tag()) const;
130         virtual void render(Renderer &, const Tag &tag = Tag()) const;
131
132 private:
133         void create_targets(unsigned);
134 };
135
136 } // namespace GL
137 } // namespace Msp
138
139 #endif