[SlimDX 11] Databoxes can't be reused?

Started by
1 comment, last by CuboDeAgua 13 years, 3 months ago
Hi all,

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?
Advertisement
Hmmm, had a quick glance at the source code of DataBox, DataStream and UpdateSubresource. I think you should reset databox.Data.Position to zero (again) before calling UpdateSubresource.

Hmmm, had a quick glance at the source code of DataBox, DataStream and UpdateSubresource. I think you should reset databox.Data.Position to zero (again) before calling UpdateSubresource.



That was it ^^. I had lost of stream-position=0; but i hadn't that one.

Thanks :D

This topic is closed to new replies.

Advertisement