Looking at the MSDN documentation, I can't find a way to lock VertexBuffers so that I can change their data while on the device. Is this possible in XNA?
You have a number of options for modifying the contents of vertex buffers in XNA:
VertexBuffer
has aSetData
member. You can only safely use this outside ofDraw
in any case where you may activate Predicated Tiling (so it's good practice to simply always do it outside of Draw).DynamicVertexBuffer
is likeVertexBuffer
, but faster when settings its contents. However it is susceptible to the graphics device being lost, and this condition must be handled. Also take a look atSetDataOptions
.DrawUserPrimitives
(and indexed version). This has the advantages of not affecting Predicated Tiling, and not causing the the command buffer to flush for small numbers of primitives.
There is more information on MSDN about Dynamically Updating Vertices. And this thread on the XNA forums may also be worth reading.