Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top