I managed to draw from two Vertex Buffers by simply switching buffers in InputAssambler in the render function
VertexBufferBinding vb = new VertexBufferBinding(vertices
, Utilities.SizeOf<Vector4>()
+ Utilities.SizeOf<Vector4>()
+ Utilities.SizeOf<Vector2>()
, 0);
VertexBufferBinding vb2 = new VertexBufferBinding(vertices2
, Utilities.SizeOf<Vector4>()
+ Utilities.SizeOf<Vector4>()
+ Utilities.SizeOf<Vector2>()
, 0);
Then in render loop
RenderLoop.Run(form, () =>
{
context.ClearRenderTargetView(renderView, Color.Black);
....
context.InputAssembler.SetVertexBuffers(0, vb);
context.Draw(sectionsToDraw,0);
context.InputAssembler.SetVertexBuffers(0, vb2);
context.Draw(sectionsToDraw, 0);
....
}
Of course, with this solution also the layout can be simplified
var layout = new InputLayout(device, passSignature, new InputElement[]
{
new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0)
,new InputElement("COLOR", 0, Format.R32G32B32A32_Float
, InputElement.AppendAligned, 0)
,new InputElement("TEXCOORD", 0, Format.R32G32_Float
, InputElement.AppendAligned, 0)
}
but now, I am not sure if my solution does not involve copying the whole buffer every draw call. I have to read about it a bit more.
What I think is my problem is that I am using Directx 11, and I cannot find a partial Lock for buffer, like the one as I understand was in Directx 9. http://sharpdx.org/documentation/api/m-sharpdx-direct3d9-vertexbuffer-lock It looks like there is none in DirectX 11. I found that you can take MapSubresource of a resource, but according to MSDN "A buffer is defined as a single subresource". So, it is not possible to lock only a part of a buffer as I would like to.