Skip to content

TSdlBlendMode

A set of blend modes used in drawing operations.

These predefined blend modes are supported everywhere.

Additional values may be obtained from TSdlBlendMode.Compose.

Definition

Unit: Neslib.Sdl3.Video

type TSdlBlendMode = (None, Blend, BlendPremultiplied, Add, AddPremultiplied, Modulate, Multiply, Invalid)

See Also

Enumeration Values

None = SDL_BLENDMODE_NONE

No blending: dstRGBA = srcRGBA


Blend = SDL_BLENDMODE_BLEND

Alpha blending: dstRGB = (srcRGB * srcA) + (dstRGB * (1-srcA)), dstA = srcA + (dstA * (1-srcA))


BlendPremultiplied = SDL_BLENDMODE_BLEND_PREMULTIPLIED

Pre-multiplied alpha blending: dstRGBA = srcRGBA + (dstRGBA * (1-srcA))


Add = SDL_BLENDMODE_ADD

Additive blending: dstRGB = (srcRGB * srcA) + dstRGB, dstA = dstA


AddPremultiplied = SDL_BLENDMODE_ADD_PREMULTIPLIED

Pre-multiplied additive blending: dstRGB = srcRGB + dstRGB, dstA = dstA


Modulate = SDL_BLENDMODE_MOD

Color modulate: dstRGB = srcRGB * dstRGB, dstA = dstA


Multiply = SDL_BLENDMODE_MUL

Color multiply: dstRGB = (srcRGB * dstRGB) + (dstRGB * (1-srcA)), dstA = dstA


Invalid = SDL_BLENDMODE_INVALID


Methods

Name Description
Compose Compose a custom blend mode for renderers.

Method Descriptions

Compose(TSdlBlendFactor, TSdlBlendFactor, TSdlBlendOperation, TSdlBlendFactor, TSdlBlendFactor, TSdlBlendOperation)

Compose a custom blend mode for renderers.

The properties TSdlRenderer.DrawBlendMode and TSdlTexture.BlendMode accept the TSdlBlendMode returned by this function if the renderer supports it.

A blend mode controls how the pixels from a drawing operation (source) get combined with the pixels from the render target (destination). First, the components of the source and destination pixels get multiplied with their blend factors. Then, the blend operation takes the two products and calculates the result that will get stored in the render target.

Expressed in pseudocode, it would look like this:

  DstRgb := ColorOperation(SrcRgb * SrcColorFactor, DstRgb * DstColorFactor);
  DstA := AlphaOperation(SrcA * SrcAlphaFactor, DstA * DstAlphaFactor);

Where the functions ColorOperation(Src, Dst) and AlphaOperation(Src, Dst) can return one of the following:

  • Src + Dst
  • Src - Dst
  • Dst - Src
  • Min(Src, Dst)
  • Max(Src, Dst)

The red, green, and blue components are always multiplied with the first, second, and third components of the TSdlBlendFactor, respectively. The fourth component is not used.

The alpha component is always multiplied with the fourth component of the TSdlBlendFactor. The other components are not used in the alpha calculation.

Support for these blend modes varies for each renderer. To check if a specific TSdlBlendMode is supported, create a renderer and assign it to either TSdlRenderer.DrawBlendMode or TSdlTexture.BlendMode. They will raise an error if the blend mode is not supported.

This list describes the support of custom blend modes for each renderer. All renderers support the four blend modes listed in the SDL_BlendMode enumeration.

  • Direct3D: Supports all operations with all factors. However, some factors produce unexpected results with TSdlBlendOperation.Minimum and TSdlBlendOperation.Maximum.
  • Direct3D11: Same as Direct3D 9.
  • OpenGL: Supports the TSdlBlendOperation.Add operation with all factors. OpenGL versions 1.1, 1.2, and 1.3 do not work correctly here.
  • OpenGL-ES2: Supports the TSdlBlendOperation.Add, TSdlBlendOperation.Subtract, TSdlBlendOperation.RevSubtract operations with all factors.
  • Software: No custom blend mode support.

Some renderers do not provide an alpha component for the default render target. The TSdlBlendFactor.DstAlpha and TSdlBlendFactor.OneMinusDstAlpha factors do not have an effect in this case.

class function Compose(const ASrcColorFactor, ADstColorFactor: TSdlBlendFactor; const AColorOperation: TSdlBlendOperation; const ASrcAlphaFactor, ADstAlphaFactor: TSdlBlendFactor; const AAlphaOperation: TSdlBlendOperation): TSdlBlendMode; inline; static

Parameters

ASrcColorFactor: TSdlBlendFactor : The blend factor applied to the red, green, and blue components of the source pixels.

ADstColorFactor: TSdlBlendFactor : The blend factor applied to the red, green, and blue components of the destination pixels.

AColorOperation: TSdlBlendOperation : The blend operation used to combine the red, green, and blue components of the source and destination pixels.

ASrcAlphaFactor: TSdlBlendFactor : The blend factor applied to the alpha component of the source pixels.

ADstAlphaFactor: TSdlBlendFactor : The blend factor applied to the alpha component of the destination pixels.

AAlphaOperation: TSdlBlendOperation : The blend operation used to combine the alpha component of the source and destination pixels.

Returns

TSdlBlendMode: A TSdlBlendMode that represents the chosen factors and operations.

See Also

Remarks

It is safe to call this method from any thread.