1

My current understanding is that when I do instanced rendering, I pack vertex, texture, normal, index and instance data to a single VAO.

This is a bit of a problem, I'd want to separate instance data from the rest. The reason for this is that I desire to make OO code and make a Mesh class that doesn't hold any instance data.

I have no idea how to do this, it might even be impossible. Binding two VAOs is not possible(?) Expanding a VAO is not possible either(?)

0xbaadf00d
  • 2,535
  • 2
  • 24
  • 46
  • What is the problem here? You have one buffer with the vertex data, one buffer with the instance data and then you add both to the VAO. – dari Sep 17 '15 at 16:24
  • I don't think I can buffer them first, then bind to VAO? I need to first bind the VAO and then generate the buffers and then send the data. What i'd like to have is a buffer with mesh data, which I can then combine with instance data and render. I can't figure out a way to do this without buffering the data when i'm about to render, which seems like a bad idea to me – 0xbaadf00d Sep 17 '15 at 16:30
  • No, you can create and fill the buffers before even having a VAO. – dari Sep 17 '15 at 16:37
  • That I did not know, all the examples do it in that order. Can you point me to any example/tutorial? – 0xbaadf00d Sep 17 '15 at 16:39
  • 1
    I think you may be confusing vertex arrays with vertex array objects (VAO's). Vertex arrays are deprecated and should not be used, instead use VBO's. Then use one VAO, as dari mentioned. Essentially, vertex arrays and VBO's are buffers you put your data in, but VAO's only remember which buffers you bind and what parameters you set, not the actual data. It's a convenience tool, and using them is usually optional. – Henk De Boer Sep 17 '15 at 17:41
  • @HenkDeBoer Ah, it seems I don't undestand VAOs at all. So, better go learn me some more then :) – 0xbaadf00d Sep 17 '15 at 17:51
  • Is glDrawElementsInstancedBaseVertex something i should not use as well? – 0xbaadf00d Sep 17 '15 at 17:54
  • No thats fine, just google it and check the docs, if it's listed under the OpenGL 4 specification, its fine. If you want you can request and opengl context which will not contain any "old" functions, so you won't use them by accident. It's called a core context. Also, although these functions are old (and sometimes teach bad code practice), they are going to be around for a while and you can rely on them working locally. See them as a learning tool, just dont build long term code with them. – Henk De Boer Sep 17 '15 at 17:59
  • So, If i understand correctly. VAO remembers what glEnableVertexAttribArray calls i make, when it was bound? And when I bind it, it's the same as calling the glEnable* again? So if i want to add instance data, I could just buffer the data and call glEnable* for the array? I don't need to "bind" the VBO in any way to the VAO to be able to use it in rendering? – 0xbaadf00d Sep 17 '15 at 18:12
  • 1
    I wrote an answer here some time ago that tries to explain the basics of VAOs, and what state they contain: http://stackoverflow.com/questions/26552642/when-is-what-bound-to-a-vao/26559063#26559063. At least the first few paragraphs, up to the specific sub-questions, should be generic. A partly similar answer is here: http://stackoverflow.com/questions/26228498/glvertexattribpointer-overwrite/26229019#26229019. – Reto Koradi Sep 18 '15 at 04:15
  • @RetoKoradi Thanks, i played around with an example yesterday and got my setup working. There is no answer so I can't accept one. – 0xbaadf00d Sep 18 '15 at 10:28

0 Answers0