views:

195

answers:

2

Apple's Technical Q&A on addressing flickering (QA1650) includes the following paragraph. (Emphasis mine.)

You must provide a color to every pixel on the screen. At the beginning of your drawing code, it is a good idea to use glClear() to initialize the color buffer. A full-screen clear of each of your color, depth, and stencil buffers (if you're using them) at the start of a frame can also generally improve your application's performance.

On other platforms, I've always found it to be an optimization to not clear the color buffer if you're going to draw to every pixel. (Why waste time filling the color buffer if you're just going to overwrite that clear color?)

How can a call to glClear() improve performance?

+3  A: 

It is most likely related to tile-based rendering, which divides the whole viewport to tiles (smaller windows, can be typically of size 32x32) and these tiles are kept in faster memories. The copy operations between this smaller memory and the real framebuffer can take some time (memory operations are a lot slower than arithmetic operations). By issuing a glClear command, you are telling the hardware that you do not need previous buffer content, thus it does not need to copy the color/depth/whatever from the framebuffer to the smaller tile memory.

tersyon
If you need more details, check out these references:- http://developer.amd.com/gpu_assets/gdc2008_ribble_maurice_TileBasedGpus.pdf - http://www.beyond3d.com/content/articles/38/
tersyon
A: 

Not a real answer (I can't post comments?), but definitely a confirmation that you have to provide a color to every pixel on the screen.

I've verified this in a bare bones test app built on XCode's iPhone OpenGL template:

[context presentRenderbuffer:GL_RENDERBUFFER];
glClear( GL_COLOR_BUFFER_BIT );

If I leave out the glClear line (or move it further down in the loop, after some other openGL calls), the thread (running via CADisplayLink) is hardly getting any updates anymore. It seems as if CPU/GPU synchronization goes haywire and the thread gets blocked. Pretty scary stuff if you ask me, and totally not in line with my expectations.

BTW, you don't neccessarily have to use glClear(), just drawing a fullscreen quad seems to have the same effect (obviously, a textured quad is more expensive). It seems you just have to invalidate all the tiles.

zmippie