SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLGLFrameBuffer.h
Go to the documentation of this file.
1 /**
2  * \file SLGLFrameBuffer.h
3  * \brief Wrapper class around OpenGL Frame Buffer Objects (FBO)
4  * \date April 2018
5  * \authors Carlos Arauz, Marcus Hudritsch
6  * \copyright http://opensource.org/licenses/GPL-3.0
7  * \remarks Please use clangformat to format the code. See more code style on
8  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
9 */
10 
11 #ifndef SLGLFRAMEBUFFER_H
12 #define SLGLFRAMEBUFFER_H
13 
14 #include <SLGLTexture.h>
15 
16 //-----------------------------------------------------------------------------
17 /*!
18 The frame buffer class generates a frame buffer and a render buffer, with the
19 default size of 512x512, this can also in run time be changed.
20 */
22 {
23 public:
25  virtual ~SLGLFrameBuffer() { clear(); }
26 
27  //! Calls delete and clears data
28  void clear();
29 
30  //! Deletes this buffers
31  void deleteGL();
32 
33  //! Generates the framebuffer
34  void generate();
35 
36  //! Binds the framebuffer and renderbuffer
37  void bind();
38 
39  //! Unbinds the framebuffer and renderbuffer
40  void unbind();
41 
42  //! Sets the size of the buffer storage
44  SLsizei height);
45 
46  //! Attaches texture image to framebuffer
47  void attachTexture2D(SLenum attachment,
48  SLenum target,
49  SLGLTexture* texture,
50  SLint level = 0);
51 
52  // Getters
53  SLuint fboId() { return this->_fboId; }
54  SLuint rboId() { return this->_rboId; }
55  SLsizei rboWidth() { return this->_rboWidth; }
56  SLsizei rboHeight() { return this->_rboHeight; }
57 
58  // Some statistics
59  static SLuint totalBufferCount; //! static total no. of buffers in use
60  static SLuint totalBufferSize; //! static total size of all buffers in bytes
61 
62 protected:
63  SLuint _fboId; //!< frame buffer identifier
64  SLuint _prevFboId; //!< previously active frame buffer identifier
65  SLuint _rboId; //!< render buffer identifier
66  SLuint _sizeBytes; //!< size in bytes of this buffer
67  SLsizei _rboWidth; //!< width of the render buffer
68  SLsizei _rboHeight; //!< height of the render buffer
69 };
70 //-----------------------------------------------------------------------------
71 #endif
unsigned int SLenum
Definition: SL.h:176
unsigned int SLuint
Definition: SL.h:171
int SLsizei
Definition: SL.h:172
int SLint
Definition: SL.h:170
SLuint _prevFboId
previously active frame buffer identifier
SLsizei rboWidth()
void attachTexture2D(SLenum attachment, SLenum target, SLGLTexture *texture, SLint level=0)
Attaches texture image to framebuffer.
SLsizei _rboHeight
height of the render buffer
void clear()
Calls delete and clears data.
void bindAndSetBufferStorage(SLsizei width, SLsizei height)
Sets the size of the buffer storage.
static SLuint totalBufferCount
SLuint _fboId
static total size of all buffers in bytes
virtual ~SLGLFrameBuffer()
SLsizei _rboWidth
width of the render buffer
SLGLFrameBuffer(SLsizei rboWidth, SLsizei rboHeight)
Constructor.
void generate()
Generates the framebuffer.
static SLuint totalBufferSize
static total no. of buffers in use
void unbind()
Unbinds the framebuffer and renderbuffer.
SLuint _rboId
render buffer identifier
SLuint _sizeBytes
size in bytes of this buffer
void bind()
Binds the framebuffer and renderbuffer.
SLsizei rboHeight()
void deleteGL()
Deletes this buffers.
Texture object for OpenGL texturing.
Definition: SLGLTexture.h:110