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