glBindRenderbuffer — bind a named renderbuffer object
void glBindRenderbuffer( | GLenum target, |
GLuint renderbuffer) ; |
target
Specifies the target to which the renderbuffer object is bound. The symbolic constant must be GL_RENDERBUFFER
.
renderbuffer
Specifies the name of a renderbuffer object.
A renderbuffer is a data storage object containing a single image of a renderable internal format. A renderbuffer's image may be attached to a framebuffer object to use as a destination for rendering and as a source for reading.
glBindRenderbuffer
lets you create or use a named renderbuffer object. Calling glBindRenderbuffer
with target
set to GL_RENDERBUFFER
and renderbuffer
set to the name of the new renderbuffer object binds the renderbuffer object name. When a renderbuffer object is bound, the previous binding is automatically broken.
Renderbuffer object names are unsigned integers. The value zero is reserved, but there is no default renderbuffer object. Instead, renderbuffer
set to zero effectively unbinds any renderbuffer object previously bound. Renderbuffer object names and the corresponding renderbuffer object contents are local to the shared object space of the current GL rendering context.
You may use glGenRenderbuffers to generate a set of new renderbuffer object names.
The state of a renderbuffer object immediately after it is first bound is a zero-sized memory buffer with format GL_RGBA4
and zero-sized red, green, blue, alpha, depth, and stencil pixel depths.
While a non-zero renderbuffer object name is bound, GL operations on target GL_RENDERBUFFER
affect the bound renderbuffer object, and queries of target GL_RENDERBUFFER
return state from the bound renderbuffer object. While renderbuffer object name zero is bound, as in the initial state, attempts to modify or query state on target GL_RENDERBUFFER
generates an GL_INVALID_OPERATION
error.
A renderbuffer object binding created with glBindRenderbuffer
remains active until a different renderbuffer object name is bound, or until the bound renderbuffer object is deleted with glDeleteRenderbuffers.
// 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 color_renderbuffer; glGenRenderbuffers(1, &color_renderbuffer); glBindRenderbuffer( GL_RENDERBUFFER, (GLuint)color_renderbuffer ); glRenderbufferStorage( GL_RENDERBUFFER, GL_RGBA8, fbo_width, fbo_height ); glBindRenderbuffer( GL_RENDERBUFFER, 0 ); // Build the texture that will serve as the depth attachment for the framebuffer. GLuint depth_renderbuffer; glGenRenderbuffers(1, &depth_renderbuffer); glBindRenderbuffer( GL_RENDERBUFFER, (GLuint)depth_renderbuffer ); glRenderbufferStorage( GL_RENDERBUFFER, GL_DEPTH_COMPONENT, fbo_width, fbo_height ); glBindRenderbuffer( GL_RENDERBUFFER, 0 ); // Build the framebuffer. GLuint framebuffer; glGenFramebuffers(1, &framebuffer); glBindFramebuffer(GL_FRAMEBUFFER, (GLuint)framebuffer); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, color_renderbuffer); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth_renderbuffer); GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); if (status != GL_FRAMEBUFFER_COMPLETE) // Error glBindFramebuffer(GL_FRAMEBUFFER, 0);
Songho - OpenGL Frame Buffer Object (FBO)
open.gl - Framebuffers
opengl-tutorial.org - Tutorial 14 : Render To Texture
glDeleteRenderbuffers, glFramebufferRenderbuffer, glGenRenderbuffers, glGet, glGetRenderbufferParameteriv, glIsRenderbuffer, glRenderbufferStorage
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. https://opencontent.org/openpub/.