WebGL2RenderingContext: bufferData() method
Baseline Widely available *
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 inWeb Workers.
TheWebGL2RenderingContext.bufferData() method of theWebGL API creates and initializes the buffer object's data store.
In this article
Syntax
bufferData(target, size, usage)bufferData(target, srcData, usage)bufferData(target, srcData, usage, srcOffset)bufferData(target, srcData, usage, srcOffset, length)Parameters
targetA
GLenumspecifying the binding point (target). Possible values:gl.ARRAY_BUFFERBuffer containing vertex attributes, such asvertex 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.
sizeOptionalA
GLsizeiptrsetting the size in bytes of the buffer object's datastore.One ofsizeandsrcDatamust be provided.srcDataOptionalA
TypedArrayor aDataViewthat views anArrayBufferorSharedArrayBufferthat will be copied into the data store.Ifnull, a data store is still created, but the content is uninitialized and undefined.One ofsizeandsrcDatamust be provided.usageA
GLenumspecifying the intended usage pattern of the data storefor optimization purposes. Possible values:gl.STATIC_DRAWThe contents are intended to be specifiedonce by the application, and used many times as the source for WebGLdrawing and image specification commands.
gl.DYNAMIC_DRAWThe contents are intended to be respecifiedrepeatedly by the application, and used many times as the source for WebGLdrawing and image specification commands.
gl.STREAM_DRAWThe contents are intended to be specifiedonce by the application, and used at most a few times as the source forWebGL drawing and image specification commands.
gl.STATIC_READThe contents are intended to bespecified once by reading data from WebGL, and queried many timesby the application.
gl.DYNAMIC_READThe contents are intended to berespecified repeatedly by reading data from WebGL, and queriedmany times by the application.
gl.STREAM_READThe contents are intended to bespecified once by reading data from WebGL, and queried at most afew times by the application
gl.STATIC_COPYThe contents are intended to bespecified once by reading data from WebGL, and used many times asthe source for WebGL drawing and image specification commands.
gl.DYNAMIC_COPYThe contents are intended to berespecified repeatedly by reading data from WebGL, and used manytimes as the source for WebGL drawing and image specificationcommands.
gl.STREAM_COPYThe contents are intended to bespecified once by reading data from WebGL, and used at most a fewtimes as the source for WebGL drawing and image specificationcommands.
srcOffsetOptionalA
GLuintspecifying the element index offset where to start readingthe buffer.Only allowed ifsrcDatais provided.lengthOptionalA
GLuintdefaulting to 0.Only allowed ifsrcOffsetis given.
Return value
None (undefined).
Exceptions
- A
gl.OUT_OF_MEMORYerror is thrown if the context is unable to createa data store with the givensize. - A
gl.INVALID_VALUEerror is thrown ifsizeis negative. - A
gl.INVALID_ENUMerror is thrown iftargetorusageare not one of the allowed enums.
Specifications
| Specification |
|---|
| WebGL Specification> # 5.14.5> |