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 7 of 7

Thread: glDrawArrays vs glDrawElements

  1. #1
    Junior Member Regular Contributor
    Join Date
    Jun 2000
    Location
    Portugal
    Posts
    223

    glDrawArrays vs glDrawElements

    here's the deal: I'm drawing a mesh 20*20=400 quads total. To improve performance I choosed to use triangles and vertex arrays, so my vertex array is 400*6=2400 (6 because 2 triangles in a square). This is what I do:

    GLfloat mesh[4200][3];
    //fill up array
    glVertexPointer(3, GL_FLOAT, 0, mesh);
    glDrawArrays(GL_TRIANGLES,0,2400);

    How can I use glDrawElements, is it faster? What's the diference?

  2. #2
    Junior Member Regular Contributor
    Join Date
    Apr 2000
    Posts
    116

    Re: glDrawArrays vs glDrawElements

    From my understanding I don't think you'd get any performance increase by using glDrawElements. I think it does the same thing as glDrawArrays just in a different input format.

    I do have a few related questions though.

    How come glDrawElements only alows types of GL_UNSIGNED_INT, GL_UNSIGNED_SHORT, and GL_UNSIGNED_INT? What if I'm using floats?

    Also using glDrawElements or glDrawArrays I have the following problem:
    - I have to draw my polygons in a particular order for transparency reasons
    - Using this order my texture for each polygon switches almost every time
    So is there a way to sort of call a glBind automatically depending on which element in my array I'm at. (I bet there isn't but opengl has supprised me before.)

  3. #3
    Junior Member Regular Contributor
    Join Date
    Jun 2000
    Location
    Portugal
    Posts
    223

    Re: glDrawArrays vs glDrawElements

    wow, you read my mind!!!!
    I don't know how can I use a glBind inside a glDrawArrays or glDrawElements. If you get something concerning this matter let me know...

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jun 2000
    Location
    Shreveport, LA, USA
    Posts
    1,757

    Re: glDrawArrays vs glDrawElements

    Nope, glDrawElements will not magically do a glBind for you. For transparent sorted polygons you must call glBind every time a new texture is needed. From my experience, a call to glBind is not needed for every transparent polygon. Typically, transparent polygons that are close to one another, also use the same texture. So I group my triangles after sorting them. And then you have to consider, how many transparent polygons are there in a typical scene? For example, in a Quake 3 map, there usually is not that many in any given scene. In fact most of the transparent polygons are temporary entities, and their variety is usually quite limited. One thing you might try with the smaller textures used with transparent polys is to tile them into a single texture and load that into OpenGL, and then use the texture coordinates cleverly to use the tile you need. This approach works very nicely for particle systems with key framed animation. Imagine a particle system of glowing, globuals, flickering with fire as they fly up into the air, and then change to into red glowing beads as they fall down, finally vanishing after a short period of time. Believe me, it is beautiful. And it is all done using just one 256x256 texture (and a lot of polys).

  5. #5
    Junior Member Regular Contributor
    Join Date
    Jun 2000
    Location
    Portugal
    Posts
    223

    Re: glDrawArrays vs glDrawElements

    that's all right folks, but it still doesn't aswer my question: how to use glDrawElements with the problem above?

  6. #6
    Senior Member OpenGL Pro
    Join Date
    Jun 2000
    Location
    Shreveport, LA, USA
    Posts
    1,757

    Re: glDrawArrays vs glDrawElements

    Regarding your question KRONOS, I think you would gain more speed by using an array of triangle strips. In fact glDrawElements should be a little slower than glDrawArrays since the former uses an index array to determine which element to draw where as with the latter, no such indexing is used.

  7. #7
    Junior Member Regular Contributor
    Join Date
    Jun 2000
    Location
    Portugal
    Posts
    223

    Re: glDrawArrays vs glDrawElements

    yes, I know that but then how would I pass from one line to the next (keeping the front face correct) without another call to glDrawElements ?

Posting Permissions

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