using Ryujinx.Graphics.GAL;
namespace Ryujinx.Graphics.Gpu.Engine.Threed.Blender
{
///
/// Fixed function alpha state used for a advanced blend function.
///
readonly struct FixedFunctionAlpha
{
///
/// Fixed function alpha state with alpha blending disabled.
///
public static FixedFunctionAlpha Disabled => new(BlendUcodeEnable.EnableRGBA, default, default, default);
///
/// Individual enable bits for the RGB and alpha components.
///
public BlendUcodeEnable Enable { get; }
///
/// Alpha blend operation.
///
public BlendOp AlphaOp { get; }
///
/// Value multiplied with the blend source operand.
///
public BlendFactor AlphaSrcFactor { get; }
///
/// Value multiplied with the blend destination operand.
///
public BlendFactor AlphaDstFactor { get; }
///
/// Creates a new blend fixed function alpha state.
///
/// Individual enable bits for the RGB and alpha components
/// Alpha blend operation
/// Value multiplied with the blend source operand
/// Value multiplied with the blend destination operand
public FixedFunctionAlpha(BlendUcodeEnable enable, BlendOp alphaOp, BlendFactor alphaSrc, BlendFactor alphaDst)
{
Enable = enable;
AlphaOp = alphaOp;
AlphaSrcFactor = alphaSrc;
AlphaDstFactor = alphaDst;
}
///
/// Creates a new blend fixed function alpha state.
///
/// Alpha blend operation
/// Value multiplied with the blend source operand
/// Value multiplied with the blend destination operand
public FixedFunctionAlpha(BlendOp alphaOp, BlendFactor alphaSrc, BlendFactor alphaDst) : this(BlendUcodeEnable.EnableRGB, alphaOp, alphaSrc, alphaDst)
{
}
}
///
/// Blend microcode assembly function delegate.
///
/// Assembler
/// Fixed function alpha state for the microcode
delegate FixedFunctionAlpha GenUcodeFunc(ref UcodeAssembler asm);
///
/// Advanced blend microcode state.
///
readonly struct AdvancedBlendUcode
{
///
/// Advanced blend operation.
///
public AdvancedBlendOp Op { get; }
///
/// Advanced blend overlap mode.
///
public AdvancedBlendOverlap Overlap { get; }
///
/// Whenever the source input is pre-multiplied.
///
public bool SrcPreMultiplied { get; }
///
/// Fixed function alpha state.
///
public FixedFunctionAlpha Alpha { get; }
///
/// Microcode.
///
public uint[] Code { get; }
///
/// Constants used by the microcode.
///
public RgbFloat[] Constants { get; }
///
/// Creates a new advanced blend state.
///
/// Advanced blend operation
/// Advanced blend overlap mode
/// Whenever the source input is pre-multiplied
/// Function that will generate the advanced blend microcode
public AdvancedBlendUcode(
AdvancedBlendOp op,
AdvancedBlendOverlap overlap,
bool srcPreMultiplied,
GenUcodeFunc genFunc)
{
Op = op;
Overlap = overlap;
SrcPreMultiplied = srcPreMultiplied;
UcodeAssembler asm = new();
Alpha = genFunc(ref asm);
Code = asm.GetCode();
Constants = asm.GetConstants();
}
}
}