Sign in to follow this  
gomidas

C# SharpDX how to use dynamic vertex buffers

Recommended Posts

gomidas    163

I am using a static vertex buffer. I need to get immediate update of vertex positions how can I achieve that instead re-creating a buffer everytime ? After getting dynamic buffer how will I update positinos ?

 

Thanks if anyone answer.

Share this post


Link to post
Share on other sites
__Toz__    320

I'm not familiar with SharpDX but it's likely that you would need to lock the vertex buffer and then copy the new vertex positions into the vertex buffer. After that you need to unlock the vertex buffer so it can be used to draw again.

Looking at the SharpDX source code this is indeed what you need to do: https://github.com/sharpdx/SharpDX/blob/master/Source/SharpDX.Direct3D9/VertexBuffer.cs

Share this post


Link to post
Share on other sites
gomidas    163

I'm not familiar with SharpDX but it's likely that you would need to lock the vertex buffer and then copy the new vertex positions into the vertex buffer. After that you need to unlock the vertex buffer so it can be used to draw again.

Looking at the SharpDX source code this is indeed what you need to do: https://github.com/sharpdx/SharpDX/blob/master/Source/SharpDX.Direct3D9/VertexBuffer.cs

Alright, that would be perfect if there was an example usage about how will I put them inside. Buf for retriving existing cooords I do not have use that I can get correct positions over matrix and pass transformed coords to VertexData instead of it huh ? I think access is for animations (?)

Share this post


Link to post
Share on other sites
__Toz__    320

I googled "sharpdx tutorial vertex buffer" and this was one of the links:

https://gamedev.stackexchange.com/questions/49727/proper-use-of-dynamic-vertex-buffers-for-rapid-update

This has a snippet of code using Map/Unmap to lock/unlock the vertex buffer.

 

Hmm I just noticed that the repository I linked to was for Direct3D9, which is a bit old. I'm guessing you're using the Direct3D11 version of SharpDX? That code snippet is for 10 but I think the APIs have stayed mostly the same between 10 and 11. 

Share this post


Link to post
Share on other sites
gomidas    163

I googled "sharpdx tutorial vertex buffer" and this was one of the links:

https://gamedev.stackexchange.com/questions/49727/proper-use-of-dynamic-vertex-buffers-for-rapid-update

This has a snippet of code using Map/Unmap to lock/unlock the vertex buffer.

 

Hmm I just noticed that the repository I linked to was for Direct3D9, which is a bit old. I'm guessing you're using the Direct3D11 version of SharpDX? That code snippet is for 10 but I think the APIs have stayed mostly the same between 10 and 11. 

Hmm, I am going to check that thank you very much.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this