Triple buffering is a technique that uses three buffers to reduce or avoid the problems VSYNC can cause. The three buffers are:
- The frontbuffer
The frontbuffer holds the image currently being displayed.
- The middlebuffer
The middlebuffer holds a completed image until the front buffer is ready to display it. When the current frame finishes displaying, the frontbuffer and middlebuffer switch.
- The backbuffer
The backbuffer holds the image being drawn. When the GPU finishes drawing the backbuffer and middlebuffer switch.
Using three buffers decouples the drawing process from the display process. This means that a consistent high frame rate is achieved with VSYNC, even if frame drawing takes take longer than the frame display time.
Triple buffering with VSYNC is shown in Figure 2.4. The frame generation process takes longer than the frame display, but the display frame rate remains high because the GPU can keep drawing while the middle buffer holds a completed frame. A frame might be dropped occasionally.
Triple buffering requires a third buffer the size of the frame buffer. This can be a significant amount of memory if your application is drawing to a high resolution.