vaoForInstancing = {
const vao = gl.createVertexArray()
gl.bindVertexArray(vao)
{
const numComponents = 2;
const type = gl.FLOAT;
const normalize = false;
const stride = 0;
const offset = 0;
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
gl.vertexAttribPointer(
attributeLocationsForInstancing.position,
numComponents,
type,
normalize,
stride,
offset);
gl.enableVertexAttribArray(attributeLocationsForInstancing.position);
}
{
const numComponents = 4;
const type = gl.FLOAT;
const normalize = false;
const stride = 0;
const offset = 0;
gl.bindBuffer(gl.ARRAY_BUFFER, colorBuffer);
gl.vertexAttribPointer(
attributeLocationsForInstancing.color,
numComponents,
type,
normalize,
stride,
offset);
gl.enableVertexAttribArray(attributeLocationsForInstancing.color);
}
{
gl.bindBuffer(gl.ARRAY_BUFFER, transformsBuffer);
for (let i = 0; i < 4; i++) {
const loc = attributeLocationsForInstancing.transform + i;
gl.enableVertexAttribArray(loc);
const numComponents = 4;
const type = gl.FLOAT;
const normalize = false;
const stride = 4 * 16;
const offset = i * 16;
gl.vertexAttribPointer(
loc,
numComponents,
type,
normalize,
stride,
offset);
gl.vertexAttribDivisor(loc, 1)
}
}
{
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, ebo)
}
return vao
}