0

When I say storage layout, I mean what I define with glVertexAttribPointer. Is this state saved in the currently bound VAO or the buffer I bound to GL_ARRAY_BUFFER?

mak
  • 225
  • 4
  • 11

2 Answers2

1

You can't have multiple "storage layouts" in one VAO. This is for the same reason you can't have multiple textures in one texture object. Or multiple buffers in one buffer object. And so on.

VAOs are the "storage layout". So if you need more than one layout, then you need more than one VAO.

Or you can modify the existing VAO's state; they're not immutable. But that kinda defeats the purpose of the VAO.

Nicol Bolas
  • 378,677
  • 53
  • 635
  • 829
  • I have working code, that first defines and enables my standard vertex attributes (position and normal), then again defines and enables _other_ vertex attributes, that I use for my model matrices (using instanced arrays). Then I do the draw call. Although I changed the VAO state with my second `glVertexAttribPointer`, the standard attributes are still found during rendering. How is this possible? – mak May 28 '16 at 19:16
  • @mak: "*How is this possible?*" I can't tell; I'm not looking at your code. Without that, all I can do is guess based on what you describe your code to be doing. – Nicol Bolas May 28 '16 at 19:54
  • Ok, here is roughly what I am doing, 1. Generate and bind VAO 2. Generate and bind VBO 3. Send vertex data (position and normal) to GPU 4. glVertexAttribPointer and glEnableVertexAttribArray for position and normal 5. Generate and bind another VBO 6. Upload model matrices 7. Use program 8. Set uniforms 9. glVertexAttribPointer, glEnableVertexAttribArray and glVertexAttribDivisor for model matrix columns 10. glDrawArraysInstanced 11. Everything available in shader Shouldn't I have overridden position and normal with model matrix columns? – mak May 28 '16 at 20:02
  • @mak: If you want that answered, put it in your question, where it can be reasonably formatted. Also, that's a very different question from *this one*, so ask it as a separate one. Oh, and it's best to put your actual code, not a description of it. If there are bugs, we can't tell the difference between what you wanted to do and what you wrote. – Nicol Bolas May 28 '16 at 20:03
  • Ok, I have created [this question](http://stackoverflow.com/questions/37509555/how-to-minimize-glvertexattribpointer-calls-when-using-instanced-arrays) – mak May 29 '16 at 11:55
  • BTW it seems like I actually CAN have multiple storage layouts in one VAO because the code in the other question is actually working. – mak May 29 '16 at 12:25
  • @mak: That's not using multiple storage layouts, any more than constantly uploading new data to a texture is using multiple textures. You're merely *changing* the storage layout for each object. If the VAO were actually *storing* multiple layouts, then you would be able to switch between them without resetting the data. – Nicol Bolas May 29 '16 at 12:54
  • But shouldn't the rendered outcome be wrong after I reset the data because the vertex attrib pointers for positions and normals are overridden by those for matrices? – mak May 29 '16 at 13:14
  • @mak: Think about what you just said. Now think about how you can assign attrib pointers for normals, *without* overriding the attributes for positions. – Nicol Bolas May 29 '16 at 13:15
  • By setting offsets and strides. But I first have a position at offset 0 and later I have a matrix column at offset 0. – mak May 29 '16 at 13:17
  • @mak: What is the first parameter to `glVertexAttribPointer`? – Nicol Bolas May 29 '16 at 13:19
  • The attrib's shader location. Sorry, I don't get it. – mak May 29 '16 at 13:35
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/113255/discussion-between-nicol-bolas-and-mak). – Nicol Bolas May 29 '16 at 13:36
0

The "description" you give to glVertexAttribPointer is stored in the VAO state.

So for the same VBO you can have it setup differently in different attributes in the same VAO, or also in other VAO.

246tNt
  • 1,916
  • 1
  • 14
  • 19