SLProject  4.3.020
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLGLFbo.h
Go to the documentation of this file.
1 /**
2  * \file SLGLFbo.h
3  * \brief Wraps an OpenGL framebuffer object
4  * \date September 2018
5  * \authors Stefan Thoeni
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 SLGLFBO_H
12 #define SLGLFBO_H
13 
14 #include <SL.h>
15 
16 //-----------------------------------------------------------------------------
17 //! Wrapper around an OpenGL framebuffer object for offscreen rendering
18 /*! An SLGLFbo owns three GL objects: a framebuffer, a 2D colour texture bound
19 to GL_COLOR_ATTACHMENT0, and a renderbuffer holding a 24 bit depth buffer.
20 Rendering into it and then binding the result as a texture is the usual way to
21 implement a post-processing or reflection pass.
22 
23 \warning The constructor issues OpenGL calls, so an instance may only be
24 created on the main thread once a GL context exists — unlike the mesh classes,
25 it cannot be built during asynchronous asset loading. */
26 class SLGLFbo
27 {
28 public:
29  //! Creates the framebuffer, its colour texture and its depth renderbuffer
30  /*! \param w Width in pixels
31  \param h Height in pixels
32  \param magFilter GL magnification filter of the colour texture
33  \param minFilter GL minification filter of the colour texture
34  \param internalFormat GL internal format of the colour texture
35  \param format GL data type of the colour texture pixels
36  \param wrap GL wrap mode applied to both S and T
37  The previously bound framebuffer is restored before returning. A
38  completeness failure is reported on stderr, not thrown. */
39  SLGLFbo(SLuint w,
40  SLuint h,
41  SLenum magFilter = GL_NEAREST,
42  SLenum minFilter = GL_NEAREST,
43  SLint internalFormat = GL_RGB16F,
44  SLint format = GL_FLOAT,
45  SLint wrap = GL_REPEAT);
46 
47  //! Deletes the texture, the renderbuffer and the framebuffer
48  ~SLGLFbo();
49 
50  //! Binds the colour texture to a texture unit and sets the sampler uniform
51  /*! \param progId GL id of the shader program holding the sampler
52  \param samplerName Name of the sampler uniform in that program
53  \param textureUnit Texture unit to bind to, added to GL_TEXTURE0 */
54  void activateAsTexture(int progId,
55  const SLstring& samplerName,
56  int textureUnit = 0);
57 
58  SLuint width; //!< Width of the framebuffer in pixels
59  SLuint height; //!< Height of the framebuffer in pixels
60  SLuint attachment; //!< \deprecated Never assigned or read; left uninitialised
61  SLuint fboID; //!< GL id of the framebuffer object
62  SLuint texID; //!< GL id of the colour attachment texture
63  SLuint rboID; //!< GL id of the depth renderbuffer
64 };
65 //-----------------------------------------------------------------------------
66 #endif // SLGLFBO_H
unsigned int SLenum
analog to GLenum
Definition: SL.h:203
unsigned int SLuint
analog to GLuint
Definition: SL.h:198
string SLstring
Redefinition of standard types for platform independence.
Definition: SL.h:185
int SLint
analog to GLint
Definition: SL.h:197
Wrapper around an OpenGL framebuffer object for offscreen rendering.
Definition: SLGLFbo.h:27
SLuint texID
GL id of the colour attachment texture.
Definition: SLGLFbo.h:62
void activateAsTexture(int progId, const SLstring &samplerName, int textureUnit=0)
Binds the colour texture to a texture unit and sets the sampler uniform.
Definition: SLGLFbo.cpp:83
SLuint height
Height of the framebuffer in pixels.
Definition: SLGLFbo.h:59
~SLGLFbo()
Deletes the texture, the renderbuffer and the framebuffer.
Definition: SLGLFbo.cpp:77
SLuint attachment
Definition: SLGLFbo.h:60
SLuint fboID
GL id of the framebuffer object.
Definition: SLGLFbo.h:61
SLuint rboID
GL id of the depth renderbuffer.
Definition: SLGLFbo.h:63
SLGLFbo(SLuint w, SLuint h, SLenum magFilter=GL_NEAREST, SLenum minFilter=GL_NEAREST, SLint internalFormat=GL_RGB16F, SLint format=GL_FLOAT, SLint wrap=GL_REPEAT)
Creates the framebuffer, its colour texture and its depth renderbuffer.
Definition: SLGLFbo.cpp:15
SLuint width
Width of the framebuffer in pixels.
Definition: SLGLFbo.h:58