VBOs, VertexArrays and good way to store data...

Started by
10 comments, last by BladeWise 18 years, 10 months ago
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...
Advertisement
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
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out his new home he rounded a corner and saw someone in Marine Dress Blues. He ran back to St. Peter and yelled "You lied to me! There are Marines in heaven!" St. Peter said "Who him? That's just God. He wishes he were a Marine."
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?
Why wouldntyou just use indices?

cheers
-Dan
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out his new home he rounded a corner and saw someone in Marine Dress Blues. He ran back to St. Peter and yelled "You lied to me! There are Marines in heaven!" St. Peter said "Who him? That's just God. He wishes he were a Marine."
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... :(
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?
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.
Thnx for the answer... this makes my worst fears come true ^^
but dublicating vertex data doesn't couse any problems or am I missing something?

This topic is closed to new replies.

Advertisement