jubilant-funicular
FrameBuffer.h
1 #ifndef NTA_FRAMEBUFFER_H_INCLUDED
2 #define NTA_FRAMEBUFFER_H_INCLUDED
3 
4 #include <vector>
5 
6 #include <GL/glew.h>
7 
8 namespace nta {
10  class FrameBuffer {
11  private:
13  GLuint m_fbo;
15  std::vector<GLuint> m_texs;
17  std::vector<GLuint> m_rbos;
18  public:
19  FrameBuffer() : m_fbo(0) {}
20  ~FrameBuffer() { destroy(); }
21 
23  void init();
25  void use() const;
27  void set_texture(GLuint idx = 0) const;
29  void unuse() const;
30 
32  GLuint add_texture(GLuint width, GLuint height,
33  GLint min_filt = GL_LINEAR, GLint mag_filt = GL_LINEAR,
34  bool rgba = true);
36  GLuint get_tex(GLuint idx = 0) const;
38  GLuint get_width(GLuint idx = 0) const;
40  GLuint get_height(GLuint idx = 0) const;
41  GLuint num_texs() const { return m_texs.size(); }
42 
44  void destroy();
45  };
46 }
47 
48 #endif // NTA_FRAMEBUFFER_H_INCLUDED
nta::FrameBuffer::init
void init()
Initializes a new FrameBuffer (deleting the old one if it existed)
Definition: FrameBuffer.cpp:5
nta::FrameBuffer::m_rbos
std::vector< GLuint > m_rbos
The render buffer objects (currently unused)
Definition: FrameBuffer.h:17
nta::FrameBuffer::get_tex
GLuint get_tex(GLuint idx=0) const
Returns id of texture associated with GL_COLOR_ATTACHMENTidx.
Definition: FrameBuffer.cpp:48
nta::FrameBuffer::add_texture
GLuint add_texture(GLuint width, GLuint height, GLint min_filt=GL_LINEAR, GLint mag_filt=GL_LINEAR, bool rgba=true)
Returns index of added texture.
Definition: FrameBuffer.cpp:24
nta::FrameBuffer::set_texture
void set_texture(GLuint idx=0) const
Sets which texture to draw to.
Definition: FrameBuffer.cpp:14
nta::FrameBuffer::get_width
GLuint get_width(GLuint idx=0) const
Returns width of texture associated with GL_COLOR_ATTACHMENTidx.
Definition: FrameBuffer.cpp:51
nta::FrameBuffer::m_texs
std::vector< GLuint > m_texs
The textures to draw to.
Definition: FrameBuffer.h:15
nta
Definition: Animation2D.h:6
nta::FrameBuffer::get_height
GLuint get_height(GLuint idx=0) const
Returns height of texture associated with GL_COLOR_ATTACHMENTidx.
Definition: FrameBuffer.cpp:59
nta::FrameBuffer::unuse
void unuse() const
Binds the default FrameBuffer (i.e. the screen)
Definition: FrameBuffer.cpp:19
nta::FrameBuffer
A wrapper around an OpenGL Framebuffer object.
Definition: FrameBuffer.h:10
nta::FrameBuffer::m_fbo
GLuint m_fbo
The id of this frame buffer.
Definition: FrameBuffer.h:13
nta::FrameBuffer::use
void use() const
Binds this FrameBuffer.
Definition: FrameBuffer.cpp:11
nta::FrameBuffer::destroy
void destroy()
Destroys this FrameBuffer.
Definition: FrameBuffer.cpp:67