Added BlendState

This commit is contained in:
Simon Lübeß
2021-02-09 13:37:26 +01:00
parent 7e3bb932fc
commit abe4f66724
8 changed files with 170 additions and 4 deletions
+93
View File
@@ -0,0 +1,93 @@
using System;
using GlitchyEngine.Math;
namespace GlitchyEngine.Renderer
{
public struct BlendStateDescription
{
public typealias Blend = DirectX.D3D11.Blend;
public typealias BlendOperation = DirectX.D3D11.BlendOperation;
public typealias ColorWriteEnable = DirectX.D3D11.ColorWriteEnable;
public struct RenderTargetBlend
{
/**
* Enable (or disable) blending.
*/
public bool BlendEnable;
public Blend SourceBlend;
public Blend DestinationBlend;
public BlendOperation BlendOperation;
public Blend SourceBlendAlpha;
public Blend DestinationBlendAlpha;
public BlendOperation BlendOperationAlpha;
public ColorWriteEnable RenderTargetWriteMask;
public this()
{
this = default;
}
public this(bool blendEnable, Blend sourceBlend, Blend destinationBlend, BlendOperation blendOperation,
Blend sourceBlendAlpha, Blend destinationBlendAlpha, BlendOperation blendOperationAlpha, ColorWriteEnable renderTargetWriteMask)
{
BlendEnable = blendEnable;
SourceBlend = sourceBlend;
DestinationBlend = destinationBlend;
BlendOperation = blendOperation;
SourceBlendAlpha = sourceBlendAlpha;
DestinationBlendAlpha = destinationBlendAlpha;
BlendOperationAlpha = blendOperationAlpha;
RenderTargetWriteMask = renderTargetWriteMask;
}
public static readonly RenderTargetBlend Default = RenderTargetBlend(false, .One, .Zero, .Add, .One, .Zero, .Add, .All);
}
/**
* Specifies whether to enable independent blending in simultaneous render targets. Set to TRUE to enable independent blending.
* If set to FALSE, only the RenderTarget[0] members are used; RenderTarget[1..7] are ignored.
*/
public bool IndependentBlendEnable;
/**
* Specifies whether to use alpha-to-coverage as a multisampling technique when setting a pixel to a render target.
*/
public bool AlphaToCoverageEnable;
public RenderTargetBlend[8] RenderTarget;
public this()
{
this = default;
}
public this(bool independentBlend, bool alphaToCoverage, RenderTargetBlend[8] renderTarget)
{
IndependentBlendEnable = independentBlend;
AlphaToCoverageEnable = alphaToCoverage;
RenderTarget = renderTarget;
}
public static readonly Self Default = .(false, false, .(.Default, .Default, .Default, .Default, .Default, .Default, .Default, .Default));
}
public class BlendState : RefCounted
{
protected GraphicsContext _context ~ _?.ReleaseRef();
protected BlendStateDescription _desc;
public BlendStateDescription Description => _desc;
public this(GraphicsContext context, BlendStateDescription desc)
{
_context = context..AddRef();
_desc = desc;
PlatformCreateBlendState();
}
public extern void Bind(ColorRGBA blendFactor = .White);
protected extern void PlatformCreateBlendState();
}
}
+7 -1
View File
@@ -12,7 +12,13 @@ namespace GlitchyEngine.Renderer
get => _rendererAPI;
set => _rendererAPI = value;
}
[Inline]
public static void Init()
{
_rendererAPI.Init();
}
[Inline]
public static void Clear(RenderTarget renderTarget, ColorRGBA color)
{
+2
View File
@@ -28,6 +28,8 @@ namespace GlitchyEngine.Renderer
_objectConstants = new Buffer<ObjectConstants>(_context, .(0, .Constant, .Dynamic, .Write));
_objectConstants.Update();
RenderCommand.Init();
}
public static void BeginScene(Camera camera)
@@ -15,6 +15,8 @@ namespace GlitchyEngine.Renderer
*/
public static extern API Api { get; }
public extern void Init();
public extern void Clear(RenderTarget renderTarget, ColorRGBA clearColor);
public extern void DrawIndexed(GeometryBinding geometry);