bindBuffer now invokes gl.bindBuffer. We only call createBuffer when setting up the scene. But we call bindBuffer on each frame we render.
103 function bindBuffer(vertexBuffer, attribute, size, type, stride, offset) 104 { 105 // Binding an object in Open GL makes it the target of subsequent operations. 106 gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer); 107 108 // Lookup a shader attribute location 109 var attributeLocation = gl.getAttribLocation(program, attribute); 110 111 // enable that attribute (location) to receive data from an array 112 // The vertexBuffer, defined above, is used because it is the currently bound buffer. 113 gl.enableVertexAttribArray(attributeLocation); 114 115 // Each element in the vector contains 3 floating point entries, they should not be normalized, 116 // there are no array entries between attribute values, and the first element is at position 117 // 0 in the array. 118 gl.vertexAttribPointer(attributeLocation, size, gl.FLOAT, false, stride, offset); 119 }
This is the same method as previously, with one alteration. gl.bindBuffer is invoked at the top of the method to identify the vertices we are working with.
Continue as before to lookup the index of the attribute by name with gl.getAttribLocation.
Enable the attribute for input by passing that index to gl.enableVertexAttribArray.
Finally, vertexAttribPointer describes exactly how to map the currently bound buffer to the attibute.