A blending stage is a set of texture operations, together with their arguments, that define how textures are blended. When making a blending stage, applications invoke the IDirect3DDevice3::SetTextureStageState function. The first call specifies the operation that will be performed. Two additional invocations define the arguments to which the operation will be applied. The following code fragment illustrates the creation of a blending stage:
// This example assumes that lpD3DDev is a valid pointer to an
// IDirect3DDevice3 interface.
// Set the operation for the 1st texture.
lpD3DDev->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_ADD);
// Set arg1 for the texture operation.
lpD3DDev->SetTextureStageState(0, // First texture
D3DTSS_COLORARG1, // Set color arg 1
D3DTA_TEXTURE); // Color arg 1 value
// Set arg2 for the texture operation.
lpD3DDev->SetTextureStageState(0, // First texture
D3DTSS_COLORARG2, // Set color arg 2
D3DTA_DIFFUSE); // Color arg 2 value
Texel data in textures contain color and alpha values. Programs can define separate operations for both color and alpha values in a single blending stage. Each operation (color and alpha) has its own arguments. For details, see D3DTEXTURESTAGESTATETYPE.
Although not part of the Direct3D API, the following macros can also be inserted into your program to abbreviate the code required for creating texture blending stage.
#define SetTextureColorStage( dev, i, arg1, op, arg2 ) \
dev->SetTextureStageState( i, D3DTSS_COLOROP, op); \
dev->SetTextureStageState( i, D3DTSS_COLORARG1, arg1 ); \
dev->SetTextureStageState( i, D3DTSS_COLORARG2, arg2 );
#define SetTextureAlphaStage( dev, i, arg1, op, arg2 ) \
dev->SetTextureStageState( i, D3DTSS_ALPHAOP, op); \
dev->SetTextureStageState( i, D3DTSS_ALPHARG1, arg1 ); \
dev->SetTextureStageState( i D3DTSS_ALPHARG2, arg2 );