I just started a gltf loader. I thought I understood the design until I encountered large accessor offsets.
The mental model I had was:
- glTF buffer = OpenGL buffer.
- glTF bufferview = OpenGL bindingindex (eg glVertexArrayVertexBuffer).
- glTF accessor = OpenGL attribindex.
My workflow is this:
- For each gltf buffer, glCreateBuffers a GL buffer and load it up completely.
- For each primitive in each mesh:
a. Create a VAO.
b. glVertexArrayElementBuffer the buffer associated with the indices’ accessor’s buffer.
c. For each vertex attribute in the primitive:
i. Associate each bufferView referenced by an attribute accessor with glVertexArrayVertexBuffer. This sets the view->offset and view->stride.
ii. glEnableVertexArrayAttrib the attribute index.
iii. glVertexArrayAttribBinding to associate the bindingindex of the bufferView from (i) with the attribindex from (ii).
iv. glVertexArrayAttribFormat to define the vertex attribute’s type, size and relative offset from the attribute’s accessor.
I was expecting accessor’s offset to be less than the stride of its bufferView, but it’s not. It includes large linear offsets:
There’s one bufferView per stride, and accessors are linearly separated into those, not interleaved. OpenGL gives an "Invalid " error in the glVertexArrayAttribFormat with the large offset.
How am I supposed to interpret these data structures, and what’s the point of bufferView? Seems like it may have no special OpenGL treatment and I should just fold its offset/stride into the accessor.
The primitive loading attempt is here