I'm using this code to modify a vertex buffer and works fine:
DataStream stream = new DataStream(3 * 32, true, true);
stream.WriteRange(new[] {
new Vector4(0.0f, 0.5f, 0.5f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
new Vector4(0.5f, -0.5f, 0.5f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
new Vector4(-0.5f, -0.5f, 0.5f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f)
});
stream.Position = 0;
vertices = new SlimDX.Direct3D11.Buffer(D3D11Context.Device, stream, new BufferDescription()
{
BindFlags = BindFlags.VertexBuffer,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.None,
SizeInBytes = 3 * 32,
Usage = ResourceUsage.Default
});
//I rewrite the stream with different values just to overwrite it
stream.Position = 0;
stream.WriteRange(new[] {
new Vector4(-0.3f, 0.5f, 0.5f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
new Vector4(0.5f, -0.5f, 0.8f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
new Vector4(-0.5f, -0.5f, 0.5f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f)
});
//Create new Databox
stream.Position = 0;
DataBox databox = new DataBox(32, 32 * 3, stream);
//Commit changes
D3D11Context.deviceContext.UpdateSubresource(databox, vertices, 0);
But if i somewhat try to reuse the Databox changing its data directly it doesn't work (i get no render this time):
//Modify same databox for reuse
databox.Data.Position = 0;
databox.Data.WriteRange(new[] {
new Vector4(-0.3f, 0.5f, 0.5f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
new Vector4(0.5f, -0.5f, 0.5f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
new Vector4(-0.5f, -0.5f, 0.5f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f)
});
D3D11Context.deviceContext.UpdateSubresource(databox, vertices, 0);
So... The only way to use UpdateSubresource is to get a new instance of the Databox class each and everytime i want to change the buffer or there is something i'm missing?