]> git.tdb.fi Git - libs/gl.git/blob - source/postprocessor.h
Better lifecycle management of the fullscreen quad in PostProcessor
[libs/gl.git] / source / postprocessor.h
1 #ifndef MSP_GL_POSTPROCESSOR_H_
2 #define MSP_GL_POSTPROCESSOR_H_
3
4 #include <msp/datafile/objectloader.h>
5
6 namespace Msp {
7 namespace GL {
8
9 class Mesh;
10 class Renderer;
11 class Shader;
12 class Texture2D;
13
14 /**
15 Base class for post-processing effects.  Post-processors receive the contents
16 of the entire framebuffer as a texture and render it back, altering it in the
17 process.
18 */
19 class PostProcessor
20 {
21 public:
22         struct Template
23         {
24                 class Loader: public Msp::DataFile::ObjectLoader<Template>
25                 {
26                 public:
27                         Loader(Template &);
28                 };
29
30                 unsigned size_divisor;
31
32                 Template();
33                 virtual ~Template() { }
34
35                 virtual PostProcessor *create(unsigned, unsigned) const = 0;
36         };
37
38 private:
39         static WeakPtr<Mesh> fullscreen_quad;
40
41 protected:
42         PostProcessor() { }
43 public:
44         virtual ~PostProcessor() { }
45
46         /// Renders the effect.
47         virtual void render(const Texture2D &, const Texture2D &) { }
48
49         virtual void render(Renderer &, const Texture2D &, const Texture2D &);
50
51 protected:
52         /** Returns a mesh consisting of a single quad, covering the entire screen.
53         The vertices are in normalized device coordinates. */
54         static RefPtr<Mesh> get_fullscreen_quad();
55 };
56
57 } // namespace GL
58 } // namespace Msp
59
60 #endif