X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=vrfileman;a=blobdiff_plain;f=src%2Frtarg.h;fp=src%2Frtarg.h;h=ed15ac36baff1e32ba96fba5245864a4ae036860;hp=0000000000000000000000000000000000000000;hb=7c59a70219aa7bcf80291f41903a9e6fc9b6e073;hpb=5e07bfd4d034dc3d974c8db008c6446e62838d39 diff --git a/src/rtarg.h b/src/rtarg.h new file mode 100644 index 0000000..ed15ac3 --- /dev/null +++ b/src/rtarg.h @@ -0,0 +1,56 @@ +#ifndef RTARG_H_ +#define RTARG_H_ + +#include "gmath/gmath.h" +#include "opengl.h" + +class Texture; + +class RenderTarget { +private: + int width, height; + + unsigned int fbo; + Texture *color_tex; + unsigned int tex_targ; + int tex_face; + unsigned int rbuf_zstencil; + + Mat4 tex_matrix; + + void bind() const; + +public: + static unsigned int default_fbo; // 0 on most platforms, GLKit fbo on iOS. + + RenderTarget(); + ~RenderTarget(); + + bool create(unsigned int fmt = GL_RGBA); + bool create(int width, int height, unsigned int fmt = GL_RGBA); + bool create(Texture *tex, int face = 0); + + void cleanup(); + + bool resize(int width, int height); + + int get_width() const; + int get_height() const; + + Texture *get_texture() const; + + /** calculates a texture matrix to map the full texture space + * onto the part of the texture occupied by the render target + */ + const Mat4 &get_texture_matrix() const; + + bool check() const; + + friend void set_render_target(const RenderTarget *rtarg); +}; + +void set_render_target(const RenderTarget *rtarg); + +int next_pow2(int x); + +#endif // RTARG_H_