1 #ifndef MSP_GL_SEQUENCE_H_
2 #define MSP_GL_SEQUENCE_H_
7 #include "frameformat.h"
8 #include "renderable.h"
9 #include "stenciltest.h"
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.
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.
27 The target framebuffer can optionally be cleared before the first step.
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
34 A Sequence itself is normally rendered with an empty tag. A special "noclear"
35 tag can be used to suppress clearing.
37 class Sequence: public Renderable, public NonCopyable
44 const Lighting *lighting;
46 StencilTest stencil_test;
47 Renderable *renderable;
50 Step(Tag, Renderable *);
52 Tag get_tag() const { return tag; }
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; }
67 void (*delete_func)(void *) = 0;
69 OwnedObject(void *p, void (*d)(void *)): pointer(p), delete_func(d) { }
72 std::vector<Step> steps;
73 std::vector<PostProcessor *> postproc;
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;
85 static const Tag noclear_tag;
89 Sequence(unsigned, unsigned, const FrameFormat &);
92 unsigned get_width() const { return width; }
93 unsigned get_height() const { return height; }
94 const FrameFormat &get_target_format() { return target_format; }
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);
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 &);
105 const std::vector<Step> &get_steps() const { return steps; }
107 /** Adds a postprocessor to the sequence. A render target format must be
109 void add_postprocessor(PostProcessor &);
111 const std::vector<PostProcessor *> &get_postprocessors() const { return postproc; }
113 /** Adds an owned object, which will be deleted together with the sequence. */
116 { owned_data.push_back({ p, [](void *ptr){ delete static_cast<T *>(ptr); } }); }
118 virtual void setup_frame(Renderer &);
119 virtual void finish_frame();
121 virtual void render(Renderer &, Tag tag = Tag()) const;
123 void set_debug_name(const std::string &);