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