luma.gl

Renderbuffer

Renderbuffers are WebGL Objects that contain textures. They are optimized for use as render targets, while vanilla Textures may not be, and are the logical choice when you do not need to sample (i.e. in a post-pass shader) from the produced image. If you do need to sample (such as when reading depth back in a second shader pass), use Texture instead. In addition, in WebGL2, Renderbuffer can do Multisampling (MSAA) just like standard framebuffer.

For additional information, see OpenGL Wiki

Usage

Creating a Renderbuffer

const renderbuffer = new Renderbuffer(gl, {format: GL.RGBA4, width: 100, height: 100});

Reformatting/reinitializing a Renderbuffer

const renderbuffer = new Renderbuffer(gl, {format: GL.RGBA4, width: 100, height: 100});
renderbuffer.initialize({format: GL.RGB565, width: 50, height: 50});

Resizing a Renderbuffer

const renderbuffer = new Renderbuffer(gl, {format: GL.RGBA4});
renderbuffer.resize({width: 200, height: 200});

Attaching a Renderbuffer to a Framebuffer (automatically resizes the Renderbuffer)

framebuffer.attach({
  [GL.DEPTH_ATTACHMENT]: new Renderbuffer(gl, {format: GL.DEPTH_COMPONENT16})
 });

Members

Methods

getSamplesForFormat (static method)

Queries valid sample counts for a Renderbuffer format. The sample counts can be provided as a parameter to the Renderbuffer constructor.

Renderbuffer.getSamplesForFormat({format})

Returns (Number[]) - An list of valid sample counts in descending order.

If multisampling is not supported the returned value will be [0], e.g. signed and unsigned integer internal formats in WebGL2. Note that this method always returns [0] in WebGL1.

constructor

Creates a new Renderbuffer and initalizes it by calling initialize with the provided parameters.

new Renderbuffer(gl, {id=, format, width, height, samples=})

WebGL References gl.createRenderbuffer, also see initialize.

initialize

Creates and initializes a renderbuffer object’s data store. Used to update a Renderbuffers format and size after it was initially created.

Renderbuffer.initialize({format, width, height, samples=})

Returns itself to enable chaining

WebGL References gl.renderbufferStorage, gl.renderbufferStorageMultisample (WebGL2), gl.bindRenderbuffer

resize

Reinitializes the Renderbuffer’s data store with the new width and height but unchanged format (and samples, if available).

Renderbuffer.resize({width, height})

Returns itself to enable chaining

WebGL References see initialize.

Renderbuffer Formats

The “internal” format of the Renderbuffer.

Value Description
GL.RGBA4 4 red bits, 4 green bits, 4 blue bits 4 alpha bits
GL.RGB565 5 red bits, 6 green bits, 5 blue bits
GL.RGB5_A1 5 red bits, 5 green bits, 5 blue bits, 1 alpha bit
GL.DEPTH_COMPONENT16 16 depth bits
GL.STENCIL_INDEX8 8 stencil bits

This table lists the basic formats supported in WebGL1. For a full table of formats supported in WebGL2 and via WebGL extensions, see Texture.

Sized Internal Format Format Type Depth Bits Stencil Bits
GL.DEPTH_COMPONENT16 GL.DEPTH_COMPONENT GL.UNSIGNED_SHORT, GL.UNSIGNED_INT 16 0
GL.DEPTH_COMPONENT24 GL.DEPTH_COMPONENT GL.UNSIGNED_INT 24 0
GL.DEPTH_COMPONENT32F GL.DEPTH_COMPONENT GL.FLOAT f32 0
GL.DEPTH24_STENCIL8 GL.DEPTH_STENCIL GL.UNSIGNED_INT_24_8 24 8
GL.DEPTH32F_STENCIL8 GL.DEPTH_STENCIL GL.FLOAT_32_UNSIGNED_INT_24_8_REV f32 8

When using the WEBGL_depth_texture extension: GL.DEPTH_COMPONENT GL.DEPTH_STENCIL When using the EXT_sRGB extension: EXT.SRGB_EXT EXT.SRGB_ALPHA_EXT

When using a WebGL 2 context, the following values are available additionally:

Parameters

Parameter Type Read/Write Description
GL.RENDERBUFFER_WIDTH GLint R height of the image of renderbuffer
GL.RENDERBUFFER_HEIGHT GLint R height of the image of renderbuffer
GL.RENDERBUFFER_INTERNAL_FORMAT GLenum R See below
GL.RENDERBUFFER_GREEN_SIZE GLint R resolution (bits) of green color
GL.RENDERBUFFER_BLUE_SIZE GLint R resolution (bits) of blue color
GL.RENDERBUFFER_RED_SIZE GLint R resolution (bits) of red color
GL.RENDERBUFFER_ALPHA_SIZE GLint R resolution (bits) of alpha component
GL.RENDERBUFFER_DEPTH_SIZE GLint R resolution (bits) of depth component
GL.RENDERBUFFER_STENCIL_SIZE GLint R resolution (bits) of stencil component
GL.RENDERBUFFER_SAMPLES (WebGL2) GLint R  

Limits

Limit   WebGL2 WebGL1
GL.MAX_RENDERBUFFER_SIZE Max renderbuffer width/height >=2048 >=1
GL.MAX_SAMPLES Max samples for multisampling >=4 0

Remarks