This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Note: This feature is available in Web Workers.
The WebGLRenderingContext.bufferSubData() method of the WebGL API updates a subset of a buffer object's data store.
bufferSubData(target, offset) bufferSubData(target, offset, srcData)
targetA GLenum specifying the binding point (target). Possible values:
gl.ARRAY_BUFFERBuffer containing vertex attributes, such as vertex coordinates, texture coordinate data, or vertex color data.
gl.ELEMENT_ARRAY_BUFFERBuffer used for element indices.
When using a WebGL 2 context, the following values are available additionally:
gl.COPY_READ_BUFFERBuffer for copying from one buffer object to another.
gl.COPY_WRITE_BUFFERBuffer for copying from one buffer object to another.
gl.TRANSFORM_FEEDBACK_BUFFERBuffer for transform feedback operations.
gl.UNIFORM_BUFFERBuffer used for storing uniform blocks.
gl.PIXEL_PACK_BUFFERBuffer used for pixel transfer operations.
gl.PIXEL_UNPACK_BUFFERBuffer used for pixel transfer operations.
dstByteOffsetA GLintptr specifying an offset in bytes where the data replacement will start.
srcData OptionalA TypedArray or a DataView that views an ArrayBuffer or SharedArrayBuffer that will be copied into the data store.
srcOffsetA GLuint specifying the element index offset where to start reading the buffer.
length OptionalA GLuint defaulting to 0.
None (undefined).
gl.INVALID_VALUE error is thrown if the data would be written past the end of the buffer or if data is null.gl.INVALID_ENUM error is thrown if target is not one of the allowed enums.bufferSubData
const canvas = document.getElementById("canvas");
const gl = canvas.getContext("webgl");
const buffer = gl.createBuffer();
const data = new Float32Array([1, 2, 3, 4]);
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
gl.bufferData(gl.ARRAY_BUFFER, 1024, gl.STATIC_DRAW);
gl.bufferSubData(gl.ARRAY_BUFFER, 512, data);
| Specification |
|---|
| WebGL Specification> # 5.14.5> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
bufferSubData |
9 | 12 | 4 | 12 | 5.1 | 25 | 4 | 12 | 8 | 1.5 | 4.4.3 | 8 |
WebGL2RenderingContext.bufferSubData()WebGLRenderingContext.createBuffer()WebGLRenderingContext.bufferData()WebGLFramebuffer, WebGLRenderbuffer
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/bufferSubData