Export (0) Print
Expand All
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

bindBuffer method

Associates a buffer with a buffer target.

IE11

 

Syntax

WebGLRenderingContext.bindBuffer(target, buffer);

Parameters

target [in]

Type: Number

One of the following:

gl.ARRAY_BUFFER
gl.ELEMENT_ARRAY_BUFFER
buffer [in]

Type: WebGLBuffer

A WebGLBuffer object to bind to target.

Return value

This method does not return a value.

Remarks

WebGL errorDescription
gl.INVALID_ENUMIf target is not one of the listed values..

 

Call bindBuffer with target set to one of the two constants and buffer references a WebGLBuffer object to bind the buffer object to target. When a buffer is bound to a target, the previously bound buffer for that target is automatically unbound.

Examples

This example creates a shader, gets shader source, and binds it to a buffer using bindBuffer. For more info on this example, see Get started with WebGL.



  // Look up where the vertex data needs to go.
this.texCoordLocation2 = gl.getAttribLocation(this.lineprogram, "a_texCoord");

  // Provide texture coordinates for the rectangle.
this.texCoordBuffer2 = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, this.texCoordBuffer2);
      
// Create a buffer and set it use the array set up above.
// Set it to be modified once, use many.
// createRedGrid sets up the vector array itself.        
gl.bufferData(gl.ARRAY_BUFFER, createRedGrid(), gl.STATIC_DRAW); // Fill buffer data

// Turns on the vertex attributes in the GPU program. 
gl.enableVertexAttribArray(this.texCoordLocation2);

// Set up the data format for the vertex array - set to points (x/y). 
// Use floats.
gl.vertexAttribPointer(this.texCoordLocation2, 2, gl.FLOAT, false, 0, 0);
}


See also

WebGLRenderingContext

 

 

Show:
© 2015 Microsoft