ELI5: Explain Like I'm 5

Double buffering

Imagine you are drawing a picture on a piece of paper. You start with the background, then add a few shapes and colors, and finally a person or an animal. As you draw, you notice that the colors don't look right, they are smudged, or there are little marks and scratches on the paper.

This is because you are drawing directly on the paper, and every time you make a mistake or want to change something, you have to erase it or start over. This can be frustrating and time-consuming, and the picture may not turn out the way you want.

Now, imagine you have another piece of paper, and you put it on top of the first one, like a sandwich. You draw the background on the first paper, then add the shapes and colors on the second paper, and finally the person or animal on the first paper again.

This way, you can see the whole picture while you are drawing, but you are not touching the original paper directly. If you make a mistake or want to change something, you can just remove the second paper and start over, without damaging the original paper.

This is how double buffering works in computer graphics. When you watch a video or play a game on your computer or phone, the pictures and animations are displayed on the screen using pixels (tiny dots of light that can change color). The computer needs to update these pixels many times per second to create the illusion of motion and fluidity.

However, if the computer updates the pixels directly every time, there may be visible glitches, tearing, stuttering, or input lag (delay between your actions and the response on the screen). This is because the different parts of the picture may be updated at different rates, or the updates may interfere with each other.

To avoid this, the computer can use double buffering. It creates two copies of the picture in the memory: one is the current frame that is being displayed on the screen, and the other is the next frame that is being prepared in the background.

When the current frame is finished, the computer swaps the two frames, so that the next frame becomes the current frame, and the previous current frame becomes the new next frame. This happens so fast that you don't notice the switch, and the picture appears to be moving smoothly.

Because the next frame is prepared separately from the current frame, the computer can take its time to calculate the changes and special effects, without affecting the current frame. This also allows the computer to synchronize the updates to the refresh rate of the screen, so that the frames are displayed at the right moment.

Double buffering is like having two pieces of paper that the computer draws on simultaneously, but only shows one of them at a time. This way, the computer can create complex and dynamic graphics without sacrificing speed or quality.