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