This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2021.
* Some parts of this feature may have varying levels of support.
Note: This feature is available in Web Workers.
The WebGL2RenderingContext.bufferData() method of the WebGL API creates and initializes the buffer object's data store.
bufferData(target, size, usage) bufferData(target, srcData, usage) bufferData(target, srcData, usage, srcOffset) bufferData(target, srcData, usage, srcOffset, length)
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.
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.
size OptionalA GLsizeiptr setting the size in bytes of the buffer object's data store. One of size and srcData must be provided.
srcData OptionalA TypedArray or a DataView that views an ArrayBuffer or SharedArrayBuffer that will be copied into the data store. If null, a data store is still created, but the content is uninitialized and undefined. One of size and srcData must be provided.
usageA GLenum specifying the intended usage pattern of the data store for optimization purposes. Possible values:
gl.STATIC_DRAWThe contents are intended to be specified once by the application, and used many times as the source for WebGL drawing and image specification commands.
gl.DYNAMIC_DRAWThe contents are intended to be respecified repeatedly by the application, and used many times as the source for WebGL drawing and image specification commands.
gl.STREAM_DRAWThe contents are intended to be specified once by the application, and used at most a few times as the source for WebGL drawing and image specification commands.
gl.STATIC_READThe contents are intended to be specified once by reading data from WebGL, and queried many times by the application.
gl.DYNAMIC_READThe contents are intended to be respecified repeatedly by reading data from WebGL, and queried many times by the application.
gl.STREAM_READThe contents are intended to be specified once by reading data from WebGL, and queried at most a few times by the application
gl.STATIC_COPYThe contents are intended to be specified once by reading data from WebGL, and used many times as the source for WebGL drawing and image specification commands.
gl.DYNAMIC_COPYThe contents are intended to be respecified repeatedly by reading data from WebGL, and used many times as the source for WebGL drawing and image specification commands.
gl.STREAM_COPYThe contents are intended to be specified once by reading data from WebGL, and used at most a few times as the source for WebGL drawing and image specification commands.
srcOffset OptionalA GLuint specifying the element index offset where to start reading the buffer. Only allowed if srcData is provided.
length OptionalA GLuint defaulting to 0. Only allowed if srcOffset is given.
None (undefined).
gl.OUT_OF_MEMORY error is thrown if the context is unable to create a data store with the given size.gl.INVALID_VALUE error is thrown if size is negative.gl.INVALID_ENUM error is thrown if target or usage are not one of the allowed enums.| 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 | |
bufferData |
56 | 79 | 51 | 43 | 15 | 58 | 51 | 43 | 15 | 7.0 | 58 | 15 |
srcData_param_accepts_SharedArrayBuffer |
60 | 79 | 79 | 47 | No | 60 | 79 | 44 | No | 8.0 | 60 | No |
WebGLRenderingContext.bufferData()WebGLRenderingContext.createBuffer()WebGLRenderingContext.bufferSubData()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/WebGL2RenderingContext/bufferData