]> git.tdb.fi Git - libs/gl.git/blob - source/render/sequence.h
Remove RenderBuffer and always use textures as framebuffer attachments
[libs/gl.git] / source / render / sequence.h
1 #ifndef MSP_GL_SEQUENCE_H_
2 #define MSP_GL_SEQUENCE_H_
3
4 #include <map>
5 #include <set>
6 #include "blend.h"
7 #include "depthtest.h"
8 #include "framebuffer.h"
9 #include "renderable.h"
10 #include "rendertarget.h"
11 #include "stenciltest.h"
12 #include "texture2d.h"
13
14 namespace Msp {
15 namespace GL {
16
17 class Blend;
18 class Camera;
19 class Clipping;
20 class Lighting;
21 class PostProcessor;
22 class View;
23
24 /**
25 Top-level content class.  Typically a Sequence is used as the content
26 Renderable for a View or effects such as ShadowMap or EnvironmentMap.
27
28 A Sequence consists of a number of steps.  Each step is defined with a
29 Renderable and a tag to render it with and may also have Lighting, Clipping,
30 DepthTest and Blend states.  Scenes can be used to further organize Renderables
31 within a step.
32
33 PostProcessors can be applied after all of the steps in the Sequence have been
34 processed.  Framebuffer objects are automatically used to pass render results
35 to the PostProcessors.  High dynamic range and multisample rendering can be
36 requested for increased quality.
37 */
38 class Sequence: public Renderable
39 {
40 public:
41         class Step
42         {
43         private:
44                 Tag tag;
45                 const Lighting *lighting;
46                 DepthTest depth_test;
47                 StencilTest stencil_test;
48                 Blend blend;
49                 const Clipping *clipping;
50                 Renderable *renderable;
51
52         public:
53                 Step(Tag, Renderable *);
54
55                 Tag get_tag() const { return tag; }
56
57                 void set_lighting(const Lighting *);
58                 void set_depth_test(const DepthTest &);
59                 void set_stencil_test(const StencilTest &);
60                 void set_blend(const Blend &);
61                 void set_clipping(const Clipping *);
62                 const Lighting *get_lighting() const { return lighting; }
63                 const DepthTest &get_depth_test() const { return depth_test; }
64                 const StencilTest &get_stencil_test() const { return stencil_test; }
65                 const Blend &get_blend() const { return blend; }
66                 const Clipping *get_clipping() const { return clipping; }
67                 Renderable *get_renderable() const { return renderable; }
68         };
69
70         DEPRECATED typedef Step Pass;
71
72 private:
73         struct PostProcStep
74         {
75                 PostProcessor *postproc;
76                 bool owned;
77
78                 PostProcStep(PostProcessor *pp, bool o): postproc(pp), owned(o) { }
79         };
80
81         std::vector<Step> steps;
82         const Camera *camera;
83         std::vector<PostProcStep> postproc;
84         unsigned width;
85         unsigned height;
86         bool hdr;
87         bool alpha;
88         unsigned samples;
89         RenderTarget *target[2];
90         RenderTarget *target_ms;
91         std::string debug_name;
92
93 public:
94         Sequence(unsigned, unsigned, bool = false);
95         Sequence(const View &);
96         Sequence(const Framebuffer &);
97 private:
98         void init(unsigned, unsigned);
99 public:
100         ~Sequence();
101
102         /* Sets high dynamic range mode.  Requires floating-point texture support.
103         A ColorCurve postprocessor is recommended for full benefit. */
104         void set_hdr(bool);
105
106         /* Enable or disable alpha channel.  When enabled, all render targets are
107         created with an RGBA pixel format instead of RGB. */
108         void set_alpha(bool);
109
110         void set_multisample(unsigned);
111
112         unsigned get_width() const { return width; }
113         unsigned get_height() const { return height; }
114         bool get_hdr() const { return hdr; }
115         unsigned get_multisample() const { return samples; }
116
117         /** Adds a step to the sequence.  It's permissible to add the same
118         Renderable multiple times. */
119         Step &add_step(Tag, Renderable &);
120
121         DEPRECATED Step &add_pass(Tag t, Renderable &r) { return add_step(t, r); }
122
123         /** Adds a postprocessor to the sequence. */
124         void add_postprocessor(PostProcessor &);
125
126         /** Adds a postprocessor to the sequence, transferring ownership.  The
127         postprocessor will be deleted together with with sequence.  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         virtual void render(Renderer &, Tag tag = Tag()) const;
139
140 private:
141         void create_targets(unsigned);
142
143 public:
144         void set_debug_name(const std::string &);
145 private:
146         void set_target_debug_names();
147 };
148
149 } // namespace GL
150 } // namespace Msp
151
152 #endif