Game Development Reference
In-Depth Information
A more interesting situation arises in real-time animation. In this case,
the frame buffer is normally located in video RAM. The video card is con-
stantly reading this area of video RAM, converting the binary data into
the appropriate signal to be sent to the display device. But how can the
monitor read this memory while we're trying to render to it? A technique
known as double buffering is used to prevent an image from being displayed
before it is completely rendered. Under double buffering, there are actually
two frame buffers. One frame buffer, the front buffer, holds the image cur-
rently displayed on the monitor. The back buffer is the off-screen buffer,
which holds the image currently being rendered.
When we have finished rendering an image and are ready for it to be
displayed, we “flip” the buffers. We can do this in one of two ways. If
we use page flipping, then we instruct the video hardware to begin reading
from the buffer that was the off-screen buffer. We then swap the roles of the
two buffers; the buffer that was being displayed now becomes the off-screen
buffer. Or we may blit (copy) the off-screen buffer over the display buffer.
Double buffering is shown in Figure 10.38.
Figure 10.38
Double buffering
The more modern terminology for making visible the image that was
rendered into the back buffer is presenting the image.
The second important buffer used for rendering is the depth buffer, also
known as the z-buffer. Rather than storing a color at each pixel, the depth
buffer stores a depth value per pixel. There are many variations in the
specifics of exactly what value goes into the depth buffer, but the basic
idea is that it is related to the distance from the camera. Often the clip-
space z-coordinate is used as a depth value, which is why the depth buffer
is also known as the z-buffer.
The depth buffer is used to determine which objects occlude which ob-
jects, as follows. As we are rasterizing a triangle, we compute an inter-
polated depth value per pixel. Before rendering a pixel, we compare this
Search WWH ::




Custom Search