As mentioned in the previous section, all the color components, color indices, and stencil indices can be modified by means of a table lookup before being placed in screen memory. The command for controlling this mapping is glPixelMap*(). void glPixelMap[ui us f}v(GLenum map, GLint mapsize, const TYPE *values);
Loads the pixel map indicated by map with mapsize entries, whose values are pointed to by values. Table 8-5 lists the map names and values; the default sizes are all 1 and the default values are all 0. Each map's size must be a power of 2.
| Map Name | Address | Value |
|---|---|---|
GL_PIXEL_MAP_I_TO_I | color index | color index |
GL_PIXEL_MAP_S_TO_S | stencil index | stencil index |
GL_PIXEL_MAP_I_TO_R | color index | R |
GL_PIXEL_MAP_I_TO_G | color index | G |
GL_PIXEL_MAP_I_TO_B | color index | B |
GL_PIXEL_MAP_I_TO_A | color index | A |
GL_PIXEL_MAP_R_TO_R | R | R |
GL_PIXEL_MAP_G_TO_G | G | G |
GL_PIXEL_MAP_B_TO_B | B | B |
GL_PIXEL_MAP_A_TO_A | A | A |
The maximum size of the maps is machine-dependent. You can find the sizes of the pixel maps supported on your machine with the glGet*() command: Use the query argument GL_MAX_PIXEL_MAP_TABLE to obtain the maximum size for all the pixel map tables, and use GL_PIXEL_MAP_*_TO_*_SIZE to obtain the current size of the specified map. The six maps whose address is a color index must always be sized to an integral power of 2. The four RGBA maps can be any size from 1 through GL_MAX_PIXEL_MAP_TABLE.
To illustrate how a table works, let's look at a simple example. Suppose that you want to create a 256-entry table that maps color indices to color indices using GL_PIXEL_MAP_I_TO_I. You create a table with an entry for each of the values between 0 and 255, and initialize the table with glPixelMap*(). Let's say that you're using the table for thresholding, for example, and you want to map all indices 100 and below to 0, and all indices 101 and above to 255. In this case, your table consists of 101 0s and 155 255s. The pixel map is enabled using the routine glPixelTransfer*() to set the parameter GL_MAP_COLOR to TRUE. Once the pixel map is loaded and enabled, incoming color indices below 101 come out as 0, and incoming pixels between 101 and 255 are mapped to 255. If the incoming pixel is larger than 255, it's first masked by 255, throwing out all the bits beyond the eighth, and the resulting masked value is looked up in the table. If the incoming index is a floating-point value (say 88.14585), it's rounded to the nearest integer value (giving 88), and that number is looked up in the table (giving 0).
OpenGL Programming Guide