Vertices with multiple UV coordinates and glDrawElements()?

Started by
4 comments, last by Matias Goldberg 9 years, 7 months ago

This is essentially the same problem as the one described in this thread, however, seeing as the thread was started in 2003, things may have changed by now.

Basically, the problem is that my model can have multiple UV coordinates for vertices which are used by more than one face.

I'm using glDrawElements, but I'd like to avoid having to duplicate my vertices, just to fill it up to correlate with my UV coordinates.

Is there a way to use a separate index buffer for the UV coordinates and use that in conjunction with the main index buffer for the vertices?

Or is there an alternative altogether?

Advertisement

Short answer; no, these things have not changed since 2003.

The thing is, a vertex is defined as everything that defines it, not just its position. The position attribute of a vertex, and the vertex itself, are often used for the same thing. Sometimes that's correct, but in the context of OpenGL, that is not correct. The position attribute of a vertex which many faces may share all over the model is just that, the position attribute of a greater atomic entity.

When you say that you have two identical vertices with the same position but different color, you really have two completely different vertices. So you're not duplicating any vertices, because the two vertices are different.

Thanks.

So in essence, vertex attributes cannot be defined independently and if one vertex has similar attributes as another one, those attributes will have to be duplicated?

Correct, and correct. Although, I don't look at it as duplicating those attributes because they happen to have the same value. They are only a part of a whole vertex, and only whole vertices can be subject to duplication.

It's worth adding here that the natural impulse to "not waste memory" by eliminating this kind of duplication can sometimes lead to worse performance. Memory isn't the only arbiter of performance, and sometimes choosing to burn the extra memory in exchange for a more sequential, more cache-friendly layout that's in a format the GPU can work with more easily will give significantly higher performance gains than anything that could be theoretically obtained by saving memory.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

Polycount vs Vertex count: a cube can be made with 36 vertices, 24 or 8. (particularly see the sections "Common misconception: Why is the GPU so dumb?" and "This is going to change in the future, right?")

This topic is closed to new replies.

Advertisement