Light | Dark

# docs.GL

OpenGL 4
OpenGL 3
OpenGL ES 3
OpenGL ES 2

# glFramebufferRenderbuffer

## Name

glFramebufferRenderbuffer — attach a renderbuffer object to a framebuffer object

## C Specification

`void glFramebufferRenderbuffer(` | GLenum target,
| GLenum attachment,
| GLenum renderbuffertarget,
| GLuint renderbuffer`)`;

## Parameters

`target`

  Specifies the framebuffer target. The symbolic constant must be `GL_FRAMEBUFFER`.

`attachment`

  Specifies the attachment point to which `renderbuffer` should be attached. Must be one of the following symbolic constants: `GL_COLOR_ATTACHMENT0`, `GL_DEPTH_ATTACHMENT`, or `GL_STENCIL_ATTACHMENT`.

`renderbuffertarget`

  Specifies the renderbuffer target. The symbolic constant must be `GL_RENDERBUFFER`.

`renderbuffer`

  Specifies the renderbuffer object that is to be attached.

## Description

`glFramebufferRenderbuffer` attaches the renderbuffer specified by `renderbuffer` as one of the logical buffers of the currently bound framebuffer object. `attachment` specifies whether the renderbuffer should be attached to the framebuffer object's color, depth, or stencil buffer. A renderbuffer may not be attached to the default framebuffer object name 0.

If `renderbuffer` is not 0, 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`. `GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL` and `GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE` are set to the default values 0 and `GL_TEXTURE_CUBE_MAP_POSITIVE_X`, respectively. Any previous attachment to the `attachment` logical buffer of the currently bound framebuffer object is broken.

If `renderbuffer` is 0, the current image, if any, attached to the `attachment` logical buffer of the currently bound framebuffer object is detached. The value of `GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE` is set to `GL_NONE`. The value of `GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME` is set to 0. `GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL` and `GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE` are set to the default values 0 and `GL_TEXTURE_CUBE_MAP_POSITIVE_X`, respectively.

## Notes

If a renderbuffer object is deleted while its image is attached to the currently bound framebuffer, then it is as if `glFramebufferRenderbuffer` had been called with a `renderbuffer` of 0 for the attachment point to which this image was attached in the currently bound framebuffer object. In other words, the renderbuffer image is detached from the currently bound framebuffer. Note that the renderbuffer image is specifically not detached from any non-bound framebuffers. Detaching the image from any non-bound framebuffers is the responsibility of the application.

## Errors

`GL_INVALID_ENUM` is generated if `target` is not `GL_FRAMEBUFFER`.

`GL_INVALID_ENUM` is generated if `renderbuffertarget` is not `GL_RENDERBUFFER` and `renderbuffer` is not 0.

`GL_INVALID_ENUM` is generated if `attachment` is not an accepted attachment point.

`GL_INVALID_OPERATION` is generated if the default framebuffer object name 0 is bound.

`GL_INVALID_OPERATION` is generated if `renderbuffer` is neither 0 nor the name of an existing renderbuffer object.

## Associated Gets

glGetFramebufferAttachmentParameteriv

## 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);

## Tutorials

Songho - OpenGL Frame Buffer Object (FBO)
open.gl - Framebuffers
opengl-tutorial.org - Tutorial 14 : Render To Texture

## See Also

glBindFramebuffer, glBindRenderbuffer, glCheckFramebufferStatus, glDeleteFramebuffers, glDeleteRenderbuffers, glFramebufferTexture2D, glGetFramebufferAttachmentParameteriv, glRenderbufferStorage

## Copyright

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/.

Think you can improve this page? Edit this page on GitHub.