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
graphicsDeviceGraphicsDeviceThe associated graphics device of the vertex buffer.
vertexDeclarationVertexDeclarationThe vertex declaration, which describes per-vertex data.
vertexCountintThe number of vertices in this vertex buffer.
bufferUsageBufferUsageA set of options identifying the behaviors of this vertex buffer resource.
Exceptions
- ArgumentNullException
graphicsDeviceis null.- ArgumentOutOfRangeException
vertexCountmust 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
graphicsDeviceGraphicsDeviceThe associated graphics device of the vertex buffer.
typeTypeThe type used that describes the per-vertex data. Must derive from IVertexType.
vertexCountintThe number of vertices in this vertex buffer.
bufferUsageBufferUsageA set of options identifying the behaviors of this vertex buffer resource.
Exceptions
- ArgumentException
type/// One of the following conditions is true:- The
typeparameter is not a value type. - The
typeparameter does not derive from IVertexType.
- The
- ArgumentNullException
One of the following conditions is true:
- The
graphicsDeviceparameter is null. - The
typeparameter is null.
- The
- ArgumentOutOfRangeException
The
vertexCountparameter must be greater than zero.- Exception
A new VertexDeclaration instance cannot be created from the type provided by the
typeparameter.- 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
offsetInBytesintNumber of bytes into the vertex buffer where copying will start.
dataT[]The array of data to copy.
startIndexintThe index of the element in the array at which to start copying.
elementCountintThe number of elements to copy.
vertexStrideintThe size, in bytes, of the elements in the vertex buffer.
optionsSetDataOptionsSpecifies whether existing data in the buffer will be kept after this operation.
Type Parameters
TThe type of elements in the array.
Exceptions
- ArgumentNullException
The
datais null.- ArgumentOutOfRangeException
One of the following conditions is true:
- The
vertexStrideparameter larger than the vertex buffer size. - The
vertexStrideparameter is less than the size of the specified data. - The
dataparameter 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
dataT[]The array of data to copy.
startIndexintThe index of the element in the array at which to start copying.
elementCountintThe number of elements to copy.
optionsSetDataOptionsSpecifies whether existing data in the buffer will be kept after this operation.
Type Parameters
TThe type of elements in the array.
Exceptions
- ArgumentNullException
The
datais null.- ArgumentOutOfRangeException
The
dataparameter is not the correct size for the amount of data requested.