views:

40

answers:

2

Hi all,

When we draw 300 sprites on the iPad using opengl 2.0 with glEnable(GL_BLEND) (which we need because the sprites need tranparency and alpha blending) we get an framerate of around 40. But when we disable the blending we get an framerate of 60.

Now is (alpha) blending really that costly or are we doing something wrong?

Thanks for your time, Richard.

A: 

It is really that costly. It requires a read-modify-write for each pixel. the modify operation is of the form

fragment * alpha + previous * (1 - alpha)

Count the number of pixels you do that on, and you'll soon realize you do a lot of math (and require more memory bandwidth). It all depends on how big your sprites are, but it is not surprising to slow down heavily when you have a lot of overdraw.

Bahbar
A: 

Alpha blending really IS that costly. The problem is that you can solve a lot of overdraw issues (something the PowerVR is very good at) by using Z-Buffering. It can save a tonne of memory bandwidth by not writing to the Z-buffer and draw buffer.

The moment you start alpha blending then you instantly need to read from the frame buffer blend and then write back (Read-Modify-Write or RMW). Effectively if you have 10 overlapping sprites then they need to be drawn 10 times where as with a Z-Buffered (again ish .. the PowerVR is odd on that front) un-blended system you only actually need to draw ONE pixel. So in that edge case you have saved a tenth of the WRITE bandwidth by simply not alpha blending. And don't forget there is also the read from the frame buffer that needs to take place for alpha blending on top of that.

As I alluded to it does get more complicated when Z-buffering is involved. Mainly because a Z-buffer requires a read, a compare and potentially a write but using Z-buffering you can discard pixels much earlier in the pipeline meaning you can save even more processing time. Couple that with the tiling system the PowerVR still, I believe, uses and your main concern is that RMW bandwidth loss to alpha blending.

Goz