Partager via


DynamicVertexBuffer Class

Represents a list of 3D vertices to be streamed to the graphics device. Use DynamicVertexBuffer for dynamic vertex arrays and VertexBuffer for non-dynamic vertex arrays.

Namespace: Microsoft.Xna.Framework.Graphics
Assembly: Microsoft.Xna.Framework.Graphics (in microsoft.xna.framework.graphics.dll)

Syntax

public class DynamicVertexBuffer : VertexBuffer

Remarks

In situations where your game frequently modifies a vertex buffer, it is recommended that the buffer be instantiated or derived from DynamicVertexBuffer instead of the VertexBuffer class. DynamicVertexBuffer is optimized for frequent vertex data modification. However, to fully maximize the benefits of this class, your data must be restored after any occurrence of a ContentLost event. This event occurs whenever the related graphics device is lost. After resetting the graphics device and restoring any static resources, the ContentLost event handler is then called. Calling SetData inside this handler restores any dynamic resource data.

You can declare the event handler after constructing your dynamic vertex buffer. For example, the following code sample first constructs a dynamic vertex buffer (called vertexBuffer), declares a ContentLost event handler (called vertexBuffer_ContentLost). The final step initializes the data with a call to SetData. This is necessary for correct restoration of any existing particles after a lost device event.

      vertexBuffer = new DynamicVertexBuffer(GraphicsDevice, size, BufferUsage.Points);
      vertexBuffer.ContentLost += new EventHandler(vertexBuffer_ContentLost);
      vertexBuffer.SetData(particles);
    

See Also

Reference

DynamicVertexBuffer Members
Microsoft.Xna.Framework.Graphics Namespace

Platforms

Xbox 360, Windows 7, Windows Vista, Windows XP