FramebuffersGL 3.0

glRenderbufferStorage

Allocates the memory of the bound renderbuffer.

Signature

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

How it works

Gives the bound renderbuffer an image of internalformat and width × height pixels. A renderbuffer is a framebuffer image that shaders cannot read, so it suits buffers needed only while drawing, above all the depth-stencil buffer of an off-screen framebuffer (GL_DEPTH24_STENCIL8).

Its size must match the other attachments; when the window is resized, call it again with the new size.

Parameters

targetGLenum

GL_RENDERBUFFER.

internalformatGLenum

Storage format.

Common values

GL_DEPTH24_STENCIL8
24-bit depth + 8-bit stencil — the common choice.
GL_DEPTH_COMPONENT24 / 32F
Depth only.
GL_RGBA8 / GL_RGBA16F
Color, e.g. an MSAA color target to resolve later.
widthGLsizei

Width in pixels — must match the other attachments.

heightGLsizei

Height in pixels.

Tips & pitfalls

  • On window resize, re-allocate every attachment with the new size.

Example

example.cpp
1glBindRenderbuffer(GL_RENDERBUFFER, rbo);
2glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height);
3glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rbo);
Official Khronos documentation