// Copyright (c) Amer Koleci and contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
using static Win32.Graphics.Direct3D12.Apis;
namespace Win32.Graphics.Direct3D12;
public unsafe partial struct BlendDescription
{
///
/// A built-in description with settings for opaque blend, that is overwriting the source with the destination data.
///
public static readonly BlendDescription Opaque = new(Blend.One, Blend.Zero);
///
/// A built-in description with settings for alpha blend, that is blending the source and destination data using alpha.
///
public static readonly BlendDescription AlphaBlend = new(Blend.One, Blend.InverseSrcAlpha);
///
/// A built-in description with settings for additive blend, that is adding the destination data to the source data without using alpha.
///
public static readonly BlendDescription Additive = new(Blend.SrcAlpha, Blend.One);
///
/// A built-in description with settings for blending with non-premultipled alpha, that is blending source and destination data using alpha while assuming the color data contains no alpha information.
///
public static readonly BlendDescription NonPremultiplied = new(Blend.SrcAlpha, Blend.InverseSrcAlpha);
///
/// Initializes a new instance of the struct.
///
/// The source blend.
/// The destination blend.
public BlendDescription(Blend srcBlend, Blend destBlend)
: this()
{
AlphaToCoverageEnable = false;
IndependentBlendEnable = false;
for (int i = 0; i < D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT; i++)
{
RenderTarget[i].BlendEnable = srcBlend != Blend.One || destBlend != Blend.Zero;
RenderTarget[i].LogicOp = LogicOperation.Noop;
RenderTarget[i].SrcBlend = srcBlend;
RenderTarget[i].DestBlend = destBlend;
RenderTarget[i].BlendOp = BlendOperation.Add;
RenderTarget[i].SrcBlendAlpha = srcBlend;
RenderTarget[i].DestBlendAlpha = destBlend;
RenderTarget[i].BlendOpAlpha = BlendOperation.Add;
RenderTarget[i].RenderTargetWriteMask = ColorWriteEnable.All;
}
}
}