Framebuffer.h
Go to the documentation of this file.
1 #ifndef B_FRAMEBUFFER_H
2 #define B_FRAMEBUFFER_H
3 
4 #include <memory>
5 #include "Renderer_GL.h"
6 #include "CubeMap.h"
7 #include "DepthMap.h"
8 
13 {
14 public:
15 
16  /* Functions */
17 
20  Framebuffer();
21 
26  Framebuffer(GLint width, GLint height);
27 
31 
35  virtual void bind(bool preserveCurrentFramebuffer);
36 
45  virtual void bindTexture(TexturePtr texture, bool preserveCurrentFramebuffer);
46 
52  virtual void bindCubeMap(CubeMapPtr cubeMap, GLuint cubeFace, bool preserveCurrentFramebuffer);
53 
58  virtual void bindDepthMap(DepthMapPtr depthMap, bool preserveCurrentFramebuffer);
59 
62  virtual void unbind();
63 
67  virtual void unbind(GLint fbo);
68 
74  virtual void resize(GLint width, GLint height, bool autoResize);
75 
78  GLuint getFramebufferID() { return _fbo; }
79 
82  GLuint getDebthbufferID() { return _rbo_depth; }
83 
86  GLint getWidth() { return _width; }
87 
90  GLint getHeight() { return _height; }
91 
94  static GLint getCurrentFramebuffer();
95 
98  virtual void deleteFramebuffer();
99 
100 private:
101 
102  /* Functions */
103 
104  virtual void create();
105  virtual void bindBuffer(bool preserveCurrentFramebuffer);
106 
107  /* Variables */
108  GLint _width, _height, _oldFbo = 0;
109  GLuint _fbo = 0, _rbo_depth = 0;
110  bool _preserveCurrentFramebuffer, _autoResize;
111 
112 };
113 
114 typedef std::shared_ptr<Framebuffer> FramebufferPtr;
115 
116 #endif /* defined(B_FRAMEBUFFER_H) */
virtual void unbind()
Unbind the framebuffer object.
Definition: Framebuffer.cpp:100
std::shared_ptr< Texture > TexturePtr
Definition: Texture.h:67
virtual void bindTexture(TexturePtr texture, bool preserveCurrentFramebuffer)
Bind the framebuffer object and draw to the specified texture.
Definition: Framebuffer.cpp:37
A custom framebuffer object allows to draw to non-default framebuffer locations and offers the possib...
Definition: Framebuffer.h:12
GLint getWidth()
Get the width of the framebuffer.
Definition: Framebuffer.h:86
virtual ~Framebuffer()
Virtual destructor.
Definition: Framebuffer.h:30
virtual void deleteFramebuffer()
Delete the framebuffer.
Definition: Framebuffer.cpp:137
std::shared_ptr< DepthMap > DepthMapPtr
Definition: DepthMap.h:28
static GLint getCurrentFramebuffer()
Get the framebuffer currently active.
Definition: Framebuffer.cpp:116
std::shared_ptr< Framebuffer > FramebufferPtr
Definition: Framebuffer.h:114
virtual void bindCubeMap(CubeMapPtr cubeMap, GLuint cubeFace, bool preserveCurrentFramebuffer)
Bind the framebuffer object and draw to the specified cube map.
Definition: Framebuffer.cpp:54
virtual void bindDepthMap(DepthMapPtr depthMap, bool preserveCurrentFramebuffer)
Bind the framebuffer object and draw to the specified depth map.
Definition: Framebuffer.cpp:72
GLint getHeight()
Get the height of the framebuffer.
Definition: Framebuffer.h:90
virtual void bind(bool preserveCurrentFramebuffer)
Bind the framebuffer object.
Definition: Framebuffer.cpp:26
GLuint getDebthbufferID()
Get the depthbuffer id.
Definition: Framebuffer.h:82
virtual void resize(GLint width, GLint height, bool autoResize)
Updates the size of the framebuffer.
Definition: Framebuffer.cpp:123
GLuint getFramebufferID()
Get the framebuffer id.
Definition: Framebuffer.h:78
Framebuffer()
Constructor that takes care of the resolution automatically.
Definition: Framebuffer.cpp:7
std::shared_ptr< CubeMap > CubeMapPtr
Definition: CubeMap.h:33