iDevGames Forums
Fastest sprite method - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: iPhone, iPad & iPod Game Development (/forum-11.html)
+--- Thread: Fastest sprite method (/thread-8132.html)



Fastest sprite method - markhula - Sep 23, 2010 09:41 AM

Hi All,

I've got my quads up ok on the iphone but it's just not fast enough!
I am using the standard drawarrays approach per sprite.
I have read about VBO's which seem faster but then read another article which suggests they are not.
For example suppose I wish to draw a 10 x 10 array of quads that remain static apart from there transform; are VBO's the way to go?

Can anyone be supply me with a simple example that perhaps draws 2 disconnected quads using VBO's?

Any help/suggestions appreciated

Cheers

Mark


RE: Fastest sprite method - Skorche - Sep 23, 2010 10:37 AM

VBO's aren't really going to help for drawing a lot of immediate mode quads.

The fastest way to draw sprites generally is to transform the vertexes yourself on the CPU so that you can draw a bunch of quads together in a single draw call. Setting transformation matrices and making a draw call is quite expensive when you are only passing 4 vertexes/2 triangles. Far more expensive that simply transforming the vertexes yourself.

You should also make a sprite atlas because you can't switch textures in the middle of a sprite batch.

You can also consider using point sprites if you can live with the limitations. (no rotation and you can only batch a single sprite image)


RE: Fastest sprite method - warmi - Sep 23, 2010 10:39 AM

There is a very good chance it won't do you any good ... when drawing 2d rectangles 90% of time, you end up being fillrate limited.

Make your quads much smaller ( say 2x2 pixels) and see if it makes any difference in terms of performance - if it does then don't waste your time with your vertex submission code - you need to optimize for fillrate.


RE: Fastest sprite method - markhula - Sep 23, 2010 11:29 AM

Hi guys,

Thanks for the replies.
Currently I only do 1 texture swap, so thats not the issue.
Also my sprites are in a flat mesh and cover the screen; so I am not trying to draw millions on them :-)
I will use a texture atlas later, but just the draw now is giving a poor framte rate (40fps on 3g).
Are point sprites the way to go?, can I set there uv's within 1 texture page?
Do I need to batch my drawarrays to draw the whole mesh rather than multiple calls?

Any suggestions appreciated

Cheers


RE: Fastest sprite method - mariocaprino - Sep 23, 2010 12:50 PM

As mentioned previously in this thread the two biggies to optimising OpenGL ES for the iPhone is batching geometry (thus minimising draw calls) and reducing texture memory access by using textures with small footprint and/or mipmapping (2bits PVRTC render faster than textures with greater colour depth).

If you got a 100 quads to draw you should attempt to draw them all with a single glDrawElements()-call.
To help you achieve this you should do the following:
  • Use Texture Atlases so you may bind only one texture for all your quads
  • Perform all per-quad transformations on the CPU so they may use same OpenGL ModelViewProjection matrix.

You may view ngmoco's Stanford speech for an example of efficiently batching geometry. You may also download the source from the session.

Once you are able to submit all your quads as one single glDrawElements()-call you should be able to achieve full frame rate on an iPhone 3G.

Once you've gotten to this point you can play around with more exotic optimisations if needed:
  • Use a single static degenerate triangle-strip elements buffer for submitting your quads
  • Use VBOs for static buffers (will only help performance on newer iPhone models using the SGX chipset)
  • Use MATRIX_PALETTE to move some of the per-quad transformations from the CPU to GPU
  • Use the Accelarate.framework to batch transform vertex data on the CPU



RE: Fastest sprite method - markhula - Sep 24, 2010 12:55 AM

Hi all,

Thanks for the great help!
The ngmoco speech was most helpful and I can see that my first task is to batch my geometry. I'll try that and report back what speed increase I get.

Thanks again!

Mark


RE: Fastest sprite method - markhula - Sep 24, 2010 05:18 AM

Hmmmmm!
I have noticed some strangeness in the fireworks source, presumably my lack of understanding (I can't compile it but assume something is up)

On addVertex he increments the vertexcount each time; hence 6 for a quad.
But then after adding all 6 vertices (2 tri's) he then increments the vertex count by 6!; this can't be right!?!?!?!?!

Ok!; what have I mis-understood! LOL

Cheers


RE: Fastest sprite method - Sumaleth - Sep 24, 2010 05:46 AM

(Sep 24, 2010 05:18 AM)markhula Wrote:  On addVertex he increments the vertexcount each time; hence 6 for a quad.
But then after adding all 6 vertices (2 tri's) he then increments the vertex count by 6!; this can't be right!?
Yeah, that looks like a bug. The _vertexCount >= MAX_VERTS test below that might be a bug too, depending on how that MAX_VERTS value is calculated.

Those two issues might be related; the +=6 might have been intended to be part of that test, to ensure that there is room for the next quad.

Rowan.


RE: Fastest sprite method - markhula - Sep 24, 2010 05:55 AM

Hmmm!
But what I mean is he inc's vertexcount by 1 per vertex (which is fine).
Then he add's 6; surely therefore his vertex array will be vertex,NULL,vertex,NULL, etc. because he is stepping 12 per indices when it should be only 6.
Even with the +6 commented out I still get nothing drawn in my test rig . :-(

Cheers


RE: Fastest sprite method - markhula - Sep 24, 2010 08:04 AM

Hey!, got it working!
And yes the fireworks example *must* be wrong (neck on line :-) ).
Anyway!, I would say I've got around a 70% speed increase! :-)))))
So very happy with that, thanks everyone for your help!

Cheers