Light | Dark

glFramebufferRenderbuffer

Name

glFramebufferRenderbuffer, glNamedFramebufferRenderbuffer — attach a renderbuffer as a logical buffer of a framebuffer object

C Specification

void glFramebufferRenderbuffer( GLenum target,
GLenum attachment,
GLenum renderbuffertarget,
GLuint renderbuffer);
void glNamedFramebufferRenderbuffer( GLuint framebuffer,
GLenum attachment,
GLenum renderbuffertarget,
GLuint renderbuffer);

Parameters

target

Specifies the target to which the framebuffer is bound for glFramebufferRenderbuffer.

framebuffer

Specifies the name of the framebuffer object for glNamedFramebufferRenderbuffer.

attachment

Specifies the attachment point of the framebuffer.

renderbuffertarget

Specifies the renderbuffer target. Must be GL_RENDERBUFFER.

renderbuffer

Specifies the name of an existing renderbuffer object of type renderbuffertarget to attach.

Description

glFramebufferRenderbuffer and glNamedFramebufferRenderbuffer attaches a renderbuffer as one of the logical buffers of the specified framebuffer object. Renderbuffers cannot be attached to the default draw and read framebuffer, so they are not valid targets of these commands.

For glFramebufferRenderbuffer, the framebuffer object is that bound to target, which must be GL_DRAW_FRAMEBUFFER, GL_READ_FRAMEBUFFER or GL_FRAMEBUFFER. GL_FRAMEBUFFER is equivalent to GL_DRAW_FRAMEBUFFER.

For glNamedFramebufferRenderbuffer, framebuffer is the name of the framebuffer object.

renderbuffertarget must be GL_RENDERBUFFER.

renderbuffer must be zero or the name of an existing renderbuffer object of type renderbuffertarget. If renderbuffer is not zero, then the specified renderbuffer will be used as the logical buffer identified by attachment of the specified framebuffer object. If renderbuffer is zero, then the value of renderbuffertarget is ignored.

attachment specifies the logical attachment of the framebuffer and must be GL_COLOR_ATTACHMENTi, GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT or GL_DEPTH_STENCIL_ATTACHMENT. i in may range from zero to the value of GL_MAX_COLOR_ATTACHMENTS minus one. Setting attachment to the value GL_DEPTH_STENCIL_ATTACHMENT is a special case causing both the depth and stencil attachments of the specified framebuffer object to be set to renderbuffer, which should have the base internal format GL_DEPTH_STENCIL.

The value of GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE for the specified attachment point is set to GL_RENDERBUFFER and the value of GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME is set to renderbuffer. All other state values of specified attachment point are set to their default values. No change is made to the state of the renderbuuffer object and any previous attachment to the attachment logical buffer of the specified framebuffer object is broken.

If renderbuffer is zero, these commands will detach the image, if any, identified by the specified attachment point of the specified framebuffer object. All state values of the attachment point are set to their default values.

Errors

GL_INVALID_ENUM is generated by glFramebufferRenderbuffer if target is not one of the accepted framebuffer targets.

GL_INVALID_OPERATION is generated by glFramebufferRenderbuffer if zero is bound to target.

GL_INVALID_OPERATION is generated by glNamedFramebufferRenderbuffer if framebuffer is not the name of an existing framebuffer object.

GL_INVALID_ENUM is generated if attachment is not one of the accepted attachment points.

GL_INVALID_ENUM is generated if renderbuffertarget is not GL_RENDERBUFFER.

GL_INVALID_OPERATION is generated if renderbuffertarget is not zero or the name of an existing renderbuffer object of type GL_RENDERBUFFER.

Examples

Create a framebuffer object with a renderbuffer-based color attachment and a renderbuffer-based depth attachment.
// 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);

Version Support

OpenGL Version
Function / Feature Name 2.0 2.1 3.0 3.1 3.2 3.3 4.0 4.1 4.2 4.3 4.4 4.5
glFramebufferRenderbuffer - -
glNamedFramebufferRenderbuffer - - - - - - - - - - -
Think you can improve this page? Edit this page on GitHub.