#include <ggi/buf.h>
int ggiBufSetGCForeground
(ggiBuf_t buf, ggi_bufval val);
int ggiBufGetGCForeground
(ggiBuf_t buf, ggi_bufval *val);
int ggiBufSetGCBackground
(ggiBuf_t buf, ggi_bufval val);
int ggiBufGetGCBackground
(ggiBuf_t buf, ggi_bufval *val);
int ggiBufSetGCFlags
(ggiBuf_t buf, enum ggiBuf_flags flags);
int ggiBufGetGCFlags
(ggiBuf_t buf, enum ggiBuf_flags *flags);
ggiBufSetGCForeground and ggiBufGetGCForeground set and read, respectively, the current value used as a default for the channel (Alpha, Z, etc.) represented by the buffer buf when data is sent to a compound buffer or clad visual to which buf belongs, when such data has no corresponding channel. This value applies to all pixels drawn in the foreground color in two-color operations, or otherwise to all pixels.
ggiBufSetGCBackground and ggiBufGetGCBAckground set and read, respectively, the current value used as a default when the buffer is cleared with ggiBufClear. This value is also used in the same way that the foreground value is used when a two-color operation like text drawing is performed, but applies only to pixels drawn in the background color.
ggiBufSetGCFlags and ggiBufGetGCFlags set and read, respectively, flags which define the default behavior of the buffer.
The following flag values are defined for both Alpha and Z buffers:
Designates that the resultant alpha or Z value is not to overwrite the destination alpha or Z value, and is instead thrown away.
Designates that the channel is valid as both source and destination when a command is invoked which causes data from the buffer to be written back to itself at another position. In other words, on a clad visual, when this flag is not set, the copybox operation will use the buffer's foreground value for the source value, whereas, when it is set, the values in the buffer at the source location will be used. (This also works for crossblt, when the clad visual is used as the source visual.) Note that this also affects LibGGI get/put operations when used on a clad visual that contains alpha or Z in-pixel channels, however, using it as such must only be done when it is known that the channels are in-pixel, because otherwise it has no affect on get/put operations.
The following flag values are defined for Z buffers:
These flags determine the comparison type (greater than, less than, greater than or equal, and less than or equal, respectively) used when deciding which of two Z values is considered to be "over" the other. BUF_CMP_LTE is the default comparison (assuming it is available), meaning that if the source Z value is less than or equal to the destination Z value, the pixel in question will be drawn.
The following flags are defined for Alpha buffers and determine the type of blend performed:
Values are blended using the following rule expressed with normalized Alpha values: D = As * S + (1 - As) * D * Ad; A = As + (1 - As) * Ad
Values are blended using the following rule expressed with normalized Alpha values: D = Ad * D + (1 - Ad) * S * As; A = Ad + (1 - Ad) * As
Values are blended using the following rule expressed with normalized Alpha values: D = As * S * Ad; A = As * Ad
Values are blended using the following rule expressed with normalized Alpha values: D = Ad * D * As; A = Ad * As
Values are blended using the following rule expressed with normalized Alpha values: D = As * S * (1 - Ad); A = As * (1 - Ad)
Values are blended using the following rule expressed with normalized Alpha values: D = Ad * D * (1 - As); A = Ad * (1 - As)
Values are blended using the following rule expressed with normalized Alpha values: D = As * S * Ad + (1 - As) * D * Ad; A = As * Ad + (1 - As) * Ad
Values are blended using the following rule expressed with normalized Alpha values: D = Ad * D * As + (1 - Ad) * S * As; A = Ad * As + (1 - Ad) * As
Values are blended using the following rule expressed with normalized Alpha values: D = As * S * (1-Ad) + (1-As) * D * Ad; A = As * (1-Ad) + (1-As) * Ad
Values are blended using the following rule expressed with normalized Alpha values: D = As * S + Ad * D; A = As * Ad
This nifty feature allows you to choose a second blend to be used in when both alpha and Z are in use, which will be used when the Z value of the source is determined to be "behind" that of the destination. To choose the second blend, shift any of the below BUF_BLEND* flags (with the exception of BUF_BLEND_*_PREMULT) left by BUF_ALTBLEND_SHIFT bits. In order to use this feature, this flag must have been set on both the Z and the Alpha buffer when they were first created. This flag should not be shifted by BUF_BLEND_SHIFT, as it obviously applies to both blends.
Values in the source are premultiplied by their Alpha. This flag should not be shifted by BUF_BLEND_SHIFT, as it applies to both the primary and secondary blend.
Values in the destination are premultiplied by their Alpha. This flag should not be shifted by BUF_BLEND_SHIFT, as it applies to both the primary and secondary blend.
The values obtained from the above formulas are divided by the resultant Alpha. This is generally desired for OVER/UNDER/XOR/PLUS blends, and generally not desired for the IN/OUT blends.
All four functions 0 for OK or a negative value on failure. In the case of ggiSetGCFlags, failures usually mean that the display does not support the desired blend or comparison. You can avoid such failures by insisting that the blend be available when the buffer is created with ggiBufAddAlpha/ggiBufCreateAlpha or ggiBufAddZ/ggiBufCreateZ.