Recommended Posts

I've read that texture coordinates are applied on a triangle/face basis. I've been storing them on a polygon mesh basis and referencing them from face indices.

Wouldn't applying texture coordinates per face, create a lot of vertex duplicates? Not only does that increase the size of the file but I would think it decreases rendering effecientcy by supplying vertex duplicates.

The problem with my current setup is, when I actually need seperate uvs or normals, I have to use the polygonmesh itself as a face.

Any advice? I'm hoping the vertex duplicates aren't as bad as they sound.

Share this post

Link to post

Share on other sites

I've been storing them on a polygon mesh basis and referencing them from face indices.

I'm not familiar with your terminology, or what you mean to use a 'polygonmesh itself as a face'

Typically you store UV coordinates per vertex, and face indices point to unified vertices (position,normal,texcoord). Data duplication is required anytime any part of the unified vertex varies to use hardware buffers on GPU.

Share this post

Link to post

Share on other sites

In OpenGL, normals, texture coordinates, color, etc. are all specified per-vertex--the intermediate calls simply change OpenGL's state. If you want to specify per-face texture coordinates, OpenGL will simply specify the same texture coordinate at all three vertices.

In code:

glTexCoord2d(1.0,0.0); glVertex3d(0.0,0.0,0.0); //Sets the texcoords to (1,0), then issues vertex with the current texture coordinate (1,0)glTexCoord2d(1.0,0.0); glVertex3d(1.0,0.0,0.0); //Sets the texcoords to (1,0), then issues vertex with the current texture coordinate (1,0)glTexCoord2d(1.0,0.0); glVertex3d(1.0,1.0,0.0); //Sets the texcoords to (1,0), then issues vertex with the current texture coordinate (1,0)

Is exactly the same as:

glTexCoord2d(1.0,0.0); //Sets texcoords to (1,0)glVertex3d(0.0,0.0,0.0); //Issues vertex with the current texture coordinate (which is (1,0))glVertex3d(1.0,0.0,0.0); //Issues vertex with the current texture coordinate (which is (1,0))glVertex3d(1.0,1.0,0.0); //Issues vertex with the current texture coordinate (which is (1,0))

In both cases, the texture coordinate (1,0) will be applied for each vertex--each vertex storing its own copy of (1,0), which was the current state of OpenGL at the time.

You can make your own optimized model loader that only changes the OpenGL state when necessary (i.e., the second block of code), but generally, each of the parameters you're using are specified per-vertex.

Share this post

Link to post

Share on other sites

There seems to be a consensus that uvs are stored per vertex. My source is actually wikipedia so it's definitely possible the article could be wrong in a general sense.

Quote:

UV coordinates are applied per face[2], not per vertex.

Quote:

In OpenGL, normals, texture coordinates, color, etc. are all specified per-vertex--the intermediate calls simply change OpenGL's state. If you want to specify per-face texture coordinates, OpenGL will simply specify the same texture coordinate at all three vertices.

Do all graphics APIs internally do that? I'm using XNA which is probably the same for DirectX. If that's the case, my point would be more or less moot.