Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exercise: interleaved attributes confusion #91

Open
nelsonvassalo opened this issue Oct 3, 2017 · 1 comment
Open

Exercise: interleaved attributes confusion #91

nelsonvassalo opened this issue Oct 3, 2017 · 1 comment

Comments

@nelsonvassalo
Copy link

nelsonvassalo commented Oct 3, 2017

How do we compute the byte values for our images?

  gl.enableVertexAttribArray(0)
  gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 16, 0)

  gl.enableVertexAttribArray(1)
  gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 16, 8)

The solution tells us is 16, but why? And why is the second "geometry" offset by only 8 then? Assuming it starts at the end of the previous, shouldn't it be at 17?

Thanks

@ayamflow
Copy link

ayamflow commented Jun 5, 2018

Had some trouble with this one too, here's what I understood:

[
  startx0, starty0, endx0, endy0, // vertex 0
  startx1, starty1, endx1, endy1, // vertex 1
  startx2, starty2, endx2, endy2, // vertex 2
  ...
]

stride is the BYTES_PER_ELEMENT * < number of elements per row >
There are 4 floats between startx0 and startx1, so the stride is 4 * 4 = 16;

offset is BYTES_PER_ELEMENT * < number of elements before the value >
there are 2 elements before endx0, so the offset is 4 * 2 = 8.

Hopefully this is correct and is helpful ✌️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants