开发者

In OpenGL ES, is it faster to draw one large object or many small ones?

开发者 https://www.devze.com 2023-03-08 15:33 出处:网络
For an OpenGL ES 3-D game on iPhone, which of th开发者_开发技巧e following is faster to render:

For an OpenGL ES 3-D game on iPhone, which of th开发者_开发技巧e following is faster to render:

  • 10 objects having 100 triangles
  • one object having 1000 triangles


There is some overhead to each OpenGL ES draw call that you issue, so if you were presenting the 10 objects individually using glDrawArrays() or glDrawElements(), that would normally be slower than the one large object. However, I think you'll find the overhead from these draw calls to be only a small factor in any rendering slowdowns you might experience on iOS devices.

If these ten objects are static, it's pretty easy to used indexed triangles to combine all of them into one array that is drawn in one call. As Waldheinz points out, I the article I wrote three years ago advocates the use of vertex buffer objects (VBOs) to help store the geometry on the GPU and avoid costly uploads on every frame. This was less important at the time I wrote it than now, with the newer iOS GPUs providing hardware support for VBOs.

Other things are more likely to affect performance, such as whether these objects use transparency, the complexity of lighting on them, etc. When in doubt, follow Apple's "Best Practices for Working with Vertex Data", as contained within their OpenGL ES Programming Guide for iOS, and profile your application using the OpenGL ES Driver and OpenGL ES Analyzer instruments.


It won't really matter unless you use VBOs. But then drawing 1 object is faster than drawing 10 objects. Someone elaborated about this in some detail here.


When the triangle count is fixed, drawing a single object should always be faster than drawing multiple objects.


The number of triangles in both cases is the same, so these are equivalent, all else being equal. GL doesn't know anything about your "objects"-- it just renders the triangles.

That said, there can be some data size savings if you share vertices between triangles within objects and use triangle strips or fans or indexed vertices. See Brad's answer for more comprehensive lay of the land info there.

0

精彩评论

暂无评论...
验证码 换一张
取 消