PDA

View Full Version : VBO/VertexArrays: The UV coords have to be unique?



Godlike
03-15-2010, 03:27 PM
The most common format of a triangle mesh is to have a vector of vertex coords and one for the vertex indexes. But what happens with the UV coords in the case of VBOs and vertex arrays? Does every vertex has to have a unique UV coord or am I missing something here?

Ehsan Kamrani
03-15-2010, 06:37 PM
If your model has texture, you must specify (s,t ) (or (u,v ) ) as well to render the texture:


glEnableClientState(GL_TEXTURE_COORD_ARRAY);
BindVBO(GL_ARRAY_BUFFER, m_texCoordVboId );
glTexCoordPointer( 2, GL_FLOAT, 0, NULL);

If you don't specify the texture coordinates, your code won't have any idea about the texture coordinates and will not draw the texture(s).

Dark Photon
03-15-2010, 08:03 PM
The most common format of a triangle mesh is to have a vector of vertex coords and one for the vertex indexes. But what happens with the UV coords in the case of VBOs and vertex arrays? Does every vertex has to have a unique UV coord or am I missing something here?
No, your UV coords (e.g. TEXCOORD0, etc.) don't have to be unique. You can assign them all the same value if you want. It's whatever your shaders will find useful. It's just "shader input data".

And this has nothing to do with whether you use VBOs (server arrays), client arrays, display lists, or immediate mode. It doesn't matter to any of them. It's an independent issue.

Godlike
03-16-2010, 03:49 AM
I know its shader data but since I have vert indices I render using glDrawElements:

mesh->vbos.vertIndices.bind(); // Bind VBO
glDrawElements( GL_TRIANGLES, mesh->vertIndices.size(), GL_UNSIGNED_SHORT, 0 );

With this way (I think) that every index points to a unique vertex pos, unique vertex normal and unique vertex coord. If I have a mesh with N number of vertices I also have a N number of vertex normals and N number of tex coords so that the vertex indices act like a lookup table.

Im I right? What am I missing here?

Dark Photon
03-16-2010, 05:59 PM
I know its shader data but since I have vert indices I render using glDrawElements:

mesh->vbos.vertIndices.bind(); // Bind VBO
glDrawElements( GL_TRIANGLES, mesh->vertIndices.size(), GL_UNSIGNED_SHORT, 0 );

With this way (I think) that every index points to a unique vertex pos, unique vertex normal and unique vertex coord.
The unique is the point of confusion. Unique "offset/address" in the buffer, but not necessary unique "contents/data". For instance, you can have the vertex position at index 0 be 1,2,3 and the vertex position at index 1 be 1,2,3 as well. You might do this for instance if this vertex is on a hard corner edge where you need different normals, one for each face.

Similarly, you can (and frequently do) repeat indices in the index buffer (e.g. 0,1,2,2,1,3,...).


If I have a mesh with N number of vertices I also have a N number of vertex normals and N number of tex coords so that the vertex indices act like a lookup table.
Exactly.