Create dynamic buffer SharpDX
- by fedab
I want to set a buffer that is updated every frame but can't figure it out, what i have to do.
The only working thing i have is this:
mdexcription = new BufferDescription(Matrix.SizeInBytes * Matrices.Length, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, 0);
instanceBuffer = SharpDX.Direct3D11.Buffer.Create(Device, Matrices, mdexcription);
vBB = new VertexBufferBinding(instanceBuffer, Matrix.SizeInBytes, 0);
DeviceContext.InputAssembler.SetVertexBuffers(1, vBB);
Draw:
//Change Matrices (Matrix[]) every frame...
instanceBuffer.Dispose();
instanceBuffer = SharpDX.Direct3D11.Buffer.Create(Device, Matrices, mdexcription);
vBB = new VertexBufferBinding(instanceBuffer, Matrix.SizeInBytes, 0);
DeviceContext.InputAssembler.SetVertexBuffers(1, vBB);
I guess Dispose() and creating a new buffer is slow and can be done much faster.
I've read about DataStream but i do not know, how to set this up properly.
What steps do i have to do to set up a DataStream to achieve fast every-frame update?