[ Previous | Next | Contents | Glossary | Home | Search ]
GL3.2 Version 4.1 for AIX: Programming Concepts

Additional Z-Buffer Features

This section deals with special features that control z-buffering. Topics covered include reading the z-buffer, using the z-buffer for hidden surface removal in overlay planes, drawing directly into the z-buffer, using alternate depth comparison functions and sources, and writemasks for the z-buffer.

Reading the Z-Buffer

The contents of the z-buffer can be obtained by using the zdraw subroutine in conjunction with the lrectread subroutine.

Due to the nature of the design of the 3D Color Graphics Processor, values read back from the z-buffer may appear to be incorrect. To avoid obtaining peculiar z values, use the czclear subroutine to clear the z-buffer before drawing, and specify any z-value other than 0x7fffff or -0x800000 for the clear value. For instance, clearing to a value of -0x7ffffe can work without sacrificing dynamic range or accuracy. Note, however, that clearing to such non-standard z-values may degrade z clear performance and affect overall application performance.

Note: Not all graphics adapters support reading the z-buffer.

Hidden Surface Removal in the Overlay Planes

The z-buffer can be used in conjunction with the overlay planes to provide hidden-line and hidden-surface removal in the overlays. In a typical application, a solid-shaded figure might be drawn in the main frame buffer, while a wire-frame drawing is actively dragged about in the overlays. If the wire-frame drawing is dragged behind the solid-shaded figure, the z-buffer automatically prevents the hidden portion of the wire-frame drawing from being drawn. When performing such dragging, be sure to enable the z-buffer (by setting the z-buffer to True), and to set the z-buffer writemask so that the wire-frame drawing does not change any values already in the z-buffer.

Note: Unless the above effect is specifically desired, it is recommended that z-buffering be disabled (by setting the z-buffer to False) while drawing into the overlay planes. Otherwise, confusing visual images may be the unintentional result when a drawing in the overlay becomes z-buffered.

Drawing into the Z-buffer

In some cases it is useful to be able to draw directly into the z-buffer. For instance, the z-buffer can be used as a clipping mask by writing near values into the region to be masked. If no other primitive is nearer than the value written into the z-buffer, the z-buffer hardware prevents the pixels from being written, effectively masking the region.

On the High Performance 3-D Color Graphics Processor, the zdraw subroutine enables block transfer of pixels into and out of the z-buffer. If the zdraw subroutine is enabled, the lrectwrite and lrectread subroutines transfer pixels to and from the z-buffer.

The zdraw subroutine is similar to the frontbuffer and backbuffer subroutines in that it permits writing into the z-buffer bank. Normally, if you are writing into the z-buffer, you do not want to write into the front buffer and back buffer at the same time. Usually, drawing into the z-buffer should be bracketed by subroutines that set backbuffer(FALSE) and then backbuffer(TRUE) afterwards (assuming the program is in double buffer mode).

In single buffer mode, the frontbuffer subroutine normally has no effect. However, if you call frontbuffer(FALSE) , a flag is set so that when the zdraw subroutine is set to TRUE , the front buffer (the only buffer in single buffer mode) is not written into. If the zdraw subroutine is set to FALSE , frontbuffer(FALSE) has no effect.

Alternate Comparisons

In the default mode, the z coordinate of the new pixel is compared to the z coordinate of the figure currently at that pixel. If the incoming z value shows that the new geometry is closer to the eye than the old one, the values of the old pixel and of the old z value are replaced by the new ones.

The new value is compared to the old, and if it is less than the old, the old quantities are replaced. It is possible to change the comparison function from less-than to many other things. The available comparisons are shown in the following list.

Comparison Function Definition
ZF_NEVER Never overwrite the source pixel value.
ZF_LESS Overwrite the source pixel value if the z of the source pixel value is less than the z of the destination value.
ZF_EQUAL Overwrite the source pixel value if the z of the source pixel value is equal to the z of the destination value.
ZF_LEQUAL Overwrite the source pixel value if the z of the source pixel value is less than or equal to the z of the destination value (default).
ZF_GREATER Overwrite the source pixel value if the z of the source pixel value is greater than the z of the destination value.
ZF_NOTEQUAL Overwrite the source pixel value if the z of the source pixel value is not equal to the z of the destination value.
ZF_GEQUAL Overwrite the source pixel value if the z of the source pixel value is greater than or equal to the z of the destination value.
ZF_ALWAYS Always overwrite the source pixel value regardless of destination value.

To change the comparison function, use the zfunction subroutine.

Z-buffer Writemask

The zwritemask subroutine can be used like other writemasks to control writing into the z-buffer. The two valid settings are 0 (no write at all) and 0xffffff (write all the bits). This subroutine could be useful for a very complicated background into which a few objects are going to be drawn and moved quickly. Setting the zwritemask to 0 locks the background information in and prevents its modification. New objects are drawn or not depending on whether the depth comparison indicates that they are in front of or behind anything else in the scene.


[ Previous | Next | Contents | Glossary | Home | Search ]