Thursday, July 6, 2017

opengl - Should I give each character its own VBO or should I batch them into a single VBO?


I'm making a 3D first person game. Should I give each character its own VBO or should I batch all characters into a single VBO? What are the pros/cons?



Answer



This is really a choice between performance and flexibility, but I'll list my opinions about it.


One single VBO



The positive sides are:



  • Just one draw call to draw your scene. This increases performance. Although your application may require multiple draw calls, you can still have a single VBO and let the count and offset decide your drawing.

  • Not requiring state changes between your objects. This increases performance.


and the negative sides are:



  • Hard to manage, although this depends on how you write your code, if it's properly designed etc.

  • By saying hard to manage I mean stuff like update the VBO, set correct offset for every object etc.



Individual VBO:s


The positive sides are:



  • Easy to implement.

  • Easier to manage from the beginning.


and the negative sides are:



  • Lots of state changes. This decreases performance.

  • Lots of draw calls. It will decrease the performance.



Summary


I'd recommend you to profile your application; get your real bottleneck in data you can see. Premature optimization can be shown (in this case) as unnecessary. However, that being said, if you'd discover a real performance loss in your application, given the individual VBO:s scenario, you can start implementing a single VBO.


However, as long as it's not needed (the number of objects are low, not many state changes overall, etc) I'd recommend to go with individual VBO:s unless you see that's not gonna work.


Edit


I forgot to mention that it'd be alright with multiple draw calls. The most important thing in performance critical times is to keep the state changes at a minimum. You can simply set the number of indices to process and an offset for every draw call, and this is fine. But however, keep state changes as low as possible and make as few draw calls as possible, that's the big hello of this answer, or at least what I tried to say.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...