Operations to Manipulate WebGL Buffers

The operations to manipulate WebGL buffers are summarized in the following table:

Method Description
createBuffer() Creates a new buffer.
deleteBuffer(buffer) Deletes the supplied buffer.
bindBuffer(target, buffer)

Binds a buffer object. The accepted values for target are as follows:

  • ARRAY_BUFFER (for vertices)
  • ELEMENT_ARRAY_BUFFER (for indices)
bufferData(target, data, type)

Provides the buffer data. The accepted values for target are as follows:

  • ARRAY_BUFFER (for vertices)
  • ELEMENT_ARRAY_BUFFER (for indices)

As mentioned earlier, WebGL only accepts JavaScript typed arrays for the data.

The parameter type is a performance hint for WebGL. The accepted values for type are as follows:

  • STATIC_DRAW: Data in the buffer will not be changed (specified once and used many times)
  • DYNAMIC_DRAW: Data will be changed frequently (specified many times and used many times)
  • STREAM_DRAW: Data will change on every rendering cycle (specified once and used once)