• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Darkbouncer4689

drawElements vs drawArrays

7 posts in this topic

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!

0

Share this post


Link to post
Share on other sites
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.
1

Share this post


Link to post
Share on other sites
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?
0

Share this post


Link to post
Share on other sites
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 =)
0

Share this post


Link to post
Share on other sites
[quote name='Darkbouncer4689' timestamp='1307970845' post='4822737']
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?
[/quote]
I disagree that it is the [i]only[/i] time.

[quote name='Darkbouncer4689' timestamp='1307970900' post='4822738']
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 =)
[/quote]
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 [i]may[/i] 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 [i]per object[/i] level. Some objects may benefit from indexing, and others may not.
1

Share this post


Link to post
Share on other sites
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.[list][*]With VAOs u always have only one bind, so no advantage for [color="#1C2837"][size="2"]drawArrays [/size][/color][*][color="#1C2837"][size="2"]when using indices u get the speed up of the post transform cach[/size][/color][*][color="#1C2837"][size="2"]when u have a standart 32byte vertex layout (4*(3+3+2)) u need [b]less [/b]space with indices, if more then 6,25% of your vertices got used more then once. (using usigned short indices)[/size][/color][/list][size="2"][color="#1c2837"]
[/color][/size][size="2"][color="#1c2837"]On of these rare cases would be rendering point spirits.
[/color][/size]
[size="2"][color="#1c2837"]
[/color][/size]
[size="2"][color="#1c2837"] As [/color][/size]Brother Bob explained very well, optimizing your OpenGL code depends on a lot of factors.

[size="2"] [/size]
1

Share this post


Link to post
Share on other sites
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!

0

Share this post


Link to post
Share on other sites
take a look at :
[url="http://www.ozone3d.net/gpushark/"]http://www.ozone3d.net/gpushark/[/url]

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0