0

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 :)

gman
  • 83,286
  • 25
  • 191
  • 301
Cole-Peterson
  • 39
  • 1
  • 1
  • 7
  • There is no such thing as a "vertex index buffer". – Nicol Bolas Mar 23 '20 at 03:13
  • What I mean is "a buffer for indices that points to the vertices" – Cole-Peterson Mar 23 '20 at 04:15
  • The normal way to do things is that each unique vertex (the combination of position, normal, texcoord, color, etc...) has its own entry and therefore a shared index. If you really want separate indices for positions, normals, etc then you have to resort to [uncommon techniques](https://webglfundamentals.org/webgl/lessons/webgl-pulling-vertices.html) – gman Mar 23 '20 at 04:35

0 Answers0