Class DynamicVertexBuffer
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.
public class DynamicVertexBuffer : VertexBuffer, IDisposable
- Inheritance
-
DynamicVertexBuffer
- Implements
- Inherited Members
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.
Constructors
DynamicVertexBuffer(GraphicsDevice, VertexDeclaration, int, BufferUsage)
Initializes a new instance of DynamicVertexBuffer with the specified parameters
public DynamicVertexBuffer(GraphicsDevice graphicsDevice, VertexDeclaration vertexDeclaration, int vertexCount, BufferUsage bufferUsage)
Parameters
graphicsDevice
GraphicsDeviceThe associated graphics device of the vertex buffer.
vertexDeclaration
VertexDeclarationThe vertex declaration, which describes per-vertex data.
vertexCount
intThe number of vertices in this vertex buffer.
bufferUsage
BufferUsageA set of options identifying the behaviors of this vertex buffer resource.
Exceptions
- ArgumentNullException
graphicsDevice
is null.- ArgumentOutOfRangeException
vertexCount
must be greater than zero.- InvalidOperationException
This resource could not be created.
DynamicVertexBuffer(GraphicsDevice, Type, int, BufferUsage)
Initializes a new instance of DynamicVertexBuffer with the specified parameters
public DynamicVertexBuffer(GraphicsDevice graphicsDevice, Type type, int vertexCount, BufferUsage bufferUsage)
Parameters
graphicsDevice
GraphicsDeviceThe associated graphics device of the vertex buffer.
type
TypeThe type used that describes the per-vertex data. Must derive from IVertexType.
vertexCount
intThe number of vertices in this vertex buffer.
bufferUsage
BufferUsageA set of options identifying the behaviors of this vertex buffer resource.
Exceptions
- ArgumentException
type
/// One of the following conditions is true:- The
type
parameter is not a value type. - The
type
parameter does not derive from IVertexType.
- The
- ArgumentNullException
One of the following conditions is true:
- The
graphicsDevice
parameter is null. - The
type
parameter is null.
- The
- ArgumentOutOfRangeException
The
vertexCount
parameter must be greater than zero.- Exception
A new VertexDeclaration instance cannot be created from the type provided by the
type
parameter.- InvalidOperationException
This resource could not be created.
Properties
IsContentLost
Gets a value that indicates if the vertex buffer data has been lost due to a lost device event.
[Obsolete("This is provided for XNA compatibility only and will always return false")]
public bool IsContentLost { get; }
Property Value
Remarks
This property will always return false. It is included for XNA compatibility.
Methods
SetData<T>(int, T[], int, int, int, SetDataOptions)
Copies array data to the vertex buffer.
public void SetData<T>(int offsetInBytes, T[] data, int startIndex, int elementCount, int vertexStride, SetDataOptions options) where T : struct
Parameters
offsetInBytes
intNumber of bytes into the vertex buffer where copying will start.
data
T[]The array of data to copy.
startIndex
intThe index of the element in the array at which to start copying.
elementCount
intThe number of elements to copy.
vertexStride
intThe size, in bytes, of the elements in the vertex buffer.
options
SetDataOptionsSpecifies whether existing data in the buffer will be kept after this operation.
Type Parameters
T
The type of elements in the array.
Exceptions
- ArgumentNullException
The
data
is null.- ArgumentOutOfRangeException
One of the following conditions is true:
- The
vertexStride
parameter larger than the vertex buffer size. - The
vertexStride
parameter is less than the size of the specified data. - The
data
parameter is not the correct size for the amount of data requested.
- The
SetData<T>(T[], int, int, SetDataOptions)
Copies array data to the vertex buffer.
public void SetData<T>(T[] data, int startIndex, int elementCount, SetDataOptions options) where T : struct
Parameters
data
T[]The array of data to copy.
startIndex
intThe index of the element in the array at which to start copying.
elementCount
intThe number of elements to copy.
options
SetDataOptionsSpecifies whether existing data in the buffer will be kept after this operation.
Type Parameters
T
The type of elements in the array.
Exceptions
- ArgumentNullException
The
data
is null.- ArgumentOutOfRangeException
The
data
parameter is not the correct size for the amount of data requested.