0

I'm using various 'nested' contexts in my application (for shader and geometry sharing), so I cannot use VAOs as they cannot be shared across contexts.

My mesh data is stored in one VBO as a 'pool' of unique vertices, and in another VBO I store the indices that make up the faces. I'm currently using this successfully for wireframe rendering in my CAD app, but I would like to add a flat shaded mode - and for that I need face normals.

If I needed vertex normals, I would just append the data to the vertex position data, but I can't do that here because a vertex would have a different face normal depending on which face it belonged to is being rendered. Ideally I would like to create another VBO pair holding my face normals and indices, however I can't bind two VBOs to the same target without a VAO - even though they're used in different attributes.

I appreciate that the normal route is to use a VAO which does let you assign multiple VBOs to the same target, but I can't use them because my geometry context is shared and VAOs are not. Are there any alternative solutions to this issue?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
cmannett85
  • 21,725
  • 8
  • 76
  • 119

1 Answers1

4

If I needed vertex normals, I would just append the data to the vertex position data, but I can't do that here because a vertex would have a different face normal depending on which face it belonged to is being rendered. Ideally I would like to create another VBO pair holding my face normals and indices, however I can't bind two VBOs to the same target without a VAO - even though they're used in different attributes.

Your problem has nothing to do with VAOs or buffer objects. VAOs do not allow you to have multiple index lists. They do not allow you to have "face normals".

A vertex array objects is nothing more than a container that stores vertex attribute bindings. They do not enable you to do anything you couldn't do without them; there's simply a convenient way to change all attribute bindings.

You need to break your vertex positions up into different faces. So you need to duplicate position values, so that each unique position/normal pair is properly unique. VAOs don't get around this limitation.

FYI: the reason VAOs aren't shared is because they're too simple to bother sharing. You can set the same VAO up in two different contexts easily enough. Just create a VAO in the context you want to use it in, and do what you would normally do to set it up. It's just a simple state object; it doesn't really contain anything.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • Thank you for your quick answer. I suspected this might be the case, but what threw me was a section in the OpenGL Superbible 5ed `"a record of the currently bound buffer is made in the current VAO and used for that attribute. That is, not only does glVertexAttribPointer tell OpenGL the offset into the buffer that a vertex attribute's can be found, but it also tells OpenGL which buffer contains the data. It is therefore possible to use multiple buffers - one for each attribute - simultaneously..."`. This confused me because binding a buffer to a bound target, unbinds the old buffer. – cmannett85 Dec 10 '11 at 22:15
  • @cbamber85: That's true. But the fact that you're using different buffer objects does *not* mean that you're using different indices to access them. There's no functional difference between using the same buffer for multiple attributes and using multiple buffers for multiple attributes. The only difference is where the attribute data comes from. – Nicol Bolas Dec 10 '11 at 22:17
  • Ah, that makes sense, and completely ties up with what I'm seeing. – cmannett85 Dec 10 '11 at 22:23