Search code examples
c++copenglglew

How does the glVertexAttribPointer stride parameter work?


How does the stride parameter of the glVertexAttribPointer function work? Lets say I have a buffer which is 64 bytes large. I want to store 2 vertices which are 32 bytes large each. If the vertices start one after another, does the stride parameter need to be 0 or 32? What I'm trying to say is does the stride parameter count from the start of the last vertex or from the end of the last vertex?


Solution

  • It counts from the start of the previous vertex.

    But stride == 0 is a special case, it means that your attributes are tightly packed. So e.g. if you're passing a dvec4 (vector of 4 doubles) per vertex, it doesn't matter if you use 0 or 32 (if sizeof(double) * 4 == 32).