Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Question about glDrawElements vs glDrawArrays

  1. #1
    Intern Contributor
    Join Date
    Sep 2013
    Posts
    81

    Question about glDrawElements vs glDrawArrays

    Hi.
    I am drawing lots of rectangles in a 2D application. For each rectangle I am drawing 2 triangles.
    Right now I am using a VBO with an Array-Buffer and an Element-Array-Buffer in combination with glDrawElements.
    However, I dont use many shared vertices. Each rectangle has 4 vertices and 6 indices, so only 2 vertices are shared per 2 triangles.
    So I was thinking that maybe using glDrawArrays with GL_QUADS instead of GL_TRIANGLES would be a better idea.

    My benchmarks have shown absolutely no difference in terms of performance with either of both. However, I am not quite sure how this would go on other kinds of hardware, especially laptops with limited graphics capabilities.

    Thank you very very much for the help. I really appreciate it.

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,194
    Quote Originally Posted by Cornix View Post
    Hi.
    I am drawing lots of rectangles in a 2D application. ... So I was thinking that maybe using glDrawArrays with GL_QUADS instead of GL_TRIANGLES would be a better idea.
    Are these quads part of a connected grid, or are they isolated quads?

    If connected, then properly optimized triangles would win. If they are isolated quads, there's not much to be gained either way.

    My benchmarks have shown absolutely no difference in terms of performance with either of both.
    If you are bottlenecked on something else, that would be expected and would invalidate the conclusion you're trying to make.

  3. #3
    Intern Contributor
    Join Date
    Sep 2013
    Posts
    81
    The quads are not connected at all. They are just batched in one big array-buffer.

    I am just not sure if it would be a problem to use glDrawArrays with GL_QUADS instead of drawing triangles. Because with glDrawElements I can reuse 2 vertices for each quad making it 4 vertices for 2 triangles instead of 6 vertices. With glDrawArrays this wouldnt work that way. Since I dont want to change the code with which I upload the vertex-data I would use glDrawArrays with GL_QUADS instead.

  4. #4
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    490
    The main issue with GL_QUADS is that it's deprecated, i.e. it doesn't exist in 3.x core profile or OpenGL ES. In practice, each quad will be split into two triangles, but it's undefined as to how (i.e. which diagonal is used for the split). Although this probably doesn't matter for 2D rectangles, this means that the result of rendering quads is undefined unless the quads are planar and the mapping of attribute values to the plane is affine.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •