Added Backbuffer to Swapchain + RenderCommand API changes

This commit is contained in:
Simon Lübeß
2021-10-15 22:40:42 +02:00
parent 90e654b750
commit ffafa380ea
14 changed files with 228 additions and 129 deletions
-2
View File
@@ -85,8 +85,6 @@ namespace GlitchyEngine.Renderer
PlatformCreateBlendState();
}
public extern void Bind(ColorRGBA blendFactor = .White);
protected extern void PlatformCreateBlendState();
}
}
+4 -13
View File
@@ -6,7 +6,8 @@ namespace GlitchyEngine.Renderer
{
public class GraphicsContext : RefCounter
{
private RasterizerState _currentRasterizerState;
private static GraphicsContext s_GraphicsContext;
public static GraphicsContext Get() => s_GraphicsContext;
public extern SwapChain SwapChain {get;}
@@ -30,8 +31,9 @@ namespace GlitchyEngine.Renderer
* @BindRenderTargets has to be called in order to bind the rendertargets.
* @param renderTarget The render target to set. If null, the backbuffer will be set.
* @param slot The slot to which the rendertarget will be bound. If 0 the depth buffer of the current render target will be set. If it has no depthbuffer the current will be unset.
* @param setDepthTarget If set to true the depth stencil target of the given renderTarget will be bound (only applies if slot is 0).
*/
public extern void SetRenderTarget(RenderTarget2D renderTarget, int slot = 0);
public extern void SetRenderTarget(RenderTarget2D renderTarget, int slot = 0, bool setDepthTarget = true);
/**
* Binds all.
@@ -80,19 +82,8 @@ namespace GlitchyEngine.Renderer
public extern void SetIndexBuffer(Buffer buffer, IndexFormat indexFormat = .Index16Bit, uint32 byteOffset = 0);
public void SetRasterizerState(RasterizerState rasterizerState)
{
_currentRasterizerState = rasterizerState;
SetRasterizerStateImpl();
}
protected extern void SetRasterizerStateImpl();
public RasterizerState GetRasterizerState()
{
return _currentRasterizerState;
}
internal void SetViewport(Viewport viewport)
{
var viewport;
+38 -4
View File
@@ -3,12 +3,21 @@ using GlitchyEngine.Math;
namespace GlitchyEngine.Renderer
{
/*
public enum DepthStencilClearFlag
{
None = 0,
Depth = 1,
Stencil = 2
}
*/
public enum ClearOptions
{
None = 0,
Color = 1,
Depth = 2,
Stencil = 4
}
public static class RenderCommand
{
@@ -32,14 +41,39 @@ namespace GlitchyEngine.Renderer
_rendererAPI.Clear(renderTarget, color);
}
public static void Clear(DepthStencilTarget depthTarget, float depthValue, uint8 stencilValue, DepthStencilClearFlag clearFlags)
public static void Clear(DepthStencilTarget target, ClearOptions options, float depth, uint8 stencil)
{
_rendererAPI.Clear(depthTarget, depthValue, stencilValue, clearFlags);
_rendererAPI.Clear(target, options, depth, stencil);
}
public static void Clear(RenderTarget2D renderTarget, float depthValue, uint8 stencilValue, DepthStencilClearFlag clearFlags)
public static void Clear(RenderTarget2D renderTarget, ClearOptions options, ColorRGBA color, float depth, uint8 stencil)
{
_rendererAPI.Clear(renderTarget, depthValue, stencilValue, clearFlags);
_rendererAPI.Clear(renderTarget, options, color, depth, stencil);
}
public static void SetRenderTarget(RenderTarget2D renderTarget, int slot = 0, bool setDepthBuffer = false)
{
_rendererAPI.SetRenderTarget(renderTarget, slot, setDepthBuffer);
}
public static void SetDepthStencilTarget(DepthStencilTarget target)
{
_rendererAPI.SetDepthStencilTarget(target);
}
public static void BindRenderTargets()
{
_rendererAPI.BindRenderTargets();
}
public static void SetRasterizerState(RasterizerState rasterizerState)
{
_rendererAPI.SetRasterizerState(rasterizerState);
}
public static void SetBlendState(BlendState blendState, ColorRGBA blendFactor = .White)
{
_rendererAPI.SetBlendState(blendState, blendFactor);
}
[Inline]
+22 -3
View File
@@ -17,11 +17,30 @@ namespace GlitchyEngine.Renderer
public extern void Init();
public extern void Clear(RenderTarget2D renderTarget, ColorRGBA clearColor);
public extern void Clear(RenderTarget2D renderTarget, ColorRGBA color);
public extern void Clear(DepthStencilTarget target, float depthValue, uint8 stencilValue, DepthStencilClearFlag clearFlags);
public extern void Clear(DepthStencilTarget target, ClearOptions options, float depth, uint8 stencil);
public extern void Clear(RenderTarget2D renderTarget, float depthValue, uint8 stencilValue, DepthStencilClearFlag clearFlags);
public void Clear(RenderTarget2D renderTarget, ClearOptions options, ColorRGBA color, float depth, uint8 stencil)
{
var actualRt = (renderTarget ?? GraphicsContext.Get().SwapChain.BackBuffer);
if(options.HasFlag(.Color))
Clear(actualRt, color);
if((options.HasFlag(.Depth) || options.HasFlag(.Stencil)) && actualRt.DepthStencilTarget != null)
Clear(actualRt.DepthStencilTarget, options, depth, stencil);
}
public extern void SetRenderTarget(RenderTarget2D renderTarget, int slot, bool setDepthBuffer);
public extern void SetDepthStencilTarget(DepthStencilTarget target);
public extern void BindRenderTargets();
public extern void SetRasterizerState(RasterizerState rasterizerState);
public extern void SetBlendState(BlendState blendState, ColorRGBA blendFactor);
public extern void DrawIndexed(GeometryBinding geometry);
+58 -5
View File
@@ -2,22 +2,75 @@ namespace GlitchyEngine.Renderer
{
public class SwapChain
{
private GraphicsContext _context;
private bool _changed;
private uint32 _width, _height;
private Viewport _backBufferViewport;
public extern GraphicsContext Context {get;}
private DepthStencilFormat _depthStencilFormat = .None;
public RenderTarget2D _backBuffer ~ _?.ReleaseRef();
public GraphicsContext Context => _context;
/**
* Gets or Sets the backbuffers width.
* @remarks @ApplyChanges() needs to be called in order to apply the ganges.
* @remarks @ApplyChanges() needs to be called in order to apply the changes.
*/
public extern uint32 Width {get; set;}
public uint32 Width
{
get => _width;
set
{
if(_width == value)
return;
_width = value;
_changed = true;
}
}
/**
* Gets or Sets the backbuffers height.
* @remarks @ApplyChanges() needs to be called in order to apply the ganges.
* @remarks @ApplyChanges() needs to be called in order to apply the changes.
*/
public extern uint32 Height {get; set;}
public uint32 Height
{
get => _height;
set
{
if(_height == value)
return;
_height = value;
_changed = true;
}
}
public Viewport BackbufferViewport => _backBufferViewport;
/**
* Gets or Sets the format of the depth stencil buffer.
* If set to DepthStencilFormat.None DepthStencilTarget will be null.
* @remarks @ApplyChanges() needs to be called in order to apply the changes.
*/
public DepthStencilFormat DepthStencilFormat
{
get => _depthStencilFormat;
set
{
if(_depthStencilFormat == value)
return;
_depthStencilFormat = value;
_changed = true;
}
}
public RenderTarget2D BackBuffer => _backBuffer;
public extern void Init();