design/gpu-programming/webgl/experiment/game-of-life/external/webgl-utils.js
function createBuffersFromArrays(gl, arrays) {
    var buffers = { };
    Object.keys(arrays).forEach(function(key) {
      var type = key === "indices" ? gl.ELEMENT_ARRAY_BUFFER : gl.ARRAY_BUFFER;
      var array = makeTypedArray(arrays[key], name);
      buffers[key] = createBufferFromTypedArray(gl, array, type);
    });

    // hrm
    if (arrays.indices) {
      buffers.numElements = arrays.indices.length;
    } else if (arrays.position) {
      buffers.numElements = arrays.position.length / 3;
    }

    return buffers;
  }
function createBuffersFromArrays(gl, arrays) {
    var buffers = { };
    Object.keys(arrays).forEach(function(key) {
      var type = key === "indices" ? gl.ELEMENT_ARRAY_BUFFER : gl.ARRAY_BUFFER;
      var array = makeTypedArray(arrays[key], name);
      buffers[key] = createBufferFromTypedArray(gl, array, type);
    });

    // hrm
    if (arrays.indices) {
      buffers.numElements = arrays.indices.length;
    } else if (arrays.position) {
      buffers.numElements = arrays.position.length / 3;
    }

    return buffers;
  }
function createBuffersFromArrays ( gl , arrays ) { var buffers = { } ; Object . keys ( arrays ) . forEach ( function ( key ) { var type = key === "indices" ? gl . ELEMENT_ARRAY_BUFFER : gl . ARRAY_BUFFER ; var array = makeTypedArray ( arrays [ key ] , name ) ; buffers [ key ] = createBufferFromTypedArray ( gl , array , type ) ; } ) ; // hrm if ( arrays . indices ) { buffers . numElements = arrays . indices . length ; } else if ( arrays . position ) { buffers . numElements = arrays . position . length / 3 ; } return buffers ; }
Creates buffers from typed arrays

Given something like this

var arrays = {
positions: [1, 2, 3],
normals: [0, 0, 1],
}

returns something like

buffers = {
positions: WebGLBuffer,
normals: WebGLBuffer,
}

If the buffer is named 'indices' it will be made an ELEMENT_ARRAY_BUFFER.

@param {WebGLRenderingContext} gl A WebGLRenderingContext.
@param {Object<string, array|typedarray>} arrays
@return {Object<string, WebGLBuffer>} returns an object with one WebGLBuffer per array
@memberOf module:webgl-utils
Creates buffers from typed arrays