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