Save a few more webgl calls

This commit is contained in:
Paul Mathieu 2021-12-15 14:36:31 -08:00
parent 7bc7b64c8b
commit 4fdb59596f

View File

@ -339,6 +339,12 @@ async function initWorldGl(gl) {
// doing this here because it's the same for all world stuff // doing this here because it's the same for all world stuff
gl.uniformMatrix4fv(modelLoc, false, new Float32Array(se3.identity())); gl.uniformMatrix4fv(modelLoc, false, new Float32Array(se3.identity()));
gl.uniform1i(samplerLoc, 0); 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) => { const drawObject = (objectParams) => {
@ -350,16 +356,8 @@ async function initWorldGl(gl) {
gl.bindBuffer(gl.ARRAY_BUFFER, glBuffer); gl.bindBuffer(gl.ARRAY_BUFFER, glBuffer);
gl.vertexAttribPointer(positionLoc, 3, gl.FLOAT, false, 20, 0); gl.vertexAttribPointer(positionLoc, 3, gl.FLOAT, false, 20, 0);
gl.enableVertexAttribArray(positionLoc);
gl.vertexAttribPointer(normalLoc, 3, gl.BYTE, true, 20, 12); gl.vertexAttribPointer(normalLoc, 3, gl.BYTE, true, 20, 12);
gl.enableVertexAttribArray(normalLoc);
gl.vertexAttribPointer(textureLoc, 2, gl.UNSIGNED_SHORT, true, 20, 16); 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); gl.drawArrays(gl.TRIANGLES, 0, numVertices);
}; };
@ -389,11 +387,11 @@ async function main() {
velocity: [0, 0, 0], velocity: [0, 0, 0],
}, },
keys: new Set(), keys: new Set(),
world: makeWorld(),
lightDirection: [-0.2, -0.5, 0.4], lightDirection: [-0.2, -0.5, 0.4],
ambiantLight: 0.7, ambiantLight: 0.7,
flying: false, flying: false,
isOnGround: false, isOnGround: false,
world: makeWorld(),
worldGl, worldGl,
} }