]> git.tdb.fi Git - libs/gl.git/blob - source/render/sequence.h
061b04de3406a60b78c883f11a7b9ad2e2740666
[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
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                 DepthTest depth_test;
46                 StencilTest stencil_test;
47                 Blend blend;
48                 const Clipping *clipping;
49                 Renderable *renderable;
50
51         public:
52                 Step(Tag, Renderable *);
53
54                 Tag get_tag() const { return tag; }
55
56                 void set_lighting(const Lighting *);
57                 void set_depth_test(const DepthTest &);
58                 void set_stencil_test(const StencilTest &);
59                 void set_blend(const Blend &);
60                 void set_clipping(const Clipping *);
61                 const Lighting *get_lighting() const { return lighting; }
62                 const DepthTest &get_depth_test() const { return depth_test; }
63                 const StencilTest &get_stencil_test() const { return stencil_test; }
64                 const Blend &get_blend() const { return blend; }
65                 const Clipping *get_clipping() const { return clipping; }
66                 Renderable *get_renderable() const { return renderable; }
67         };
68
69 private:
70         struct PostProcStep
71         {
72                 PostProcessor *postproc;
73                 bool owned;
74
75                 PostProcStep(PostProcessor *pp, bool o): postproc(pp), owned(o) { }
76         };
77
78         std::vector<Step> steps;
79         std::vector<PostProcStep> postproc;
80         unsigned width;
81         unsigned height;
82         FrameFormat target_format;
83         RenderTarget *target[2];
84         RenderTarget *target_ms;
85         bool clear_enabled;
86
87 public:
88         Sequence();
89         Sequence(unsigned, unsigned, const FrameFormat &);
90         ~Sequence();
91
92         unsigned get_width() const { return width; }
93         unsigned get_height() const { return height; }
94         const FrameFormat &get_target_format() { return target_format; }
95
96         void set_clear_enabled(bool);
97
98         /** Adds a step to the sequence.  It's permissible to add the same
99         Renderable multiple times. */
100         Step &add_step(Tag, Renderable &);
101
102         /** Adds a postprocessor to the sequence. */
103         void add_postprocessor(PostProcessor &);
104
105         /** Adds a postprocessor to the sequence, transferring ownership.  The
106         postprocessor will be deleted together with with sequence.  It is also
107         deleted if this call throws an exception. */
108         void add_postprocessor_owned(PostProcessor *);
109
110 private:
111         void add_postprocessor(PostProcessor *, bool);
112
113 public:
114         virtual void setup_frame(Renderer &);
115         virtual void finish_frame();
116
117         virtual void render(Renderer &, Tag tag = Tag()) const;
118
119         void set_debug_name(const std::string &);
120 };
121
122 } // namespace GL
123 } // namespace Msp
124
125 #endif