Problem
When using a vertex buffer objects to draw textured primitives, we have to define a separate buffer to store a list of texture coordinates at each vertex. This texture coordinate array has to map to each vertex in the VBO, thus, we need a large array if we are drawing many primitives.
However, if all primitives have the same texture coordinates, it is a waste to repeat the coordinates for each primitive that will be drawn with glDraw* call.
Example
I have a large number of textured quads that need to be drawn. The quads share the same texture. All vertices are put in a VBO and a large texture coordinate array is created. The textured quads are drawn with a call to glDrawArrays.
4----3 8----7
| /| | /|
| / | | / |
| / | | / |
|/ | |/ |
1----2 5----6
vertex buffer: { 1, 2, 3, 4, 5, 6, 7, 8 }
Texture coordinate array: { 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1 }
<-------------------->
coordinates repeated
for second quad
The texture coordinate array repeats every 4 vertices. This buffer has to be recreated every time a batch of quads has to be drawn as we do not know the number of quads beforehand. The repeating texture coordinates also waste memory.
Question
Is there a way to remove the repetition in texture coordinate arrays when the primitives to be drawn have all the same texture coordinates?