Say I have a vertex buffer, a vertex index buffer, a normals buffer and a normals index buffer. In total I want 2 attributes per vertex, the positions and the normals. I can render geometry just fine using the vertex buffer and vertex index buffer using gl.drawElements(gl.TRIANGLES, length, gl.UNSIGNED_SHORT, indexBuffer);
and the vertex positions seem to be set correctly with
gl.enableVertexAttribArray(positionAttributeLocation);
gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
gl.vertexAttribPointer(positionAttributeLocation, 3 , gl.FLOAT, false, 0, 0)
but what I'm having trouble understanding is how I send other indexed stuff (in my case normals) to the attributes. I understand that gl.drawElements
knows which array buffer to reference by using the last one bound, but as for attributes, I'm stuck.
In all, how do I tell the vertex index buffer to reference the vertex buffer, and the normal index buffer to reference the normal buffer? And then how does that data get passed to the attributes so I have a normal for every vertex?
I apologize if this kind of question has been asked before, Iv'e been trying to wrap my head around this all day.
Thanks You :)