Class IndexBuffer
Describes the rendering order of the vertices in a vertex buffer.
public class IndexBuffer : GraphicsResource, IDisposable
- Inheritance
-
IndexBuffer
- Implements
- Derived
- Inherited Members
Constructors
IndexBuffer(GraphicsDevice, IndexElementSize, int, BufferUsage)
Creates a new instance of IndexBuffer with the specified parameters.
public IndexBuffer(GraphicsDevice graphicsDevice, IndexElementSize indexElementSize, int indexCount, BufferUsage bufferUsage)
Parameters
graphicsDevice
GraphicsDeviceThe associated graphics device of the index buffer.
indexElementSize
IndexElementSizeThe size, in bits, of an index element.
indexCount
intNumber of indices in the buffer.
bufferUsage
BufferUsageA set of options identifying the behaviors of this index buffer resource.
Exceptions
- ArgumentNullException
graphicsDevice
is null.- ArgumentOutOfRangeException
One of the following conditions is true
-
The
indexCount
parameter is invalid. Index buffers can only be created for indices which are sixteen or thirty-two bits in length -
The
indexElementSize
parameter is invalid. The resource size must be greater than zero. -
The
indexElementSize
parameter is invalid. The total size of the index buffer must be an even multiple of the index element size (either 16 or 32 bits).
-
The
IndexBuffer(GraphicsDevice, IndexElementSize, int, BufferUsage, bool)
Creates a new instance of IndexBuffer with the specified parameters.
protected IndexBuffer(GraphicsDevice graphicsDevice, IndexElementSize indexElementSize, int indexCount, BufferUsage usage, bool dynamic)
Parameters
graphicsDevice
GraphicsDeviceThe associated graphics device of the index buffer.
indexElementSize
IndexElementSizeThe size, in bits, of an index element.
indexCount
intNumber of indices in the buffer.
usage
BufferUsageA set of options identifying the behaviors of this index buffer resource.
dynamic
booltrue if this is a dynamic index buffer; otherwise, false.
Exceptions
- ArgumentNullException
graphicsDevice
is null.- ArgumentOutOfRangeException
One of the following conditions is true
-
The
indexCount
parameter is invalid. Index buffers can only be created for indices which are sixteen or thirty-two bits in length -
The
indexElementSize
parameter is invalid. The resource size must be greater than zero. -
The
indexElementSize
parameter is invalid. The total size of the index buffer must be an even multiple of the index element size (either 16 or 32 bits).
-
The
- InvalidOperationException
The resource could not be created
IndexBuffer(GraphicsDevice, Type, int, BufferUsage)
Creates a new instance of IndexBuffer with the specified parameters.
public IndexBuffer(GraphicsDevice graphicsDevice, Type indexType, int indexCount, BufferUsage usage)
Parameters
graphicsDevice
GraphicsDeviceThe associated graphics device of the index buffer.
indexType
TypeType to use for index values.
indexCount
intNumber of indices in the buffer.
usage
BufferUsageA set of options identifying the behaviors of this index buffer resource.
Exceptions
- ArgumentOutOfRangeException
The
indexCount
parameter is invalid. It must be greater than zero, and the index must be sixteen or thirty-two bits in length. Index buffers can only be created for indices which are sixteen or thirty-two bits in length.- InvalidOperationException
The resource could not be created
IndexBuffer(GraphicsDevice, Type, int, BufferUsage, bool)
Creates a new instance of IndexBuffer with the specified parameters.
protected IndexBuffer(GraphicsDevice graphicsDevice, Type indexType, int indexCount, BufferUsage usage, bool dynamic)
Parameters
graphicsDevice
GraphicsDeviceThe associated graphics device of the index buffer.
indexType
TypeType to use for index values.
indexCount
intNumber of indices in the buffer.
usage
BufferUsageA set of options identifying the behaviors of this index buffer resource.
dynamic
booltrue if this is a dynamic index buffer; otherwise, false.
Exceptions
- ArgumentOutOfRangeException
The
indexCount
parameter is invalid. Index buffers can only be created for indices which are sixteen or thirty-two bits in length- InvalidOperationException
The resource could not be created
Properties
BufferUsage
Gets the usage hint for optimizing memory placement of this IndexBuffer.
public BufferUsage BufferUsage { get; }
Property Value
IndexCount
Gets the total number of elements in this IndexBuffer.
public int IndexCount { get; }
Property Value
IndexElementSize
Gets a value indicating the size of each element in this IndexBuffer
public IndexElementSize IndexElementSize { get; }
Property Value
Methods
Dispose(bool)
protected override void Dispose(bool disposing)
Parameters
disposing
bool
GetData<T>(int, T[], int, int)
Copies the index buffer into an array.
public void GetData<T>(int offsetInBytes, T[] data, int startIndex, int elementCount) where T : struct
Parameters
offsetInBytes
intThe number of bytes into the index buffer where copying will start.
data
T[]The array to receive index buffer data.
startIndex
intThe index of the element in the array at which to start copying.
elementCount
intThe number of elements to copy.
Type Parameters
T
The type of elements in the array.
Exceptions
- ArgumentNullException
data
is null.- InvalidOperationException
data
is not the correct size for the amount of data requested.- NotSupportedException
This IndexBuffer was created with a usage type of WriteOnly.
GetData<T>(T[])
Copies the index buffer into an array.
public void GetData<T>(T[] data) where T : struct
Parameters
data
T[]The array to receive index buffer data.
Type Parameters
T
The type of elements in the array.
Exceptions
- ArgumentNullException
data
is null.- InvalidOperationException
data
is not the correct size for the amount of data requested.- NotSupportedException
This IndexBuffer was created with a usage type of WriteOnly.
GetData<T>(T[], int, int)
Copies the index buffer into an array.
public void GetData<T>(T[] data, int startIndex, int elementCount) where T : struct
Parameters
data
T[]The array to receive index buffer data.
startIndex
intThe index of the element in the array at which to start copying.
elementCount
intThe number of elements to copy.
Type Parameters
T
The type of elements in the array.
Exceptions
- ArgumentNullException
data
is null.- InvalidOperationException
data
is not the correct size for the amount of data requested.- NotSupportedException
This IndexBuffer was created with a usage type of WriteOnly.
GraphicsDeviceResetting()
The GraphicsDevice is resetting, so GPU resources must be recreated.
protected override void GraphicsDeviceResetting()
SetDataInternal<T>(int, T[], int, int, SetDataOptions)
Copies array data to the index buffer.
protected void SetDataInternal<T>(int offsetInBytes, T[] data, int startIndex, int elementCount, SetDataOptions options) where T : struct
Parameters
offsetInBytes
intNumber of bytes into the index 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.
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
data
is null.- InvalidOperationException
data
is not the correct size for the amount of data requested.
SetData<T>(int, T[], int, int)
public void SetData<T>(int offsetInBytes, T[] data, int startIndex, int elementCount) where T : struct
Parameters
Type Parameters
T
SetData<T>(T[])
Copies array data to the index buffer.
public void SetData<T>(T[] data) where T : struct
Parameters
data
T[]The array of data to copy.
Type Parameters
T
The type of elements in the array.
Exceptions
- ArgumentNullException
data
is null.- InvalidOperationException
data
is not the correct size for the amount of data requested.
SetData<T>(T[], int, int)
Copies array data to the index buffer.
public void SetData<T>(T[] data, int startIndex, int elementCount) 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.
Type Parameters
T
The type of elements in the array.
Exceptions
- ArgumentNullException
data
is null.- InvalidOperationException
data
is not the correct size for the amount of data requested.