Added Context, Bind and Unbind to GeometryBinding

This commit is contained in:
Simon Lübeß
2021-01-06 19:29:27 +01:00
parent 9eb4a19df1
commit 1fe678103e
3 changed files with 21 additions and 4 deletions
+2 -2
View File
@@ -136,7 +136,7 @@ namespace GlitchyEngine
_indexBuffer = new IndexBuffer(Window.Context, (.)indices.Count, .Immutable);
_indexBuffer.SetData(indices);
_geometryBinding = new GeometryBinding();
_geometryBinding = new GeometryBinding(_window.Context);
_geometryBinding.SetVertexBufferSlot(_vertexBuffer, 0);
_geometryBinding.SetVertexLayout(_vertexLayout);
_geometryBinding.SetPrimitiveTopology(.TriangleList);
@@ -175,7 +175,7 @@ namespace GlitchyEngine
_window.Context.SetRenderTarget(null);
_window.Context.BindRenderTargets();
_geometryBinding.Bind(_window.Context);
_geometryBinding.Bind();
_window.Context.SetVertexShader(_vertexShader);
@@ -73,8 +73,11 @@ namespace GlitchyEngine.Renderer
}
public void Bind(GraphicsContext context)
public override void Bind(GraphicsContext context = null)
{
var context;
context ??= _context;
context.nativeContext.InputAssembler.SetVertexBuffers(0, nativeBuffers.Count, &nativeBuffers, &bufferStrides, &bufferOffsets);
context.nativeContext.InputAssembler.SetInputLayout(_vertexLayout.nativeLayout);
context.nativeContext.InputAssembler.SetPrimitiveTopology((.)_primitiveTopology);
@@ -82,8 +85,11 @@ namespace GlitchyEngine.Renderer
context.nativeContext.InputAssembler.SetIndexBuffer(_indexBuffer.nativeBuffer, _indexBuffer.Format == .Index32Bit ? .R32_UInt : .R16_UInt, _indexByteOffset);
}
public void Unbind(GraphicsContext context)
public void Unbind(GraphicsContext context = null)
{
var context;
context ??= _context;
ID3D11Buffer*[nativeBuffers.Count] nullBuffers = .();
uint32[nativeBuffers.Count] zeroStrides = .();
uint32[nativeBuffers.Count] zeroOffsets = .();
@@ -5,6 +5,8 @@ namespace GlitchyEngine.Renderer
{
public class GeometryBinding
{
internal GraphicsContext _context;
internal List<VertexBufferBinding> _vertexBuffers = new .() ~ delete _;
internal IndexBuffer _indexBuffer;
internal VertexLayout _vertexLayout;
@@ -12,6 +14,11 @@ namespace GlitchyEngine.Renderer
internal uint32 _indexCount;
internal PrimitiveTopology _primitiveTopology;
public this(GraphicsContext context)
{
_context = context;
}
public VertexBufferBinding GetVertexBuffer(uint32 slot)
{
return _vertexBuffers[slot];
@@ -79,5 +86,9 @@ namespace GlitchyEngine.Renderer
}
protected extern void PlatformSetIndexBuffer(IndexBuffer indexBuffer);
public extern void Bind(GraphicsContext context = null);
public extern void Unbind(GraphicsContext context = null);
}
}