Jump to content

  • Log In with Google      Sign In   
  • Create Account


drawElements vs drawArrays


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 Darkbouncer4689   Members   -  Reputation: 110

Like
0Likes
Like

Posted 13 June 2011 - 06:25 AM

So I was checking out c3dl and they exclusively use drawArrays in their engine. Until now I had been using drawElements and now I am questioning which is the better choice.

With drawArrays I would think that you're vertex/normal/texcoord buffers are going to be larger since you cant index into them and thus consume more memory. However with this you don't have to store an indices buffer at all which saves memory, where as with drawElements you have to store and bind an indices buffer everytime.

For example:
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, getIndexBuffer());
could be removed from the render calls all together when using drawArrays over drawElements. It may seem like a negligable difference but if you are drawing 50 objects 60 times a second thats 3000 bind and accessor calls saved per second.

On the otherhand if you're buffers have a lot of repeated data in them you would save memory with drawElements, as well as have a much better cache hit/miss ratio. The linear pattern of drawArrays wouldn't give you any extra cache hits.

I hope this isn't too advanced.

Could anyone share what they think is the most efficient/preferred format and for what reasons?

Thanks!



Sponsor:

#2 Brother Bob   Moderators   -  Reputation: 7904

Like
1Likes
Like

Posted 13 June 2011 - 06:54 AM

You can't compare them like that. You have already provided cases where both are more efficient than the other, so you have already, yourself, argued why one of them cannot be universally better than the other. It is entirely situational which one is better for a particular case, and even depends on other factors than the number of binds and the size of the arrays.

#3 Darkbouncer4689   Members   -  Reputation: 110

Like
0Likes
Like

Posted 13 June 2011 - 07:14 AM

Agreed Bob.

As I'm reading up more on gpu caches I am starting to lean toward drawElements being the better choice for most situations. I'm thinking (and feel free to disagree) that the only time one would want to use drawArrays would be when drawing strips since there will be hardly any repeated data. Is that the general rule?

#4 Darkbouncer4689   Members   -  Reputation: 110

Like
0Likes
Like

Posted 13 June 2011 - 07:15 AM

It is entirely situational which one is better for a particular case, and even depends on other factors than the number of binds and the size of the arrays.

Could you provide some more information on this please? Thanks =)

#5 Brother Bob   Moderators   -  Reputation: 7904

Like
1Likes
Like

Posted 13 June 2011 - 08:01 AM

I'm thinking (and feel free to disagree) that the only time one would want to use drawArrays would be when drawing strips since there will be hardly any repeated data. Is that the general rule?

I disagree that it is the only time.

It is entirely situational which one is better for a particular case, and even depends on other factors than the number of binds and the size of the arrays.

Could you provide some more information on this please? Thanks =)

It all comes down to particular setups. Optimizing these things, from a theoretical side so to say, is not my strong side, but there are people around here that know this very well. There are always trade-offs between various parameters. One solution may improve performance at the cost of doubling the number of buffer binds; but if you're not bind-performance bound, then binding more buffers may not be a problem. If you're not vertex processing-performance bound, then using index arrays to save vertex processing is not going to help. If you're vertex processing-performance bound, then index arrays may help, as long as you don't start binding too many buffers because you now have an index array to bind as well.

Many of these points may, in practice, not have such big relative impact as I make it sound like, but it's all just examples of how all these parameters may interact, and how you have to consider the problem. The trade-offs could very well change just because you decided to increase the level of details in your scene by increasing the polygon count of your characters and objects, or if you decide to increase the number of objects.

It is very complex, and perhaps you can guess from experience if you're experienced enough, but profiling will often give you a better answer. And keep in mind that, for maximum performance, it is not a question of indexing or not indexing on an application level, but on a per object level. Some objects may benefit from indexing, and others may not.

#6 Danny02   Members   -  Reputation: 271

Like
1Likes
Like

Posted 13 June 2011 - 08:06 AM

In 99% of all cases, using indices is better in every aspect.

Only in some rar cases u can save a few bytes of memory but it will probably be slower.
  • With VAOs u always have only one bind, so no advantage for drawArrays
  • when using indices u get the speed up of the post transform cach
  • when u have a standart 32byte vertex layout (4*(3+3+2)) u need less space with indices, if more then 6,25% of your vertices got used more then once. (using usigned short indices)

On of these rare cases would be rendering point spirits.



As Brother Bob explained very well, optimizing your OpenGL code depends on a lot of factors.



#7 Darkbouncer4689   Members   -  Reputation: 110

Like
0Likes
Like

Posted 13 June 2011 - 08:51 AM

Thanks for the great responses guys, really appreciate it.
On a somewhat similar matter, would anyone know ways to keep track of gpu memory/usage? Something similar to the task manager of the cpu but for the gpu would be very helpful for monitoring my code.

Thanks so much!



#8 Danny02   Members   -  Reputation: 271

Like
1Likes
Like

Posted 13 June 2011 - 01:41 PM

take a look at :
http://www.ozone3d.net/gpushark/

its from http://www.geeks3d.com/ which is also a very cool blog with interessting stuff(shader samples for example)




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS