Main Menu

Indices

Started by jeussa, November 26, 2015, 16:09:51

Previous topic - Next topic

jeussa

Hi dere LWJGL community,

I'm sort of coping with a small issue at the moment. I have created a small program which uses data from an OBJ file to render in a 3D environment. When rendering an object I have 3 VBO's (one for geometric vectors, then texture vectors and finally normal vectors). However each one of these lists of vectors have their own index lists. How would I make it so I can use different indices for each VBO?

Thanks for the time!

Kai

OpenGL itself does not support this with the single ELEMENTS_BUFFER. It will always index into all active vertex attribute sources (i.e. VBOs) using the same index.
And I would also not advise you to handcode manually indexing into a shader storage buffer object by gl_VertexID.
I would simply not use indexed rendering with a Wavefront OBJ model and just duplicate each triple (position, normal, texcoord) when reading the faces ('f' elements) of the model and insert those triples into their respective VBOs.
This will also likely be faster than any manual indexing due to coalesced accesses to global memory.

Neoptolemus

The way I get around this is to create a distinct list of vertex definitions (position/UV/Normal) and then load those into the VBOS,  then generate my own indices by mapping the vertex definitions in the OBJ file against the distinct list. So for example:

f 12/34/56 78/910/1112 1314/1516/1718
f 12/34/56 1314/1516/1718 1920/2122/2324


The distinct list is:

1: 12/34/56
2: 78/910/1112
3: 1314/1516/1718
4: 1920/2122/2324

So I upload the positions at 12, 78, 1314, 1920 into the position buffer in that order, the UVs at 34, 910, 1516, 2122 into the UV buffer in the same order and so on.

Then I regenerate the indices as 1, 2, 3, 1, 3, 4.

That way you can still use drawelements and you don't have to duplicate vertex information.

Hope this helps!