Added (dirty) VertexLayout

This commit is contained in:
Simon Lübeß
2020-12-01 19:57:59 +01:00
parent e7464118d6
commit 1c58d0986e
5 changed files with 157 additions and 97 deletions
@@ -155,5 +155,10 @@ namespace GlitchyEngine.Renderer
{
nativeContext.Rasterizer.SetViewports(viewportsCount, (.)viewports);
}
public override void SetVertexLayout(VertexLayout vertexLayout)
{
nativeContext.InputAssembler.SetInputLayout(vertexLayout.nativeLayout);
}
}
}
@@ -0,0 +1,47 @@
using System;
using DirectX.D3D11;
using System.Diagnostics;
using DirectX.Common;
using internal GlitchyEngine.Renderer;
namespace GlitchyEngine.Renderer
{
public extension VertexLayout
{
internal ID3D11InputLayout* nativeLayout ~ _?.Release();
public ID3DBlob* nativeShaderCode;
public this(GraphicsContext context, VertexElement[] ownElements, ID3DBlob* nativeShaderCode)
{
this.nativeShaderCode = nativeShaderCode;
_context = context;
_elements = ownElements;
CreateNativeLayout();
}
private void ToNativeLayout(VertexElement[] input, InputElementDescription[] output)
{
Debug.Assert(input.Count == output.Count);
for(int i < input.Count)
output[i] = .(input[i].SemanticName, input[i].SemanticIndex, input[i].Format, input[i].InputSlot, input[i].AlignedByteOffset, (.)input[i].InputSlotClass);
}
protected override void CreateNativeLayout()
{
var nativeElements = scope InputElementDescription[_elements.Count];
ToNativeLayout(_elements, nativeElements);
var result = _context.nativeDevice.CreateInputLayout(nativeElements.CArray(), (.)nativeElements.Count, nativeShaderCode.GetBufferPointer(), nativeShaderCode.GetBufferSize(), &nativeLayout);
if(result.Failed)
{
Log.EngineLogger.Error($"Failed to create D3D11 input layout: Message({(int)result}): {result}");
}
}
}
}