openglquadgl-triangle-strip

Opengl : Can we still use GL_QUADS?


I am loading models from obj, colladae files where individual faces of the mesh are not triangulated if all the faces are perfect quads when exporting to save memory.

Now I know this won't work for most models but for some meshes say a cube where some amount of duplication can be avoided along each face I want to make it work.

I have 2 options using triangle strips or gl_quads.

The problem with triangle strips is that neighbouring faces are connected so it is impossible to have some gap between them,even for a simple cube the output looks correct on the outside but when I go inside the cube even with back face culling enabled I see some stray triangles connecting the front and back of the cube and basically it's a whole jumbled mess.

But with gl_quads everything works correctly but the docs say that quads is deprecated in 3.1 [even though I can still use it gl 4.0] so my question is

Can I continue using gl_quads for loading meshes from files without running into problems in the future or how can I replace it with triangle strips without the whole connectivity issue?.

One solution I found was to issue a draw call for every 4 vertices in a for loop but this is terrible for performance for an huge mesh.

Any suggestions?


Solution

  • Can we still use GL_QUADS?

    Yes, if using a compatibility profile OpenGL context.

    Can I continue using gl_quads for loading meshes from files without running into problems in the future...?

    Platforms may choose not to implement the compatibility profile. Most desktop platforms do and have done so since forever. Would surprise me if existing implementations decided to drop it.

    ...or how can I replace it with triangle strips without the whole connectivity issue?

    One way to render disconnected quads (or triangle strips in general) is to draw two vertices in the same point and then move to where the next strip should continue, see this question.

    The simpler way is to generate a sequence of indices like [1 2 3, 1 3 4, 5 6 7, 5 7 8, ...] and render the mesh of quads using those indices.