gamma correction in post when there's no sRGB framebuffer and simple shader compositi...
[vrfileman] / src / rtarg.h
1 #ifndef RTARG_H_
2 #define RTARG_H_
3
4 #include "gmath/gmath.h"
5 #include "opengl.h"
6
7 class Texture;
8
9 class RenderTarget {
10 private:
11         int width, height;
12
13         unsigned int fbo;
14         Texture *color_tex;
15         unsigned int tex_targ;
16         int tex_face;
17         unsigned int rbuf_zstencil;
18
19         Mat4 tex_matrix;
20
21         void bind() const;
22
23 public:
24         static unsigned int default_fbo;        // 0 on most platforms, GLKit fbo on iOS.
25
26         RenderTarget();
27         ~RenderTarget();
28
29         bool create(unsigned int fmt = GL_RGBA);
30         bool create(int width, int height, unsigned int fmt = GL_RGBA);
31         bool create(Texture *tex, int face = 0);
32
33         void cleanup();
34
35         bool resize(int width, int height);
36
37         int get_width() const;
38         int get_height() const;
39
40         Texture *get_texture() const;
41
42         /** calculates a texture matrix to map the full texture space
43          * onto the part of the texture occupied by the render target
44          */
45         const Mat4 &get_texture_matrix() const;
46
47         bool check() const;
48
49         friend void set_render_target(const RenderTarget *rtarg);
50 };
51
52 void set_render_target(const RenderTarget *rtarg);
53
54 int next_pow2(int x);
55
56 #endif  // RTARG_H_