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.
void glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height);
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
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 parameter is the number of samples in the buffer. It must be less than GL_MAX_SAMPLES.
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
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.