]> git.tdb.fi Git - libs/gl.git/blob - source/rendertarget.h
Refactor AnimationPlayer ticking
[libs/gl.git] / source / rendertarget.h
1 #ifndef RENDERTARGET_H_
2 #define RENDERTARGET_H_
3
4 #include "framebuffer.h"
5 #include "texture2d.h"
6
7 namespace Msp {
8 namespace GL {
9
10 enum RenderOutput
11 {
12         RENDER_COLOR = 0|3,
13         RENDER_DEPTH = 192|12
14 };
15
16 class RenderTargetFormat
17 {
18 private:
19         enum { MAX_OUTPUTS = 7 };
20
21         unsigned char count;
22         unsigned char outputs[MAX_OUTPUTS];
23
24 public:
25         RenderTargetFormat();
26         RenderTargetFormat(RenderOutput);
27
28         RenderTargetFormat operator,(RenderOutput) const;
29         RenderTargetFormat operator,(PixelFormat) const;
30
31         bool empty() const { return !count; }
32         const unsigned char *begin() const { return outputs; }
33         const unsigned char *end() const { return outputs+count; }
34         int index(RenderOutput) const;
35 };
36
37 inline RenderTargetFormat operator,(RenderOutput o1, RenderOutput o2)
38 { return (RenderTargetFormat(o1), o2); }
39
40 inline RenderTargetFormat operator,(RenderOutput o, PixelFormat f)
41 { return (RenderTargetFormat(o), f); }
42
43 inline unsigned get_output_type(unsigned char o)
44 { return o>>4; }
45
46 PixelFormat get_output_pixelformat(unsigned char);
47
48
49 class RenderTarget
50 {
51 private:
52         union TargetBuffer
53         {
54                 Texture2D *texture;
55                 Renderbuffer *buffer;
56         };
57
58         unsigned width;
59         unsigned height;
60         unsigned samples;
61         RenderTargetFormat format;
62         std::vector<TargetBuffer> buffers;
63         Framebuffer fbo;
64
65 public:
66         RenderTarget(unsigned, unsigned, const RenderTargetFormat & = (RENDER_COLOR, RENDER_DEPTH));
67         RenderTarget(unsigned, unsigned, unsigned, const RenderTargetFormat & = (RENDER_COLOR, RENDER_DEPTH));
68 private:
69         RenderTarget(const RenderTarget &);
70         RenderTarget &operator=(const RenderTarget &);
71         void init(unsigned, unsigned, unsigned, const RenderTargetFormat &);
72 public:
73         ~RenderTarget();
74
75         const RenderTargetFormat &get_format() const { return format; }
76         Framebuffer &get_framebuffer() { return fbo; }
77         void set_texture_filter(TextureFilter);
78         const Texture2D &get_target_texture(unsigned) const;
79         const Texture2D &get_target_texture(RenderOutput) const;
80         void blit_from(const RenderTarget &);
81 };
82
83 } // namespace GL
84 } // namespace Msp
85
86 #endif