]> git.tdb.fi Git - libs/gl.git/blob - source/render/sequence.h
Check the flat qualifier from the correct member
[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 content for a View
20 or sideband content for 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.  Lighting, DepthTest and StencilTest
24 states may also be applied to steps.  Scenes can be used to organize multiple
25 Renderables within a step.
26
27 The target framebuffer can optionally be cleared before the first step.
28
29 PostProcessors can be applied after all of the steps in the Sequence have been
30 processed.  Framebuffer objects are automatically used to pass render results
31 to the PostProcessors.  The Sequence must be created with a size and a frame
32 format.
33
34 A Sequence itself is normally rendered with an empty tag.  A special "noclear"
35 tag can be used to suppress clearing.
36 */
37 class Sequence: public Renderable, public NonCopyable
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                 Renderable *renderable;
48
49         public:
50                 Step(Tag, Renderable *);
51
52                 Tag get_tag() const { return tag; }
53
54                 void set_lighting(const Lighting *);
55                 void set_depth_test(const DepthTest &);
56                 void set_stencil_test(const StencilTest &);
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                 Renderable *get_renderable() const { return renderable; }
61         };
62
63 private:
64         struct OwnedObject
65         {
66                 void *pointer = 0;
67                 void (*delete_func)(void *) = 0;
68
69                 OwnedObject(void *p, void (*d)(void *)): pointer(p), delete_func(d) { }
70         };
71
72         std::vector<Step> steps;
73         std::vector<PostProcessor *> postproc;
74         unsigned width = 0;
75         unsigned height = 0;
76         FrameFormat target_format;
77         RenderTarget *target[2] = { 0, 0 };
78         RenderTarget *target_ms = 0;
79         bool clear_enabled = false;
80         std::vector<Color> clear_colors;
81         float clear_depth = 1.0f;
82         int clear_stencil = 0;
83         std::vector<OwnedObject> owned_data;
84
85         static Tag noclear_tag;
86
87 public:
88         Sequence() = default;
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         void set_clear_colors(const std::vector<Color> &);
98         void set_clear_depth(float);
99         void set_clear_stencil(int);
100
101         /** Adds a step to the sequence.  It's permissible to add the same
102         Renderable or tag multiple times. */
103         Step &add_step(Tag, Renderable &);
104
105         const std::vector<Step> &get_steps() const { return steps; }
106
107         /** Adds a postprocessor to the sequence.  A render target format must be
108         defined. */
109         void add_postprocessor(PostProcessor &);
110
111         const std::vector<PostProcessor *> &get_postprocessors() const { return postproc; }
112
113         /** Adds an owned object, which will be deleted together with the sequence. */
114         template<typename T>
115         void add_owned(T *p)
116         { owned_data.push_back({ p, [](void *ptr){ delete static_cast<T *>(ptr); } }); }
117
118         virtual void setup_frame(Renderer &);
119         virtual void finish_frame();
120
121         virtual void render(Renderer &, Tag tag = Tag()) const;
122
123         void set_debug_name(const std::string &);
124 };
125
126 } // namespace GL
127 } // namespace Msp
128
129 #endif