Search code examples
openglgpuwireframe

How does quads get rendered as lines in wireframe mode?


People have been telling me that "GPU renders triangles only".

But how do you explain GPU rendering a quad with 4 lines only in the wireframe mode, shouldnt it be rendering it with 5 lines since GPU cannot understand quads ?

On the other hand, how can i emulate quads in the future where GL_QUADS is banned ? do i need a shader for it, do i need to generate new array of lines for each object and i cant just simply switch from GL_FILL to GL_LINE ?


Solution

  • Lines are something different than filled primitives. When switching to glPolygonMode(…, GL_LINE) whenever a filled primitive is started (GL_TRIANGLES, GL_QUADS), OpenGL won't sent commands for filled primitives, but lines between the vertices of the filled primitive. So GL_TRIANGLES translates to tupled of 3 GL_LINES, GL_QUADS translates to tuples of 4 GL_LINES. GL_POLYGON is translated to a GL_LINE_LOOP. Of course those translations don't happen in terms of OpenGL, but the OpenGL driver will send commands to the GPU that are equivalent to what would have been sent; also there are some subtle differences between GL_LINE polygon mode and sending actual lines, most notably the evaluation of the edge flag.