Jump to content
  • Advertisement
Sign in to follow this  
CuboDeAgua

[SlimDX 11] Databoxes can't be reused?

This topic is 2805 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!