Table of Contents

Class IndexBuffer

Namespace
Microsoft.Xna.Framework.Graphics
Assembly
MonoGame.Framework.dll

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 GraphicsDevice

The associated graphics device of the index buffer.

indexElementSize IndexElementSize

The size, in bits, of an index element.

indexCount int

Number of indices in the buffer.

bufferUsage BufferUsage

A 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).

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 GraphicsDevice

The associated graphics device of the index buffer.

indexElementSize IndexElementSize

The size, in bits, of an index element.

indexCount int

Number of indices in the buffer.

usage BufferUsage

A set of options identifying the behaviors of this index buffer resource.

dynamic bool

true 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).
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 GraphicsDevice

The associated graphics device of the index buffer.

indexType Type

Type to use for index values.

indexCount int

Number of indices in the buffer.

usage BufferUsage

A 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 GraphicsDevice

The associated graphics device of the index buffer.

indexType Type

Type to use for index values.

indexCount int

Number of indices in the buffer.

usage BufferUsage

A set of options identifying the behaviors of this index buffer resource.

dynamic bool

true 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

BufferUsage

IndexCount

Gets the total number of elements in this IndexBuffer.

public int IndexCount { get; }

Property Value

int

IndexElementSize

Gets a value indicating the size of each element in this IndexBuffer

public IndexElementSize IndexElementSize { get; }

Property Value

IndexElementSize

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 int

The number of bytes into the index buffer where copying will start.

data T[]

The array to receive index buffer data.

startIndex int

The index of the element in the array at which to start copying.

elementCount int

The 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 int

The index of the element in the array at which to start copying.

elementCount int

The 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 int

Number of bytes into the index buffer where copying will start.

data T[]

The array of data to copy.

startIndex int

The index of the element in the array at which to start copying.

elementCount int

The number of elements to copy.

options SetDataOptions

Specifies 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

offsetInBytes int
data T[]
startIndex int
elementCount int

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 int

The index of the element in the array at which to start copying.

elementCount int

The 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.