]> git.tdb.fi Git - libs/gl.git/blob - source/render/rendertarget.h
030e45775f19898ef1e29914000e7e2ac8d1a660
[libs/gl.git] / source / render / 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, RenderOutput);
67         RenderTarget(unsigned, unsigned, const RenderTargetFormat & = (RENDER_COLOR, RENDER_DEPTH));
68         RenderTarget(unsigned, unsigned, unsigned, const RenderTargetFormat & = (RENDER_COLOR, RENDER_DEPTH));
69 private:
70         RenderTarget(const RenderTarget &);
71         RenderTarget &operator=(const RenderTarget &);
72         void init(unsigned, unsigned, unsigned, const RenderTargetFormat &);
73 public:
74         ~RenderTarget();
75
76         unsigned get_width() const { return width; }
77         unsigned get_height() const { return height; }
78         const RenderTargetFormat &get_format() const { return format; }
79         Framebuffer &get_framebuffer() { return fbo; }
80         const Texture2D &get_target_texture(unsigned) const;
81         const Texture2D &get_target_texture(RenderOutput) const;
82
83         void set_debug_name(const std::string &);
84 };
85
86 } // namespace GL
87 } // namespace Msp
88
89 #endif