]> git.tdb.fi Git - libs/gl.git/blob - source/pipeline.h
Add an alpha channel flag to Pipeline
[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 class View;
22
23 /**
24 Top-level content class.  Typically a Pipeline is used as the content
25 Renderable for a View or effects such as ShadowMap or EnvironmentMap.
26
27 A Pipeline contains a sequence of passes.  Each pass has a Renderable along
28 with Lighting, Clipping, DepthTest and Blend states.  Scenes can be used to
29 organize Renderables within a pass.
30
31 PostProcessors can be applied after all of the passes in the Pipeline have been
32 rendered.  Framebuffer objects are automatically used to pass render results to
33 the PostProcessors.  High dynamic range and multisample rendering can be
34 requested for increased quality.
35 */
36 class Pipeline: public Renderable
37 {
38 public:
39         class Pass
40         {
41         private:
42                 Tag tag;
43                 const Lighting *lighting;
44                 const DepthTest *depth_test;
45                 const Blend *blend;
46                 const Clipping *clipping;
47                 Renderable *renderable;
48
49         public:
50                 Pass(const Tag &, Renderable *);
51
52                 const Tag &get_tag() const { return tag; }
53
54                 void set_lighting(const Lighting *);
55                 void set_depth_test(const DepthTest *);
56                 void set_blend(const Blend *);
57                 void set_clipping(const Clipping *);
58                 const Lighting *get_lighting() const { return lighting; }
59                 const DepthTest *get_depth_test() const { return depth_test; }
60                 const Blend *get_blend() const { return blend; }
61                 const Clipping *get_clipping() const { return clipping; }
62                 Renderable *get_renderable() const { return renderable; }
63         };
64
65 private:
66         struct Slot
67         {
68                 Renderable *renderable;
69                 std::set<Tag> passes;
70
71                 Slot(Renderable *);
72         };
73
74         typedef std::list<Pass> PassList;
75
76         PassList passes;
77         const Camera *camera;
78         std::vector<Slot> renderables;
79         std::vector<RefPtr<PostProcessor> > postproc;
80         unsigned width;
81         unsigned height;
82         bool hdr;
83         bool alpha;
84         unsigned samples;
85         RenderTarget *target[2];
86         RenderTarget *target_ms;
87
88 public:
89         Pipeline(unsigned, unsigned, bool = false);
90         Pipeline(const View &);
91         Pipeline(const Framebuffer &);
92 private:
93         void init(unsigned, unsigned);
94 public:
95         ~Pipeline();
96
97         /* Sets high dynamic range mode.  Requires floating-point texture support.
98         A ColorCurve postprocessor is recommended for full benefit. */
99         void set_hdr(bool);
100
101         /* Enable or disable alpha channel.  When enabled, all render targets are
102         created with an RGBA pixel format instead of RGB. */
103         void set_alpha(bool);
104
105         void set_multisample(unsigned);
106
107         unsigned get_width() const { return width; }
108         unsigned get_height() const { return height; }
109         bool get_hdr() const { return hdr; }
110         unsigned get_multisample() const { return samples; }
111
112         // Deprecated
113         void set_camera(const Camera *);
114         Pass &add_pass(const Tag &tag);
115         void add_renderable(Renderable &);
116         void add_renderable_for_pass(Renderable &, const Tag &);
117         void remove_renderable(Renderable &);
118
119         /** Adds a pass to the pipeline.  It's permissible to add the same
120         Renderable multiple times. */
121         Pass &add_pass(const Tag &, Renderable &);
122
123         /** Adds a postprocessor to the pipeline. */
124         void add_postprocessor(PostProcessor &);
125
126         /** Adds a postprocessor to the pipeline, transferring ownership.  The
127         postprocessor will be deleted together with with pipeline.  It is also
128         deleted if this call throws an exception. */
129         void add_postprocessor_owned(PostProcessor *);
130
131 private:
132         void add_postprocessor(PostProcessor *, bool);
133
134 public:
135         virtual void setup_frame(Renderer &);
136         virtual void finish_frame();
137
138         void render();
139         virtual void render(Renderer &, const Tag &tag = Tag()) const;
140
141 private:
142         void create_targets(unsigned);
143 };
144
145 } // namespace GL
146 } // namespace Msp
147
148 #endif