0

I'm writing a small obj viewer using OpenGL. I was wondering if there's some clever way to handle vertices with multiple UVs without having to duplicate the other attributes in the VBO.

I've done some research and even here on stack overflow people seem to suggest the only way is to duplicate them. It seems to me this would imply a mandatory waste of memory everytime, although easy to handle.

Is there another way to handle multiple UVs per vertex other than just create a different vertex in the VBO?

I was also thinking of adding all the uvs in the VBO per given vertex but I'm not really sure how to use this given that in the Vertex Shader or Fragment shader I wouldn't really be able to index a specific UV.

(you can assume OpenGL 3.0 or 4.0)

user8469759
  • 2,522
  • 6
  • 26
  • 50
  • *"[...] although easy to handle."* - Why do you think this is "easy to handle"? – Rabbid76 Mar 14 '21 at 22:16
  • 2
    Related: [Rendering meshes with multiple indices](https://stackoverflow.com/questions/11148567/rendering-meshes-with-multiple-indices) and [Why does OpenGL not support multiple index buffering?](https://stackoverflow.com/questions/44046585/why-does-opengl-not-support-multiple-index-buffering). – Rabbid76 Mar 14 '21 at 22:18
  • 1
    @Rabbid76 Well because populating the VBO it's easy and straightforward. You iterate through all the triangles (in the .obj) and for each vertex I create and entry in the VBO which has coordinates (repeated) normals (repeated eventually) and uvs. The IBO is populated accordingly. – user8469759 Mar 14 '21 at 22:19
  • So you mean it would be easy to handle for you. But what about the GPU? – Rabbid76 Mar 14 '21 at 22:21
  • Yes, that's what I mean. But I think the memory problem I mentioned is also GPU related really. Though you might argue the cost of moving memory around and indirect indexing might be worse. Also the links you provided seem to confirm my understanding, I simply need to accept data must be repeated apparently. – user8469759 Mar 14 '21 at 22:23
  • @user8469759: "*handle vertices with multiple UVs*" A vertex can have as many "UVs" as you want (within the attribute limits of the hardware). I'm not sure what the problem is. Are you talking about when one *position* is used multiple times for different vertices with different UVs? Remember: a "vertex" is a collection of attributes; a "position" is a specific attribute. – Nicol Bolas Mar 14 '21 at 22:47
  • 1
    I'm talking about a vertex belonging to different triangles, each triangle might have a different "island" in uv space. Adjacent triangles vertex might have the same position, but different uvs. Now as I mentioned I could design my VBO to host a single position together with all the UVS of the triangles sharing that position in one of their vertices. However when I'm in fragment shader I have no way to distinguish which triangle is being rasterized, therefore I wouldn't really know which UV I should use to sample the texture. – user8469759 Mar 14 '21 at 23:02
  • I'm realizing my use of the word "vertex" is actually referring to different things, let me know what it's confusing and I'll try to clarify (maybe via expanding my question). – user8469759 Mar 14 '21 at 23:03

0 Answers0