Renderer Interaction with Ancillary Buffers


For an overview about Renderers, see General Information. For a list of all Renderer functions and related topics, see Renderers.

A renderer manages the Z-buffer needed for some hidden line/hidden surface algorithms.

When an implicit or explicit PEXBeginRendering occurs and the renderer's HLHSR_mode indicates that Z-buffering should be performed or if the renderer's clear Z attribute is True, then the implementation obtains or allocates a Z-buffer suitable for use with the specified drawable, and binds it to the drawable. (A new Z-buffer is only allocated if a Z-buffer does not exist for the drawable or if the Z-buffer which is bound to the drawable is not suitable, e.g. a resize has occurred and the Z-buffer has not yet been resized.) If the renderer's HLHSR_mode does not indicate that Z-buffering is to be performed and the clear Z attribute is False at the time PEXBeginRendering is processed, but the mode is later changed by a PEXChangeRendererExtAttributes request to indicate that Z-buffering is to be performed, then the Z-buffer is allocated, if necessary, at that time.

When PEXBeginRendering is processed and if the renderer's clear Z attribute is True, then the Z-buffer is cleared to the renderer's clear Z value only in the region specified by the renderer's clip list. PEXClearRenderer performs the same operation if the Z clear parameter is on.

A renderer also manages the buffer used for alpha blending and certain methods of transparency. This buffer is known as an alpha buffer as it contains the resulting alpha values from certain blending operations. When an implicit or explicit PEXBeginRendering occurs and the renderer's clear alpha attribute is True or the renderer's transparency method indicates an alpha buffer is needed, an alpha buffer is allocated and bound to the drawable. If the transparency method does not indicate that an alpha buffer is needed when PEXBeginRendering is processed, but the method is later changed by a PEXChangeRendererExtAttributes request to a method which does require an alpha buffer, then the alpha buffer is allocated, if necessary, at that time. Also, if the transparency method is TransparencyAlphaBlend, then the alpha buffer is not allocated, if necessary, until the pipeline state's alpha blend function is set to a value which requires an alpha buffer (i.e., a function which uses destination alpha as an input).

When PEXBeginRendering is processed and if the renderer's clear alpha attribute is True, then the alpha buffer is cleared to the alpha value in the renderer's background color. If no alpha value is provided in the renderer's background color, then the default value of 1.0 is used. The alpha buffer is cleared only in the region specified by the renderer's clip list. PEXClearRenderer performs the same operation if the alpha clear parameter is on.

In addition to the conditions previously described, ancillary buffers can also be allocated by the implementation under certain circumstances in response to other renderer requests described in this chapter. For example, if a renderer is created and a PEXClearRenderer request to clear the Z buffer is received immediately after the renderer is created, the implementation allocates the Z buffer as a part of satisfying the request. Z buffers can be allocated as the result of the PEXClearRenderer, PEXGetZBuffer, PEXPutZBuffer, PEXCopyZBufferToPixmap, and PEXCopyPixmapToZBuffer functions. Alpha buffers can be allocated as the result of the PEXClearRenderer, PEXCopyAlphaBufferToPixmap, and PEXCopyPixmapToAlphaBuffer functions.

If the Z-buffer or alpha buffer could not be allocated, then the implementation issues an BadAlloc error and aborts rendering; the renderer state is set to PEXIdle.

Z-buffers and alpha buffers are not deallocated when the renderer state becomes PEXIdle. They remain bound to the drawable until you free the drawable. This allows the contents of the buffers to be reused if the corresponding clear flags are off. When the renderer state next becomes PEXRendering or PEXPicking, an attempt is made to reuse them. If they cannot be reused (for instance, if the drawable has been resized and the Z-buffer has not been resized to match), then they are reallocated as necessary.

Finally, a renderer also utilizes an accumulation buffer as another type of ancillary buffer. However, accumulation buffers are managed differently than other ancillary buffers. See Accumulation Buffers for more information.

Related to this discussion on buffers is the PEXGetAncillaryBufferInfo which provides information to determine the capabilities of various visuals such as whether Z-buffer, alpha buffer and accumulation buffers are supported for a specified drawable created with a particular visual.