Reworked RenderTarget2D and corresponding API

This commit is contained in:
Simon Lübeß
2021-09-21 16:30:34 +02:00
parent 8e39d7988b
commit 229d2b578e
11 changed files with 178 additions and 36 deletions
@@ -6,7 +6,8 @@ namespace GlitchyEngine.Renderer
D16_UNorm,
D24_UNorm_S8_UInt,
D32_Float,
D32_Float_S8X24_UInt
D32_Float_S8X24_UInt,
None
}
// TODO: add all features.
@@ -23,6 +24,8 @@ namespace GlitchyEngine.Renderer
public this(GraphicsContext context, uint32 width, uint32 height, DepthStencilFormat format = .D32_Float)
{
Log.EngineLogger.Assert(format != .None, "DepthStencilFormat None is only valid for RenderTarget");
_context = context..AddRef();
_width = width;
_height = height;
@@ -16,12 +16,10 @@ namespace GlitchyEngine.Renderer
public extern void Init();
/**
* Sets a rendertarget.
* @param renderTarget The render target.
* @param slot The slot to which the rendertarget will be bound.
* @remarks When @RenderTarget is null the backbuffer will be bound.
* @BindRenderTargets has to be called in order to bind the rendertargets.
/** @brief Sets a rendertarget to the given slot.
* @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.
*/
public extern void SetRenderTarget(RenderTarget2D renderTarget, int slot = 0);
+8 -5
View File
@@ -9,7 +9,7 @@ namespace GlitchyEngine.Renderer
Depth = 1,
Stencil = 2
}
public static class RenderCommand
{
private static RendererAPI _rendererAPI;
@@ -31,12 +31,15 @@ namespace GlitchyEngine.Renderer
{
_rendererAPI.Clear(renderTarget, color);
}
[Inline]
public static void Clear(DepthStencilTarget target, float depthValue, uint8 stencilValue, DepthStencilClearFlag clearFlags)
public static void Clear(DepthStencilTarget depthTarget, float depthValue, uint8 stencilValue, DepthStencilClearFlag clearFlags)
{
_rendererAPI.Clear(target, depthValue, stencilValue, clearFlags);
_rendererAPI.Clear(depthTarget, depthValue, stencilValue, clearFlags);
}
public static void Clear(RenderTarget2D renderTarget, float depthValue, uint8 stencilValue, DepthStencilClearFlag clearFlags)
{
_rendererAPI.Clear(renderTarget, depthValue, stencilValue, clearFlags);
}
[Inline]
+72 -14
View File
@@ -1,25 +1,83 @@
using System;
namespace GlitchyEngine.Renderer
{
public class RenderTarget2D : Texture2D
public struct RenderTarget2DDescription
{
public this(GraphicsContext context, uint32 width, uint32 height, Format format, uint32 arraySize = 1, uint32 mipLevels = 1, CPUAccessFlags cpuAccess = .None)
: base(context)
public uint32 Width;
public uint32 Height;
public uint32 ArraySize;
public uint32 MipLevels;
public Format PixelFormat;
public CPUAccessFlags CpuAccess;
public uint32 SampleCount;
public uint32 SampleQuality;
public DepthStencilFormat DepthStencilFormat;
public bool IsSwapchainTarget;
public this(Format pixelFormat, uint32 width, uint32 height, uint32 arraySize = 1, uint32 mipLevels = 1,
DepthStencilFormat depthStencilFormat = .None, CPUAccessFlags cpuAccess = .None, uint32 sampleCount = 1, uint32 sampleQuality = 0, bool isSwapchainTarget = false)
{
Texture2DDesc desc;
PixelFormat = pixelFormat;
Width = width;
Height = height;
ArraySize = arraySize;
MipLevels = mipLevels;
CpuAccess = cpuAccess;
DepthStencilFormat = depthStencilFormat;
desc.Width = width;
desc.Height = height;
desc.Format = format;
desc.ArraySize = arraySize;
desc.MipLevels = mipLevels;
// RenderTargets only can do default (I think)
desc.Usage = .Default;
desc.CpuAccess = cpuAccess;
SampleCount = sampleCount;
SampleQuality = sampleQuality;
CreateRenderTargetPlatform(desc);
IsSwapchainTarget = isSwapchainTarget;
}
}
public class RenderTarget2D : RefCounted
{
internal GraphicsContext _context;
private RenderTarget2DDescription _description;
public RenderTarget2DDescription Description => _description;
public uint32 Width => _description.Width;
public uint32 Height => _description.Height;
protected internal DepthStencilTarget _depthStenilTarget ~ _?.ReleaseRef();
protected extern void CreateRenderTargetPlatform(Texture2DDesc desc);
// TODO: DepthStencilTarget is just a renderTarget
public DepthStencilTarget DepthStencilTarget => _depthStenilTarget;
protected SamplerState _samplerState ~ _?.ReleaseRef();
public SamplerState SamplerState
{
get => _samplerState;
set
{
if(_samplerState == value)
return;
SetReference!(_samplerState, value);
}
}
public this(GraphicsContext context, RenderTarget2DDescription description)
{
_context = context;
_description = description;
ApplyChanges();
}
/// Recreates the render target using the current description
public void ApplyChanges()
{
PlatformApplyChanges();
}
public extern void Resize(uint32 width, uint32 height);
protected extern void PlatformApplyChanges();
}
}
@@ -20,6 +20,8 @@ namespace GlitchyEngine.Renderer
public extern void Clear(RenderTarget2D renderTarget, ColorRGBA clearColor);
public extern void Clear(DepthStencilTarget target, float depthValue, uint8 stencilValue, DepthStencilClearFlag clearFlags);
public extern void Clear(RenderTarget2D renderTarget, float depthValue, uint8 stencilValue, DepthStencilClearFlag clearFlags);
public extern void DrawIndexed(GeometryBinding geometry);