1.4. The Frame Buffer
OpenGL is an API for drawing graphics, and so the fundamental purpose for OpenGL is to transform data provided by an application into something that is visible on the display screen. This processing is often referred to as RENDERING. Typically, this processing is accelerated by specially designed hardware, but some or all operations of the OpenGL pipeline can be performed by a software implementation running on the CPU. It is transparent to the user of the OpenGL implementation how this division among the software and hardware is handled. The important thing is that the results of rendering conform to the results defined by the OpenGL specification.
The hardware that is dedicated to drawing graphics and maintaining the contents of the display screen is often called the GRAPHICS ACCELERATOR. Graphics accelerators typically have a region of memory that is dedicated to maintaining the contents of the display. Every visible picture element (pixel) of the display is represented by one or more bytes of memory on the graphics accelerator. A grayscale display might have a byte of memory to represent the gray level at each pixel. A color display might have a byte of memory for each of red, green, and blue in order to represent the color value for each pixel. This so-called DISPLAY MEMORY is scanned (refreshed) a certain number of times per second in order to maintain a flicker-free representation on the display. Graphics accelerators also typically have a region of memory called OFFSCREEN MEMORY that is not displayable and is used to store things that aren't visible.
OpenGL assumes that allocation of display memory and offscreen memory is handled by the window system. The window system decides which portions of memory may be accessed by OpenGL and how these portions are structured. In each environment in which OpenGL is supported, a small set of function calls tie OpenGL into that particular environment. In the Microsoft Windows environment, this set of routines is called WGL (pronounced "wiggle"). In the X Window System environment, this set of routines is called GLX. In the Macintosh environment, this set of routines is called AGL. In each environment, this set of calls supports such things as allocating and deallocating regions of graphics memory, allocating and deallocating data structures called GRAPHICS CONTEXTS that maintain OpenGL state, selecting the current graphics context, selecting the region of graphics memory in which to draw, and synchronizing commands between OpenGL and the window system.
The region of graphics memory that is modified as a result of OpenGL rendering is called the FRAME BUFFER. In a windowing system, the OpenGL notion of a frame buffer corresponds to a window. Facilities in window-system-specific OpenGL routines let users select the frame buffer characteristics for the window. The windowing system typically also clarifies how the OpenGL frame buffer behaves when windows overlap. In a nonwindowed system, the OpenGL frame buffer corresponds to the entire display.
A window that supports OpenGL rendering (i.e., a frame buffer) may consist of some combination of the following:
Most graphics hardware supports both a front buffer and a back buffer in order to perform DOUBLE BUFFERING. This allows the application to render into the (offscreen) back buffer while displaying the (visible) front buffer. When rendering is complete, the two buffers are swapped so that the completed rendering is now displayed as the front buffer and rendering can begin anew in the back buffer. When double buffering is used, the end user never sees the graphics when they are in the process of being drawn, only the finished image. This technique allows smooth animation at interactive rates.
Stereo viewing is supported by having a color buffer for the left eye and one for the right eye. Double buffering is supported by having both a front and a back buffer. A double-buffered stereo window will therefore have four color buffers: front left, front right, back left, and back right. A normal (nonstereo) double-buffered window will have a front buffer and a back buffer. A single-buffered window will have only a front buffer.
If 3D objects are to be drawn with hidden-surface removal, a DEPTH BUFFER is needed. This buffer stores the depth of the displayed object at each pixel. As additional objects are drawn, a depth comparison can be performed at each pixel to determine whether the new object is visible or obscured.
A STENCIL BUFFER is used for complex masking operations. A complex shape can be stored in the stencil buffer, and subsequent drawing operations can use the contents of the stencil buffer to determine whether to update each pixel.
The ACCUMULATION BUFFER is a color buffer that typically has higherprecision components than the color buffers. Several images can thus be accumulated to produce a composite image. One use of this capability would be to draw several frames of an object in motion into the accumulation buffer. When each pixel of the accumulation buffer is divided by the number of frames, the result is a final image that shows motion blur for the moving objects. Similar techniques can be used to simulate depth-of-field effects and to perform high-quality full-screen antialiasing.
Normally, when objects are drawn, a single decision is made as to whether the graphics primitive affects a pixel on the screen. The MULTISAMPLE BUFFER is a buffer that allows everything that is rendered to be sampled multiple times within each pixel in order to perform high-quality full-screen antialiasing without rendering the scene more than once. Each sample within a pixel contains color, depth, and stencil information, and the number of samples per pixel can be queried. When a window includes a multisample buffer, it does not include separate depth or stencil buffers. As objects are rendered, the color samples are combined to produce a single color value, and that color value is passed on to be written into the color buffer. Because multisample buffers contain multiple samples (often 4, 8, or 16) of color, depth, and stencil for every pixel in the window, they can use up large amounts of offscreen graphics memory.
AUXILIARY BUFFERS are offscreen memory buffers that can store arbitrary data such as intermediate results from a multipass rendering algorithm. A frame buffer may have 1, 2, 3, 4, or even more associated auxiliary buffers.