From 4fdb59596f94f3e2608fc72759e65e7e30ca98e3 Mon Sep 17 00:00:00 2001 From: Paul Mathieu Date: Wed, 15 Dec 2021 14:36:31 -0800 Subject: [PATCH] Save a few more webgl calls --- index.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index fdc86f1..0835ae8 100644 --- a/index.js +++ b/index.js @@ -339,6 +339,12 @@ async function initWorldGl(gl) { // doing this here because it's the same for all world stuff gl.uniformMatrix4fv(modelLoc, false, new Float32Array(se3.identity())); gl.uniform1i(samplerLoc, 0); + + gl.enableVertexAttribArray(positionLoc); + gl.enableVertexAttribArray(normalLoc); + gl.enableVertexAttribArray(textureLoc); + gl.activeTexture(gl.TEXTURE0); + gl.bindTexture(gl.TEXTURE_2D, texture); }; const drawObject = (objectParams) => { @@ -350,16 +356,8 @@ async function initWorldGl(gl) { gl.bindBuffer(gl.ARRAY_BUFFER, glBuffer); gl.vertexAttribPointer(positionLoc, 3, gl.FLOAT, false, 20, 0); - gl.enableVertexAttribArray(positionLoc); - gl.vertexAttribPointer(normalLoc, 3, gl.BYTE, true, 20, 12); - gl.enableVertexAttribArray(normalLoc); - gl.vertexAttribPointer(textureLoc, 2, gl.UNSIGNED_SHORT, true, 20, 16); - gl.enableVertexAttribArray(textureLoc); - - gl.activeTexture(gl.TEXTURE0); - gl.bindTexture(gl.TEXTURE_2D, texture); gl.drawArrays(gl.TRIANGLES, 0, numVertices); }; @@ -389,11 +387,11 @@ async function main() { velocity: [0, 0, 0], }, keys: new Set(), - world: makeWorld(), lightDirection: [-0.2, -0.5, 0.4], ambiantLight: 0.7, flying: false, isOnGround: false, + world: makeWorld(), worldGl, }