f77682d5a126ba892ee9819f6f3b47193c5a3528
[laserbrain_demo] / src / rtarg.h
1 #ifndef RTARG_H_
2 #define RTARG_H_
3
4 #include <gmath/gmath.h>
5 #include "opengl.h"
6 #include "texture.h"
7
8 // flags for RenderTarget::create
9 enum {
10         RT_COLOR = 1,
11         RT_DEPTH = 2,
12         RT_STENCIL = 4
13 };
14
15 class RenderTarget {
16 private:
17         int width, height;
18         int tex_width, tex_height;
19
20         unsigned int fbo;
21         Texture *tex[4];
22         int rtcount;
23         // either the depth texture or a dummy depth render target is used
24         Texture *depth;
25         unsigned int rbdepth;
26         Mat4 texmat; // texture matrix to map tex coords from [0,1] to the useful area
27
28         bool own_texture[4];
29         bool auto_vport;
30
31 public:
32         RenderTarget();
33         ~RenderTarget();
34
35         bool create(int xsz, int ysz, unsigned int fmt = GL_SRGB_ALPHA,
36                         unsigned int flags = RT_COLOR | RT_DEPTH);
37         bool create_mrt(int xsz, int ysz, int num, unsigned int fmt = GL_RGB16F,
38                         unsigned int flags = RT_COLOR | RT_DEPTH);
39         void destroy();
40
41         int get_width() const;
42         int get_height() const;
43
44         void set_texture(Texture *tex, int idx = 0);
45         void set_depth_texture(Texture *tex);
46
47         Texture *texture(int idx = 0) const;
48         Texture *depth_texture() const;
49
50         void set_auto_viewport(bool enable);
51         bool auto_viewport() const;
52
53         void bind() const;
54         const Mat4 &texture_matrix() const;
55 };
56
57 void set_render_target(RenderTarget *rt);
58 RenderTarget *current_render_target();
59
60 bool push_render_target(RenderTarget *rt);
61 bool pop_render_target();
62
63 #endif  // RTARG_H_