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
graphicsDeviceGraphicsDeviceThe associated graphics device of the index buffer.
indexElementSizeIndexElementSizeThe size, in bits, of an index element.
indexCountintNumber of indices in the buffer.
bufferUsageBufferUsageA set of options identifying the behaviors of this index buffer resource.
Exceptions
- ArgumentNullException
 graphicsDeviceis null.- ArgumentOutOfRangeException
 One of the following conditions is true
- 
            The 
indexCountparameter is invalid. Index buffers can only be created for indices which are sixteen or thirty-two bits in length - 
            The 
indexElementSizeparameter is invalid. The resource size must be greater than zero. - 
            The 
indexElementSizeparameter 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
graphicsDeviceGraphicsDeviceThe associated graphics device of the index buffer.
indexElementSizeIndexElementSizeThe size, in bits, of an index element.
indexCountintNumber of indices in the buffer.
usageBufferUsageA set of options identifying the behaviors of this index buffer resource.
dynamicbooltrue if this is a dynamic index buffer; otherwise, false.
Exceptions
- ArgumentNullException
 graphicsDeviceis null.- ArgumentOutOfRangeException
 One of the following conditions is true
- 
            The 
indexCountparameter is invalid. Index buffers can only be created for indices which are sixteen or thirty-two bits in length - 
            The 
indexElementSizeparameter is invalid. The resource size must be greater than zero. - 
            The 
indexElementSizeparameter 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
graphicsDeviceGraphicsDeviceThe associated graphics device of the index buffer.
indexTypeTypeType to use for index values.
indexCountintNumber of indices in the buffer.
usageBufferUsageA set of options identifying the behaviors of this index buffer resource.
Exceptions
- ArgumentOutOfRangeException
 The
indexCountparameter 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
graphicsDeviceGraphicsDeviceThe associated graphics device of the index buffer.
indexTypeTypeType to use for index values.
indexCountintNumber of indices in the buffer.
usageBufferUsageA set of options identifying the behaviors of this index buffer resource.
dynamicbooltrue if this is a dynamic index buffer; otherwise, false.
Exceptions
- ArgumentOutOfRangeException
 The
indexCountparameter 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
disposingbool
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
offsetInBytesintThe number of bytes into the index buffer where copying will start.
dataT[]The array to receive index buffer data.
startIndexintThe index of the element in the array at which to start copying.
elementCountintThe number of elements to copy.
Type Parameters
TThe type of elements in the array.
Exceptions
- ArgumentNullException
 datais null.- InvalidOperationException
 datais 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
dataT[]The array to receive index buffer data.
Type Parameters
TThe type of elements in the array.
Exceptions
- ArgumentNullException
 datais null.- InvalidOperationException
 datais 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
dataT[]The array to receive index buffer data.
startIndexintThe index of the element in the array at which to start copying.
elementCountintThe number of elements to copy.
Type Parameters
TThe type of elements in the array.
Exceptions
- ArgumentNullException
 datais null.- InvalidOperationException
 datais 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
offsetInBytesintNumber of bytes into the index 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.
optionsSetDataOptionsSpecifies whether existing data in the buffer will be kept after this operation.
Type Parameters
TThe type of elements in the array.
Exceptions
- ArgumentNullException
 datais null.- InvalidOperationException
 datais 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
dataT[]The array of data to copy.
Type Parameters
TThe type of elements in the array.
Exceptions
- ArgumentNullException
 datais null.- InvalidOperationException
 datais 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
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.
Type Parameters
TThe type of elements in the array.
Exceptions
- ArgumentNullException
 datais null.- InvalidOperationException
 datais not the correct size for the amount of data requested.