21 SLint wrap) : width(w), height(h)
23 GLint previousFrameBuffer;
24 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &previousFrameBuffer);
27 glGenFramebuffers(1, &
fboID);
28 glBindFramebuffer(GL_FRAMEBUFFER,
fboID);
30 glGenTextures(1, &
texID);
31 glBindTexture(GL_TEXTURE_2D,
texID);
34 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter);
35 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter);
36 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap);
37 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap);
39 glTexImage2D(GL_TEXTURE_2D,
49 glFramebufferTexture2D(GL_FRAMEBUFFER,
55 glGenRenderbuffers(1, &
rboID);
56 glBindRenderbuffer(GL_RENDERBUFFER,
rboID);
59 glRenderbufferStorage(GL_RENDERBUFFER,
64 glFramebufferRenderbuffer(GL_FRAMEBUFFER,
69 glBindRenderbuffer(GL_RENDERBUFFER, 0);
70 glBindFramebuffer(GL_FRAMEBUFFER,
73 if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
74 std::cerr <<
"FBO failed to initialize correctly." << std::endl;
79 glDeleteTextures(1, &
texID);
80 glDeleteFramebuffers(1, &
fboID);
85 const int textureUnit)
87 glActiveTexture(GL_TEXTURE0 + textureUnit);
88 glBindTexture(GL_TEXTURE_2D,
texID);
89 glUniform1i(glGetUniformLocation(progId,
90 glSamplerName.c_str()),
unsigned int SLenum
analog to GLenum
unsigned int SLuint
analog to GLuint
string SLstring
Redefinition of standard types for platform independence.
Wraps an OpenGL framebuffer object.
Singleton class for global render state.
SLuint texID
GL id of the colour attachment texture.
void activateAsTexture(int progId, const SLstring &samplerName, int textureUnit=0)
Binds the colour texture to a texture unit and sets the sampler uniform.
~SLGLFbo()
Deletes the texture, the renderbuffer and the framebuffer.
SLuint fboID
GL id of the framebuffer object.
SLuint rboID
GL id of the depth renderbuffer.
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.