mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Added rudimentary DepthStencilTarget
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
using DirectX.D3D11;
|
||||
using internal GlitchyEngine.Renderer;
|
||||
|
||||
namespace GlitchyEngine.Renderer
|
||||
{
|
||||
extension DepthStencilTarget
|
||||
{
|
||||
internal ID3D11DepthStencilView* nativeView ~ _?.Release();
|
||||
|
||||
protected override void PlatformCreate()
|
||||
{
|
||||
Texture2DDescription desc = .();
|
||||
desc.Format = .D32_Float;
|
||||
desc.ArraySize = 1;
|
||||
desc.BindFlags = .DepthStencil;
|
||||
desc.Width = _width;
|
||||
desc.Height = _height;
|
||||
desc.SampleDesc = .(1, 0);
|
||||
|
||||
ID3D11Texture2D* tex = ?;
|
||||
_context.nativeDevice.CreateTexture2D(ref desc, null, &tex);
|
||||
|
||||
_context.nativeDevice.CreateDepthStencilView(tex, null, &nativeView);
|
||||
|
||||
tex.Release();
|
||||
}
|
||||
|
||||
public override void Bind()
|
||||
{
|
||||
_context.SetDepthStencilTarget(this);
|
||||
}
|
||||
|
||||
public override void Clear(float depthValue, uint8 stencilValue, DepthStencilClearFlag clearFlags)
|
||||
{
|
||||
_context.nativeContext.ClearDepthStencilView(nativeView, (.)clearFlags, depthValue, stencilValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -92,8 +92,14 @@ namespace GlitchyEngine.Renderer
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private ID3D11DepthStencilView* _depthStencilTarget;
|
||||
private ID3D11RenderTargetView*[MaxRTVCount] _renderTargets;
|
||||
|
||||
internal void SetDepthStencilTarget(DepthStencilTarget target)
|
||||
{
|
||||
_depthStencilTarget = target?.nativeView;
|
||||
}
|
||||
|
||||
public override void SetRenderTarget(RenderTarget renderTarget, int slot = 0)
|
||||
{
|
||||
@@ -109,7 +115,7 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
public override void BindRenderTargets()
|
||||
{
|
||||
nativeContext.OutputMerger.SetRenderTargets(MaxRTVCount, &_renderTargets, null);
|
||||
nativeContext.OutputMerger.SetRenderTargets(MaxRTVCount, &_renderTargets, _depthStencilTarget);
|
||||
}
|
||||
|
||||
public override void ClearRenderTarget(RenderTarget renderTarget, ColorRGBA color)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using GlitchyEngine.Math;
|
||||
|
||||
using internal GlitchyEngine.Renderer;
|
||||
|
||||
namespace GlitchyEngine.Renderer
|
||||
{
|
||||
extension RendererAPI
|
||||
@@ -24,6 +26,11 @@ namespace GlitchyEngine.Renderer
|
||||
_context.ClearRenderTarget(renderTarget, clearColor);
|
||||
}
|
||||
|
||||
public override void Clear(DepthStencilTarget target, float depthValue, uint8 stencilValue, DepthStencilClearFlag clearFlags)
|
||||
{
|
||||
_context.nativeContext.ClearDepthStencilView(target.nativeView, (.)clearFlags, depthValue, stencilValue);
|
||||
}
|
||||
|
||||
public override void DrawIndexed(GeometryBinding geometry)
|
||||
{
|
||||
_context.DrawIndexed(geometry.IndexCount, geometry.IndexByteOffset, 0);
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
namespace GlitchyEngine.Renderer
|
||||
{
|
||||
// TODO: add all features.
|
||||
public class DepthStencilTarget : RefCounted
|
||||
{
|
||||
protected internal GraphicsContext _context ~ _?.ReleaseRef();
|
||||
|
||||
protected uint32 _width, _height;
|
||||
|
||||
public uint32 Width => _width;
|
||||
public uint32 Height => _height;
|
||||
|
||||
public this(GraphicsContext context, uint32 width, uint32 height)
|
||||
{
|
||||
_context = context..AddRef();
|
||||
_width = width;
|
||||
_height = height;
|
||||
|
||||
PlatformCreate();
|
||||
}
|
||||
|
||||
protected extern void PlatformCreate();
|
||||
|
||||
public extern void Bind();
|
||||
|
||||
public extern void Clear(float depthValue, uint8 stencilValue, DepthStencilClearFlag clearFlags);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,13 @@ using GlitchyEngine.Math;
|
||||
|
||||
namespace GlitchyEngine.Renderer
|
||||
{
|
||||
public enum DepthStencilClearFlag
|
||||
{
|
||||
None = 0,
|
||||
Depth = 1,
|
||||
Stencil = 2
|
||||
}
|
||||
|
||||
public static class RenderCommand
|
||||
{
|
||||
private static RendererAPI _rendererAPI;
|
||||
@@ -24,6 +31,13 @@ namespace GlitchyEngine.Renderer
|
||||
{
|
||||
_rendererAPI.Clear(renderTarget, color);
|
||||
}
|
||||
|
||||
|
||||
[Inline]
|
||||
public static void Clear(DepthStencilTarget target, float depthValue, uint8 stencilValue, DepthStencilClearFlag clearFlags)
|
||||
{
|
||||
_rendererAPI.Clear(target, depthValue, stencilValue, clearFlags);
|
||||
}
|
||||
|
||||
[Inline]
|
||||
public static void DrawIndexed(GeometryBinding geometry)
|
||||
|
||||
@@ -19,6 +19,8 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
public extern void Clear(RenderTarget renderTarget, ColorRGBA clearColor);
|
||||
|
||||
public extern void Clear(DepthStencilTarget target, float depthValue, uint8 stencilValue, DepthStencilClearFlag clearFlags);
|
||||
|
||||
public extern void DrawIndexed(GeometryBinding geometry);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user