Graphics Reference
In-Depth Information
The color buffer holds the image shown on-screen in a graphics system. A
reasonable representation might be a 2D array of pixel values, each of which stores
three fields: red, green, and blue. Set aside the interpretation of those fields for the
moment and consider the implementation details of this representation.
The fields should be small, that is, they should contain few bits. If the color
buffer is too large then it might not fit in memory, so it is desirable to make each
field as compact as possible without affecting the perceived quality of the final
image. Furthermore, ordered access to the color buffer will be substantially faster
if the working set fits into the processor's memory cache. The smaller the fields,
the more pixels that can fit in cache.
The size of each pixel in bits should be an integer multiple or fraction of the
word size of the machine. If each pixel fits into a single word, then the memory
system can make aligned read and write operations. Those are usually twice as fast
as unaligned memory accesses, which must make two adjacent aligned accesses
and synthesize the unaligned result. Aligned memory accesses are also required
for hardware vector operations in which a set of adjacent memory locations are
read and then processed in parallel. This might give another factor of 32 in perfor-
mance on a vector architecture that has 32 lanes. If a pixel is larger than a word by
an integer multiple, then multiple memory accesses are required to read it; how-
ever, vectorization and alignment are still preserved. If a pixel is smaller than a
word by an integer multiple, then multiple pixels may be read with each aligned
access, giving a kind of super-vectorization.
One common buffer format is shown in Figure 14.5. This figure shows a 3
16-bit pixel
RGBRGBRGB
RG
BR G BR G B
RGBRGBRGB
5-bit channels
6-bit channels
Figure 14.5: The GL_R5G6B5
buffer format packs three normal-
ized fixed-point values represent-
ing red, green, blue, and cover-
age values, each on [0, 1], into
every 16-bit pixel. The red and
blue channels each receive five
bits. Because 16 is not evenly
divisible by three, the “extra” bit
is (mostly arbitrarily) assigned to
the green channel.
3
buffer in the GL_R5G6B5 format. This is a normalized-fixed point format for 16-bit
pixels. On a 64-bit computer, four of these pixels can be read or written with a
single scalar instruction.
×
Five bits per channel is not much considering that the human eye can distin-
guish hundreds of shades of gray. Eight bits per channel enable 256 monochrome
shades. But three 8-bit channels consume 24 bits, and most memory systems are
built on power-of-two word sizes. One solution is to round up to a 32-bit pixel
and simply leave the last eight bits of each pixel unused. This is a common prac-
tice beyond graphics—compilers often align the fields of data structures with such
unused bits to enable efficient aligned memory access. However, it is also common
in graphics to store some other value in the available space. For example, the com-
mon GL_RGBA8 format stores three 8-bit normalized fixed-point color channels and
an additional 8-bit normalized fixed-point value called
(or “alpha,” represented
by an “A”) in the remaining space (see Figure 14.6). This value might represent
coverage, where
α
α
= 0 is a pixel that the viewer should be able to see through and
α
= 1 is a completely opaque pixel.
Obviously, on most displays one cannot see through the display itself when a
color buffer pixel has
= 0; however, the color buffer may not be intended for
direct display. Perhaps we are rendering an image that will itself be composited
into another image. When writing this topic, we prepared horizontal and vertical
grid lines of Figure 14.5 as an image in a drawing program and left the pixels that
appear “white” on the page as “transparent.” The drawing program stored those
values with
α
= 0. We then pasted the grid over the text labels “R,” “G,” etc.
Because the color buffer from the grid image indicated that the interior of the grid
cells had no coverage, the text labels showed through, rather than being covered
with white squares. We return more extensively to coverage and transmission in
Section 14.10.2.
α
 
 
Search WWH ::




Custom Search