Renderbuffer Object

From OpenGL Wiki
Revision as of 20:17, 16 March 2010 by Alfonse (talk | contribs) (moved Renderbuffer Objects to Renderbuffer Object: de-pluralizing, per Wikipedia standard.)
Jump to navigation Jump to search

Renderbuffer Objects are OpenGL Objects that contain images. They are created and used specifically with Framebuffer Objects. They are optimized for being used as render targets, while Textures may not be.


Renderbuffer objects are standard OpenGL objects. So they have the usual glGen*/glDelete* creation and destruction functions. They also have the usual glBindRenderbuffer function to bind them. It takes a target parameter, but the only viable target is GL_RENDERBUFFER.

Similar to Texture objects, renderbuffers are empty at initialization. Before you can get to binding them to a Framebuffer Object, you must allocate storage for the renderbuffer. To do this, simply call:

 void glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height);

The target should be GL_RENDERBUFFER, the same target you bound the renderbuffer object to. The internalformat should be an internal format used for images. The article on Image Formats elaborates in detail on the meaning of these formats. The width and height are the width and height of the renderbuffer.

If you wish to create a multisample renderbuffer, you use a slightly different function:

 void glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);

This works exactly like the original except for the samples parameter. Indeed, it works exactly like the original if you pass 0 for samples. The samples parameter is the number of samples in the buffer. It must be less than GL_MAX_SAMPLES.

Similar to glTexImage2d, calling this function on a renderbuffer than has already had this function called on it will cause it to deallocate any resources associated with the previous call and allocate new storage.

Note: You are strongly advised not to do this. If you need a new renderbuffer, just delete the old object and create a new one. Recreating a renderbuffer with the same object name can cause completeness problems, particularly if it is attached to another object at the time.


You may have noticed that, unlike glTexImage2d, there are no parameters in these creation functions to actually initialize the data. The renderbuffer is created uninitialized. There is also no function to upload data to the renderbuffer like glTexSubImage2d.

No, the only way to use a renderbuffer object is to attach it to a Framebuffer Object. After you bind that FBO to the context, and set up the draw or read buffers appropriately, you can use pixel transfer operations to read and write to it. Of course, you can also render to it. The standard glClear function will also clear the appropriate buffer.