/** * init buffers to create a square * @param {any} gl the web gl context * @param {Array} positions the position buffer to be loaded * @param {Array} indices the index buffer to be loaded * @param {Array} normals the normal buffer to be loaded * @param {Array} uvs the texture buffer to be loaded * @return {any} the buffers */ export function initBuffers( gl: any, positions: Array, indices: Array, normals: Array, uvs: Array) { const positionBuffer = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer); gl.bufferData( gl.ARRAY_BUFFER, new Float32Array(positions), gl.STATIC_DRAW); const normalBuffer = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, normalBuffer); gl.bufferData( gl.ARRAY_BUFFER, new Float32Array(normals), gl.STATIC_DRAW); const indexBuffer = gl.createBuffer(); gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer); gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(indices), gl.STATIC_DRAW); // Now send the element array to GL const uvBuffer = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, uvBuffer); gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(uvs), gl.STATIC_DRAW); return { positions: positionBuffer, indices: indexBuffer, normals: normalBuffer, uvs: uvBuffer, }; } /** * init buffers to create a square * @param {any} gl the web gl context * @param {any} buffers the buffers to delete */ export function deleteBuffers(gl: any, buffers: any) { gl.deleteBuffer(buffers.uvs); gl.deleteBuffer(buffers.positions); gl.deleteBuffer(buffers.normals); gl.deleteBuffer(buffers.indices); }