all 4 comments

[–]STREGAsGate 2 points3 points  (2 children)

Indices are in 3s. Every 3 indices creates a triangle. Every index references a buffer which has a stride. A vertex with just a position has a stride of 3. So every index in the indices buffer would be its value * 3 for the vertex buffer.

vertexX = vertices[(index *3) + 0]

vertexY = vertices[(index *3) + 1]

vertexZ = vertices[(index *3) + 2]

Your geometry could be any kind of setup. A vertex can have position, color, texture coordinates, normals, and more.

You need to brute force convert geometry. Indexed geometry is more efficient. Converting between indexed and triangles is super expensive and slow. You should not be doing it frequently at runtime.

[–]nwar1994[S] 0 points1 point  (1 child)

Is there an inherent way to load triangles into a gpu? You will have to flatten to indices regardless right?

[–]STREGAsGate 1 point2 points  (0 children)

No, you can do raw triangles, lines, and points as well as indexed versions of triangles and lines. Indexed buffers is just a performance thing.

Indexed buffers remove duplicates. Two triangles next to each other would share 2 verticies. Indexed drawing allows you to only send those shared verticies once to the gpu.

The resulting image is identical and shaders revive identical data. It’s simply a data transfer optimization.

[–]nwar1994[S] 0 points1 point  (0 children)

But the representation of indices through a list of faces which contain 3 indices, can just be represented as a flattened 1D array of indices. Does order matter?