I am trying to dynamically update the vertex buffer in a UWP project using SharpDX, once every time I call the following method, where context is the device context member.
public void UpdateVertexBuffer(ScatterVertex data)
{
DataBox dataBox =
this.context.MapSubresource(
scatterPointVertexBuffer,
0,
D3D11.MapMode.WriteNoOverwrite,
D3D11.MapFlags.None
);
var pointer = dataBox.DataPointer;
pointer = Utilities.WriteAndPosition(pointer, ref data);
this.context.UnmapSubresource(scatterPointVertexBuffer, 0);
}
I am expecting to keep the old data during the update process. However each time I call this method, the previous data is overwritten. I checked the pointer of dataBox.DataPointer and it remains the same value in every call.
Using DataStream as output doesn't help either. In either cases if I check the vertex buffer I get only one vertex.
But shouldn't the MapSubresource method protect the old data if I choose the WriteNoOverwrite mode?
What should I do to keep the previous data during update?