OpenGL ES: number of vertices for textures
Say we want to rende开发者_开发技巧r a cube. To draw a geometry we need only 8 vertices. Is it true that in case we need to map textures we need 24 vertices, i.e. we must submit redundant vertices?
Thanx
Since these vertices have different properties they are not the same. So yes, some data may be redundant but not all of it. Normally indexed geometry could be used when vertices are shared between faces, but in this case they are not really shared.
OpenGL provides vertex array functionality which could be used to separate bits of vertex data into independent chunks. Let's say you can have coordinates in one consecutive array, colors in another and texture coordinates and in the third. Vertex data doesn't have to be interleaved. See glVertexPointer
, glColorPointer
, glTexCoordPointer
and etc.
Using vertex arrays you could save some memory by sharing some of the vertex data, but that would require to make many draw calls and would not be worth it for this simple case of a cube. This article could be quite useful, check it out.
I provide code for an indexed, textured cube for the iPhone here, if you'd like to see an example of this in action. Even if you're not on the iPhone, it might help illustrate how indices can reduce geometry size for an object like this. The OpenGL ES portions of the code should translate well to other platforms.
Indices can prevent the upload of redundant geometry (the size of which can be a limiting factor on mobile GPUs), and GPUs like the ones in the iOS devices are optimized for indexed triangle strips. I've observed some significant performance wins when using indices to shrink the size of my geometry.
精彩评论