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