GraphicsDevice.DrawIndexedPrimitives Method
Renders the specified geometric primitive, based on indexing into an array of vertices.
Syntax
'Declaration
Public Sub DrawIndexedPrimitives ( _
primitiveType As PrimitiveType, _
baseVertex As Integer, _
minVertexIndex As Integer, _
numVertices As Integer, _
startIndex As Integer, _
primitiveCount As Integer _
)
public void DrawIndexedPrimitives (
PrimitiveType primitiveType,
int baseVertex,
int minVertexIndex,
int numVertices,
int startIndex,
int primitiveCount
)
public:
void DrawIndexedPrimitives(
PrimitiveType primitiveType,
int baseVertex,
int minVertexIndex,
int numVertices,
int startIndex,
int primitiveCount
)
Parameters
- primitiveType
Type: PrimitiveType
Describes the type of primitive to render. PrimitiveType.PointList is not supported with this method. - baseVertex
Type: Int32
Offset to add to each vertex index in the index buffer. - minVertexIndex
Type: Int32
Minimum vertex index for vertices used during the call. The minVertexIndex parameter and all of the indices in the index stream are relative to the baseVertex parameter. - numVertices
Type: Int32
Number of vertices used during the call. The first vertex is located at index: baseVertex + minVertexIndex. - startIndex
Type: Int32
Location in the index array at which to start reading vertices. - primitiveCount
Type: Int32
Number of primitives to render. The number of vertices used is a function of primitiveCount and primitiveType.
Exceptions
Exception type | Condition |
---|---|
ArgumentOutOfRangeException | primitiveCount is less than or equal to zero. When drawing, at least one primitive must be drawn. |
InvalidOperationException | One of the following conditions is true:
|
NotSupportedException | The profile does not support an elementSize of IndexElementSize.ThirtyTwoBits; use IndexElementSize.SixteenBits or a type that has a size of two bytes. |
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);
Remarks
This method draws indexed primitives from the current set of data input streams.
The minVertexIndex and numVertices parameters specify the range of vertex indices used for each call to DrawIndexedPrimitives. These vertex indices are used to optimize vertex processing of indexed primitives by processing a sequential range of vertices prior to indexing into them. Indices used during this call cannot reference any vertices outside this range.
If no index array is set, DrawIndexedPrimitives fails.
Requirements
Namespace: Microsoft.Xna.Framework.Graphics
Assembly: Microsoft.Xna.Framework.Graphics (in microsoft.xna.framework.graphics.dll)
See Also
Reference
GraphicsDevice Class
GraphicsDevice Members
Microsoft.Xna.Framework.Graphics Namespace
Platforms
Windows Phone