Share via


GraphicsDevice.Indices Property

Gets or sets index data. The default value is null.

Namespace: Microsoft.Xna.Framework.Graphics
Assembly: Microsoft.Xna.Framework.Graphics (in microsoft.xna.framework.graphics.dll)

Syntax

public IndexBuffer Indices { get; set; }

Property Value

Index data.

Exceptions

Exception type Condition
ObjectDisposedException Indices was called after this GraphicsDevice was disposed.

Example

The vertex buffer and index data of the graphics device must be set before any call to DrawIndexedPrimitives. The following example sets the index data and vertex buffer.

VertexBuffer  vertexBuffer = new VertexBuffer(GraphicsDevice, typeof(VertexPositionColor), 8, BufferUsage.None);

vertexBuffer.SetData<VertexPositionColor>(primitiveList);

IndexBuffer  lineListIndexBuffer = new IndexBuffer(
    GraphicsDevice,
    IndexElementSize.SixteenBits,
    sizeof(short) * lineListIndices.Length,
    BufferUsage.None);

lineListIndexBuffer.SetData<short>(lineListIndices);

GraphicsDevice.Indices = lineListIndexBuffer;
GraphicsDevice.SetVertexBuffer(vertexBuffer);
GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.LineList, 0, 0, 8, 0, 7);

See Also

Reference

GraphicsDevice Class
GraphicsDevice Members
Microsoft.Xna.Framework.Graphics Namespace

Platforms

Xbox 360, Windows 7, Windows Vista, Windows XP