docs.rodeo

MDN Web Docs mirror

WebGLRenderingContext: bufferData() method

{{APIRef("WebGL")}} {{AvailableInWorkers}} 

The WebGLRenderingContext.bufferData() method of the WebGL API initializes and creates the buffer object’s data store.

Syntax

bufferData(target, size, usage)
bufferData(target, srcData, usage)

Parameters

Return value

None ({{jsxref("undefined")}} ).

Exceptions

Examples

Using bufferData

const canvas = document.getElementById("canvas");
const gl = canvas.getContext("webgl");
const buffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
gl.bufferData(gl.ARRAY_BUFFER, 1024, gl.STATIC_DRAW);

Getting buffer information

To check the current buffer usage and buffer size, use the {{domxref("WebGLRenderingContext.getBufferParameter()")}}  method.

gl.getBufferParameter(gl.ARRAY_BUFFER, gl.BUFFER_SIZE);
gl.getBufferParameter(gl.ARRAY_BUFFER, gl.BUFFER_USAGE);

Getting size of a typed array

To calculate size parameter for a typed array.

const dataArray = new Float32Array([1, 2, 3, 4]);
const sizeInBytes = dataArray.length * dataArray.BYTES_PER_ELEMENT;

Specifications

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN