VBOs, VertexArrays and good way to store data...
Hi all, my question can sound strange but... what's the best way to store mesh data? I'm not referring to file formats, I'm pretty interested in the inner format... In many posts/lessons/tutorials, I found that a good way is:
1. Store vertices coordinates as a list/array;
2. Store faces as a list/array of vertices IDs;
3. Store vertices normals (or face normals) in a proper array/list;
4. Store vertices/faces colors in a proper array/list.
In this case, anyway, it's not possible to use VertexArrays or VBOs, since in these cases we need full arrays, so we should create the vertices list, reading the faces array and creating a new array filled with vertices informations... or I am wrong?
So, what's the best way, if the goal is developing a Game Engine (which is supposed to use a dynamical geometry... since every frame is a almost different mesh...), to store these data? Storing vertices as a simple buffer of coordinates?
Storing data as I described before (faces as vertices IDs array), is or not a bad idea if we want to use VertexArrays? Maybe I'm a bit confused...
What do you mean "full arrays"? You can do anything with VBOs that you can with vertex arrays. And anything with vertex arrays that you can with immediate mode (abeit you may need to rearrange your data , if for instance, your model is a md2 and is stored all crazy). Getting back to the "full arrays" thing, by that do you mean having like position, normal, color, texture coordinate1, texture coordinate2 ect. Because that can be accomplished with VBOs as well. (Though personally Id reccomend interleaving them anyways, as at one time it was touted as faster, AND its easier to need to just bind one buffer for each type)
hope that helps
-Dan
hope that helps
-Dan
As "full array" I'm referring to the data structure containg all (redoundant) vertices of a mesh... let's say we have a cube... using the suggested arrangement we have:
8 vertices
6 faces (if using QUADS, with 4 vertices for each face)
24 normals
Using VertexArrays, if I'm not wrong, we need to point a buffer containing all vertices ordered as faces, so we have:
24 vertices
NO faces (it's not needed to reconstruct faces)
24 normals
I think I need data contiguous in memory to use
glBindBufferARB(...);
or
glVertexPointer(...);
since both needs a pointer to a memory location... thanks the stride parameter we can use data mixed in some way, but they needs to be periodical in some way... So, my question (re-reading my post I must say I'm not clear about this...) is: to use vertex buffers, I need to repeat vertices of the mesh shared among faces, arranging them in appropriate memory structures?
8 vertices
6 faces (if using QUADS, with 4 vertices for each face)
24 normals
Using VertexArrays, if I'm not wrong, we need to point a buffer containing all vertices ordered as faces, so we have:
24 vertices
NO faces (it's not needed to reconstruct faces)
24 normals
I think I need data contiguous in memory to use
glBindBufferARB(...);
or
glVertexPointer(...);
since both needs a pointer to a memory location... thanks the stride parameter we can use data mixed in some way, but they needs to be periodical in some way... So, my question (re-reading my post I must say I'm not clear about this...) is: to use vertex buffers, I need to repeat vertices of the mesh shared among faces, arranging them in appropriate memory structures?
Are you speaking about using glDrawElements instead of glDrawArrays? Uhmm, I suppose this is what I need... if I'm not wrong, in this way I could store only non-redundant vertices in the array, and then I could specify how faces are built, using indices... but... what about normals/colors/texture coords? What if the same vertex uses a different normal depending on the face is using it? I thought glDrawElements draws data depending on the index, retrieving vertex informations (normal, color, texture coords) from the same index in the correct array... something like this:
passing index array {0,3,7,4} to draw the top face of a cube, will use {0,3,7,4} normals in the current normals array...
drawing next the front face of the cube as {0,1,2,3}, vertex[0] should be the same as before, but normals[0] should be different...
Does anyone has a code snippet, or a link to a tutorial, about using vertex arrays by indices (glDrawElements) with normals?
Maybe I'm getting this in the wrong way, any explanation is welcome... :(
passing index array {0,3,7,4} to draw the top face of a cube, will use {0,3,7,4} normals in the current normals array...
drawing next the front face of the cube as {0,1,2,3}, vertex[0] should be the same as before, but normals[0] should be different...
Does anyone has a code snippet, or a link to a tutorial, about using vertex arrays by indices (glDrawElements) with normals?
Maybe I'm getting this in the wrong way, any explanation is welcome... :(
you can only pass use 1 index for the array. This means that if normals or texture coordinates are different you have to add a new verticle. If you have sharp edges then you have dublicate vertex data. It works quite well for smooth gemetry, where you have only one normal per vertex, however.
So, to preserve sharp edges, the only way is duplicate vertices?
I was looking for a way to store not duplicated data (vertices, normals, colors...), and a face structure to store only indices... so, using vertex arrays, I could point data arrays, specifying only which elements should be taken... is it a bad idea? Or better, is it possible?
I was looking for a way to store not duplicated data (vertices, normals, colors...), and a face structure to store only indices... so, using vertex arrays, I could point data arrays, specifying only which elements should be taken... is it a bad idea? Or better, is it possible?
Wenn you use VA or VBO you can only specify one index array which is used for the vertex, normals, color, etc. array. So, if you want to preserve the sharp edges you have to dublicate vertex data.
you could make multiple normal arrays and use them with the same vertex array, but this can quicly turn complicated.
you could make multiple normal arrays and use them with the same vertex array, but this can quicly turn complicated.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement