Double Buffering


Use an offline graphics buffer to compose the next animation frame
Double buffering

How does it work?

An animation consists of a series of frames. In most cases storing all frames in memory is too costly. Using just a single buffer to show the current frame and prepare the next frame causes a noticeable flicker. A common solution is to use two bufferes: an active buffer and an inactive buffer. Show the current frame on the active buffer while preparing the next frame on the inactive buffer. Then make the active buffer inactive and vice versa, and repeat.

LCD screens, like CRT screens, are drawn line by line, from top top bottom. If a buffer switch takes place somewhere halfway the screen, the upper part of the screen will show the old buffer while the lower part of the screen will show the new buffer. This causes a noticeable "tear". To avoid this, make the switch when the monitor is not drawing lines. This is called vertical synchronization (VSYNC).

When should you use it?

  • When you need a smooth animation