Original Post
Hello,
I'm trying to use VBOs but realized the theory is not quite clear to me. I was hoping somebody could answer a few basic questions. As an example, suppose I want to draw 2 triangles: on the first I want to enable the coordinates and the colors; on the second I want to enable the coordinates, textures, and normals.
My thought was to pack everything into a single buffer large enough to contain all data. The coordinates, texture coordinates, normals, and colors are all in separate arrays. Since the two triangles do not use the same information, my coordinates array contains xyz for 6 points; my colors array contains rgb for 3 points; the normals array also contains information for 3 points; and the texture coordinates also contains information for 3 points.
The "stride" in all calls to glXXXPointer is set to zero as coordinates, normals, etc. are all packed.
1) Do I need to assume that all vertices share all attributes - i.e., coordinates, normals, textures, etc, as far a copying data to the VBO with, say, glBufferSubData?
2) My plan is to call glDrawArrays twice: once for first triangle and once for the second triangle. But the glDrawArrays function requires a starting point. Does this mean I have to "make room" in the VBO for coordinates, colors, normals, and textures for ALL points in the model, even if they won't ever be referenced (because, say, texcoord won't be enabled when drawing the first triangle)?
3) Of course, my model is much more complicated than just 2 triangles - I usually have on the order of about 1M geometric primitives, with all types of combinations for normals, textures, colors, etc. Sometimes some are on, and sometimes they are off. I would like to copy all my data to the VBO so I can quickly rotate the model that is already in the GPU. I'm just not clear whether I have to make a worst-case scenario assumption that all vertices always have all attributes.
4) I could also have separate buffers for each attribute: one buffer for coordinates; one for textures; one for color, etc. But if I have textures on a single triangle out of 1M triangles, would this mean I have to assume that all triangles have textures so that glDrawArrays can find the texture properly?
I hope I made my problem clear. If somebody could clear this for me I would appreciate it.
Thanks!
I'm trying to use VBOs but realized the theory is not quite clear to me. I was hoping somebody could answer a few basic questions. As an example, suppose I want to draw 2 triangles: on the first I want to enable the coordinates and the colors; on the second I want to enable the coordinates, textures, and normals.
My thought was to pack everything into a single buffer large enough to contain all data. The coordinates, texture coordinates, normals, and colors are all in separate arrays. Since the two triangles do not use the same information, my coordinates array contains xyz for 6 points; my colors array contains rgb for 3 points; the normals array also contains information for 3 points; and the texture coordinates also contains information for 3 points.
The "stride" in all calls to glXXXPointer is set to zero as coordinates, normals, etc. are all packed.
1) Do I need to assume that all vertices share all attributes - i.e., coordinates, normals, textures, etc, as far a copying data to the VBO with, say, glBufferSubData?
2) My plan is to call glDrawArrays twice: once for first triangle and once for the second triangle. But the glDrawArrays function requires a starting point. Does this mean I have to "make room" in the VBO for coordinates, colors, normals, and textures for ALL points in the model, even if they won't ever be referenced (because, say, texcoord won't be enabled when drawing the first triangle)?
3) Of course, my model is much more complicated than just 2 triangles - I usually have on the order of about 1M geometric primitives, with all types of combinations for normals, textures, colors, etc. Sometimes some are on, and sometimes they are off. I would like to copy all my data to the VBO so I can quickly rotate the model that is already in the GPU. I'm just not clear whether I have to make a worst-case scenario assumption that all vertices always have all attributes.
4) I could also have separate buffers for each attribute: one buffer for coordinates; one for textures; one for color, etc. But if I have textures on a single triangle out of 1M triangles, would this mean I have to assume that all triangles have textures so that glDrawArrays can find the texture properly?
I hope I made my problem clear. If somebody could clear this for me I would appreciate it.
Thanks!