glCheckFramebufferStatus — return the framebuffer completeness status of a framebuffer object
Specifies the target framebuffer object. The symbolic constant must be
glCheckFramebufferStatus returns a symbolic constant that identifies whether or not the currently bound framebuffer is framebuffer complete, and if not, which of the rules of framebuffer completeness is violated.
If the framebuffer is complete, then
GL_FRAMEBUFFER_COMPLETE is returned. If the framebuffer is not complete, the return values are as follows:
Not all framebuffer attachment points are framebuffer attachment complete. This means that at least one attachment point with a renderbuffer or texture attached has its attached object no longer in existence or has an attached image with a width or height of zero, or the color attachment point has a non-color-renderable image attached, or the depth attachment point has a non-depth-renderable image attached, or the stencil attachment point has a non-stencil-renderable image attached.
Color-renderable formats include
GL_DEPTH_COMPONENT16 is the only depth-renderable format.
GL_STENCIL_INDEX8 is the only stencil-renderable format.
Not all attached images have the same width and height.
No images are attached to the framebuffer.
The combination of internal formats of the attached images violates an implementation-dependent set of restrictions.
If the currently bound framebuffer is not framebuffer complete, then it is an error to attempt to use the framebuffer for writing or reading. This means that rendering commands (glClear, glDrawArrays, and glDrawElements) as well as commands that read the framebuffer (glReadPixels, glCopyTexImage2D, and glCopyTexSubImage2D) will generate the error
GL_INVALID_FRAMEBUFFER_OPERATION if called while the framebuffer is not framebuffer complete.
It is strongly advised, thought not required, that an application call
glCheckFramebufferStatus to see if the framebuffer is complete prior to rendering. This is because some implementations may not support rendering to particular combinations of internal formats. In this case,
GL_FRAMEBUFFER_UNSUPPORTED is returned.
The default window-system-provided framebuffer is always framebuffer complete, and thus
GL_FRAMEBUFFER_COMPLETE is returned when
GL_FRAMEBUFFER_BINDING is 0.
Additionally, if an error occurs, zero is returned.
// fbo_width and fbo_height are the desired width and height of the FBO. // For Opengl <= 4.4 or if the GL_ARB_texture_non_power_of_two extension // is present, fbo_width and fbo_height can be values other than 2^n for // some integer n. // Build the texture that will serve as the color attachment for the framebuffer. GLuint texture_map; glGenTextures(1, &texture_map); glBindTexture(GL_TEXTURE_2D, texture_map); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fbo_width, fbo_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); glBindTexture(GL_TEXTURE_2D, 0); // Build the texture that will serve as the depth attachment for the framebuffer. GLuint depth_texture; glGenTextures(1, &depth_texture); glBindTexture(GL_TEXTURE_2D, depth_texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, fbo_width, fbo_height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL); glBindTexture(GL_TEXTURE_2D, 0); // Build the framebuffer. GLuint framebuffer; glGenFramebuffers(1, &framebuffer); glBindFramebuffer(GL_FRAMEBUFFER, (GLuint)framebuffer); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture_map, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depth_texture, 0); GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); if (status != GL_FRAMEBUFFER_COMPLETE) // Error glBindFramebuffer(GL_FRAMEBUFFER, 0);
Copyright © 2008 Khronos Group. This material may be distributed subject to the terms and conditions set forth in the Open Publication License, v 1.0, 8 June 1999. http://opencontent.org/openpub/.