]> git.tdb.fi Git - libs/gl.git/blob - source/render/sequence.h
Use default member initializers for simple types
[libs/gl.git] / source / render / sequence.h
1 #ifndef MSP_GL_SEQUENCE_H_
2 #define MSP_GL_SEQUENCE_H_
3
4 #include <vector>
5 #include "blend.h"
6 #include "depthtest.h"
7 #include "frameformat.h"
8 #include "renderable.h"
9 #include "stenciltest.h"
10
11 namespace Msp {
12 namespace GL {
13
14 class Clipping;
15 class Lighting;
16 class PostProcessor;
17 class RenderTarget;
18
19 /**
20 Top-level content class.  Typically a Sequence is used as the content
21 Renderable for a View or effects such as ShadowMap or EnvironmentMap.
22
23 A Sequence consists of a number of steps.  Each step is defined with a
24 Renderable and a tag to render it with and may also have Lighting, Clipping,
25 DepthTest and Blend states.  Scenes can be used to further organize Renderables
26 within a step.
27
28 PostProcessors can be applied after all of the steps in the Sequence have been
29 processed.  Framebuffer objects are automatically used to pass render results
30 to the PostProcessors.  High dynamic range and multisample rendering can be
31 requested for increased quality.
32 */
33 class Sequence: public Renderable
34 {
35 public:
36         class Step
37         {
38         private:
39                 Tag tag;
40                 const Lighting *lighting;
41                 DepthTest depth_test;
42                 StencilTest stencil_test;
43                 Blend blend;
44                 const Clipping *clipping;
45                 Renderable *renderable;
46
47         public:
48                 Step(Tag, Renderable *);
49
50                 Tag get_tag() const { return tag; }
51
52                 void set_lighting(const Lighting *);
53                 void set_depth_test(const DepthTest &);
54                 void set_stencil_test(const StencilTest &);
55                 void set_blend(const Blend &);
56                 void set_clipping(const Clipping *);
57                 const Lighting *get_lighting() const { return lighting; }
58                 const DepthTest &get_depth_test() const { return depth_test; }
59                 const StencilTest &get_stencil_test() const { return stencil_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 PostProcStep
67         {
68                 PostProcessor *postproc;
69                 bool owned;
70
71                 PostProcStep(PostProcessor *pp, bool o): postproc(pp), owned(o) { }
72         };
73
74         std::vector<Step> steps;
75         std::vector<PostProcStep> postproc;
76         unsigned width = 0;
77         unsigned height = 0;
78         FrameFormat target_format;
79         RenderTarget *target[2] = { 0, 0 };
80         RenderTarget *target_ms = 0;
81         bool clear_enabled = false;
82         std::vector<Color> clear_colors;
83         float clear_depth = 1.0f;
84         int clear_stencil = 0;
85
86 public:
87         Sequence() = default;
88         Sequence(unsigned, unsigned, const FrameFormat &);
89         ~Sequence();
90
91         unsigned get_width() const { return width; }
92         unsigned get_height() const { return height; }
93         const FrameFormat &get_target_format() { return target_format; }
94
95         void set_clear_enabled(bool);
96         void set_clear_colors(const std::vector<Color> &);
97         void set_clear_depth(float);
98         void set_clear_stencil(int);
99
100         /** Adds a step to the sequence.  It's permissible to add the same
101         Renderable multiple times. */
102         Step &add_step(Tag, Renderable &);
103
104         /** Adds a postprocessor to the sequence. */
105         void add_postprocessor(PostProcessor &);
106
107         /** Adds a postprocessor to the sequence, transferring ownership.  The
108         postprocessor will be deleted together with with sequence.  It is also
109         deleted if this call throws an exception. */
110         void add_postprocessor_owned(PostProcessor *);
111
112 private:
113         void add_postprocessor(PostProcessor *, bool);
114
115 public:
116         virtual void setup_frame(Renderer &);
117         virtual void finish_frame();
118
119         virtual void render(Renderer &, Tag tag = Tag()) const;
120
121         void set_debug_name(const std::string &);
122 };
123
124 } // namespace GL
125 } // namespace Msp
126
127 #endif