0

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?

Sync it
  • 1,180
  • 2
  • 11
  • 29
  • 1
    If you are using a compatibility profile [OpenGL Context](https://www.khronos.org/opengl/wiki/OpenGL_Context) you can continue to use QUADS like any other deprecated feature (e.g. Immediate Mode) – Rabbid76 Jan 02 '21 at 08:02
  • But is it a good practice/good for performance? Should I try to replace it with gl_triangle strips as a good measure or are there no performance implications? – Sync it Jan 02 '21 at 08:19
  • 1
    Since it it deprecated, it is not a good practice. I can't say anything about the performance. The performance is related to the hardware and driver. You have to measure it. – Rabbid76 Jan 02 '21 at 08:20
  • I see but why was it deprecated if it works?Is there an alternative besides strips? – Sync it Jan 02 '21 at 08:21
  • 1
    [What is so bad about GL_QUADS?](https://stackoverflow.com/questions/6644099/what-is-so-bad-about-gl-quads?rq=1) – Rabbid76 Jan 02 '21 at 08:25
  • Do the same problems occur with triangle strips? – Sync it Jan 02 '21 at 09:27
  • No. `GL_TRIANGLE_STRIP` is a [triangle primitive](https://www.khronos.org/opengl/wiki/Primitive#Triangle_primitives) type. – Rabbid76 Jan 02 '21 at 09:29
  • Any suggestions on how to draw disconnected quads using triangle strips? – Sync it Jan 02 '21 at 11:19
  • 1
    You can't. Use triangles and indices. I've asked something similar: [How to convert large arrays of quad primitives to triangle primitives?](https://stackoverflow.com/questions/49137481/how-to-convert-large-arrays-of-quad-primitives-to-triangle-primitives) – Rabbid76 Jan 02 '21 at 11:21
  • @Rabbid76 he is using a while loop to render which is the same as my suggested answer towards the end of my question. Isn't that terrible for large meshes which have 1000's of quads cause you use that many draw calls? – Sync it Jan 02 '21 at 11:37
  • Use a loop to create an index buffer. This only needs to be done once. The indices are always the same: `0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, ...`. It just depends on the length. However, the index buffer can have more indexes than corner vertices. – Rabbid76 Jan 02 '21 at 11:39
  • Well it's good to know i have options and since quads still continue to work for me i think i will stick to that. Question closed – Sync it Jan 02 '21 at 11:44

1 Answers1

1

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.

Andreas
  • 5,086
  • 3
  • 16
  • 36
  • Not bad that actually worked. From the linked answer all i had to do was duplicate the first and last vertex[or in case of indexed geometry their indices] of every face i read from the file and that's it seperate non connected quads drawn with triangle strips. I don't know if i should mark this as the accepted answer because degenarate strips shown up as lines in wire frame mode so it works 50/50?. – Sync it Jan 03 '21 at 09:10
  • I don't know what does the rest of the community think? – Sync it Jan 03 '21 at 09:10
  • @Syncit Wireframe mode is more problematic. Even if using indexed triangle to get rid of the degenerate strips you end up with a diagonal line across each quad which shouldn't be there for wireframed GL_QUADS. Separate GL_LINES with index will look the part, but then you can't rely on `glPolygonMode()` to do the job for you. – Andreas Jan 03 '21 at 11:01
  • Well I guess it can't be helped then ,besides one would use wireframe mode only for modeling not for real world apps anyway and even if i did I will stick to triangles then. Case closed – Sync it Jan 04 '21 at 04:20