MGL_blendFuncType

Declaration

typedef enum {
MGL_BLEND_NONE,
MGL_BLEND_ZERO,
MGL_BLEND_ONE,
MGL_BLEND_SRCCOLOR,
MGL_BLEND_ONEMINUSSRCCOLOR,
MGL_BLEND_SRCALPHA,
MGL_BLEND_ONEMINUSSRCALPHA,
MGL_BLEND_DSTALPHA,
MGL_BLEND_ONEMINUSDSTALPHA,
MGL_BLEND_DSTCOLOR,
MGL_BLEND_ONEMINUSDSTCOLOR,
MGL_BLEND_SRCALPHASATURATE,
MGL_BLEND_CONSTANTCOLOR,
MGL_BLEND_ONEMINUSCONSTANTCOLOR,
MGL_BLEND_CONSTANTALPHA,
MGL_BLEND_ONEMINUSCONSTANTALPHA,
MGL_BLEND_SRCALPHAFAST,
MGL_BLEND_CONSTANTALPHAFAST
} MGL_blendFuncType

Prototype In

mgraph.h

Description

Flags for 2D alpha blending functions supported by the SciTech MGL. The values in here define the the alpha blending functions passed to the MGL_setBlendFunc function. Essentially the blend function defines how to combine the source and destination pixel colors together to get the resulting destination color during rendering. The formula used for this is defined as:

DstColor = SrcColor * SrcFunc + DstColor * DstFunc;

If the source alpha blending function is set to MGL_BLEND_CONSTANTALPHA, the SrcFunc above becomes:

SrcFunc = ConstAlpha

If the destination alpha blending function is set to MGL_BLEND_ONEMINUSDSTALPHA then DstFunc above becomes:

DstFunc = (1-DstAlpha)

and the final equation becomes (note that each color channel is multiplied individually):

DstColor = SrcColor * ConstAlpha + DstColor * (1-DstAlpha)

Although the above is a completely contrived example, it does illustrate how the functions defined below combine to allow you to build complex and interesting blending functions. For simple source alpha transparency, the following formula is usually used:

DstColor = SrcColor * SrcAlpha + DstColor * (1-SrcAlpha)

If you wish to use this type of blending and you do not care about the resulting alpha channel information, you can set the optimised MGL_BLEND_SRCALPHAFAST blending mode. If you set both the source and destination blending modes to this value, the above formula will be used but an optimised fast path will be taken internally to make this run as fast as possible. For normal blending operations this will be much faster than setting the above formula manually. If however you need the destination alpha to be preserved, you will need to use the slower method instead.

For simple constant alpha transparency, the following formula is usually used:

DstColor = SrcColor * ConstantAlpha + DstColor * (1-ConstantAlpha)

If you wish to use this type of blending and you do not care about the resulting alpha channel information, you can set the optimised MGL_BLEND_CONSTANTALPHAFAST blending mode. If you set both the source and destination blending modes to this value, the above formula will be used but an optimised fast path will be taken internally to make this run as fast as possible. For normal blending operations this will be much faster than setting the above formula manually. If however you need the destination alpha to be preserved, you will need to use the slower method instead.

Note: All the above equations assume the color values and alpha values are in the range of 0 through 1 in floating point. In reality all blending is done with integer color and alpha components in the range of 0 to 255, when a value of 255 corresponds to a value of 1.0 in the above equations.

Note: The constant color value set by a call to MGL_setColor, and the constant alpha value set by a call to MGL_setAlphaValue.

Note: Setting a blending function that uses the destination alpha components is only supported if the framebuffer currently supports destination alpha. Likewise setting a blending function that uses source alpha components is only supported if the framebuffer or incoming bitmap data contains an alpha channel. The results are undefined if these conditiions are not met.

Note: Enabling source or destination alpha blending overrides the setting of the current write mode. Logical write modes and blending cannot be used at the same time.

Members

MGL_BLEND_NONE | No alpha blending
MGL_BLEND_ZERO | Blend factor is always zero
MGL_BLEND_ONE | Blend factor is always one
MGL_BLEND_SRCCOLOR | Blend factor is source color
MGL_BLEND_ONEMINUSSRCCOLOR | Blend factor is 1-source color
MGL_BLEND_SRCALPHA | Blend factor is source alpha
MGL_BLEND_ONEMINUSSRCALPHA | Blend factor is 1-source alpha
MGL_BLEND_DSTALPHA | Blend factor is destination alpha
MGL_BLEND_ONEMINUSDSTALPHA | Blend factor is 1-destination alpha
MGL_BLEND_DSTCOLOR | Blend factor is destination color
MGL_BLEND_ONEMINUSDSTCOLOR | Blend factor is 1-destination color
MGL_BLEND_SRCALPHASATURATE | Blend factor is src alpha saturation
MGL_BLEND_CONSTANTCOLOR | Blend factor is a constant color
MGL_BLEND_ONEMINUSCONSTANTCOLOR | Blend factor is 1-constant color
MGL_BLEND_CONSTANTALPHA | Blend factor is constant alpha
MGL_BLEND_ONEMINUSCONSTANTALPHA | Blend factor is 1-constant alpha
MGL_BLEND_SRCALPHAFAST | Common case of optimised src alpha
MGL_BLEND_CONSTANTALPHAFAST | Common case of optimised constant alpha

Copyright © 2002 SciTech Software, Inc. Visit our web site at http://www.scitechsoft.com