Fastest sprite method

Member
Posts: 117
Joined: 2010.09
Post: #1
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
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #2
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)

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Member
Posts: 166
Joined: 2009.04
Post: #3
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.
Quote this message in a reply
Member
Posts: 117
Joined: 2010.09
Post: #4
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
Quote this message in a reply
Member
Posts: 23
Joined: 2010.08
Post: #5
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

The Monkey Hustle - Now available on the App Store!
Quote this message in a reply
Member
Posts: 117
Joined: 2010.09
Post: #6
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
Quote this message in a reply
Member
Posts: 117
Joined: 2010.09
Post: #7
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
Quote this message in a reply
Apprentice
Posts: 14
Joined: 2010.01
Post: #8
(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.
Quote this message in a reply
Member
Posts: 117
Joined: 2010.09
Post: #9
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
Quote this message in a reply
Member
Posts: 117
Joined: 2010.09
Post: #10
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
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  What is the fastest way to blit a framebuffer to the iPhone screen? Rasterman 20 27,931 Mar 2, 2011 08:26 AM
Last Post: arekkusu
  Fastest Possible Blending Function, OpenGL ES 2.0 Macmenace 12 16,405 Apr 16, 2010 11:44 AM
Last Post: Macmenace