Real-Time 3D Graphics with WebGL 2
上QQ阅读APP看书,第一时间看更新

WebGL as a State Machine: Buffer Manipulation

When dealing with buffers for the getParametergetBufferParameter, and isBuffer functions, new information about the state of the rendering pipeline becomes available to us.

Similar to Chapter 1, Getting Started, we will use getParameter(parameter), where parameter can have the following values:

  • ARRAY_BUFFER_BINDING: Retrieves a reference to the currently-bound VBO
  • ELEMENT_ARRAY_BUFFER_BINDING: Retrieves a reference to the currently-bound IBO

We can also query the size and the usage of the currently-bound VBO and IBO using getBufferParameter(type, parameter), where type can have the following values:

  • ARRAY_BUFFER: To refer to the currently-bound VBO
  • ELEMENT_ARRAY_BUFFER: To refer to the currently-bound IBO

And parameter can have the following values:

  • BUFFER_SIZE: Returns the size of the requested buffer
  • BUFFER_USAGE: Returns the usage of the requested buffer
Binding Buffers

Your VBO and/or IBO needs to be bound when you inspect the state of the currently-bound VBO and/or IBO with  getParameter and  getBufferParameter.

Finally, isBuffer(object) will return true if the object is a WebGL buffer, or false with an error when the buffer is invalid. Unlike getParameter and getBufferParameterisBuffer does not require any VBO or IBO to be bound.