The CPU and the GPU

In the same manner, we copy the triangle data from the array in CPU memory to the buffer in GPU memory. This time, we use the ELEMENT_ARRAY_BUFFER binding point.

triangleArray = new Uint16Array(flatten(triangles));

gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, triangleBuffer);
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, triangleArray, gl.STATIC_DRAW);

Again, we must convert the data from JavaScript values to binary 16-bit integer values.