GraphicsDevice.DrawUserPrimitives Generic Method (PrimitiveType, T[], Int32, Int32, VertexDeclaration)

Draws primitives.

Namespace: Microsoft.Xna.Framework.Graphics
Assembly: Microsoft.Xna.Framework.Graphics (in

public void DrawUserPrimitives<T> (
         PrimitiveType primitiveType,
         T[] vertexData,
         int vertexOffset,
         int primitiveCount,
         VertexDeclaration vertexDeclaration
) where T : struct

Type Parameters

Per-vertex data type.


Type: PrimitiveType
Describes the type of primitive to render.
Type: T
The vertex data.
Type: Int32
Offset (in vertices) from the beginning of the buffer to start reading data.
Type: Int32
Number of primitives to render.
Type: VertexDeclaration
The vertex declaration, which defines per-vertex data.

Exception typeCondition
ArgumentException vertexOffset + numVertices is outside of the range of vertexData.
ArgumentNullException vertexData is null.

One of the following conditions is true:

  • primitiveCount is less than or equal to zero. When drawing, at least one primitive must be drawn.
  • vertexOffset is less than zero or greater than the length of vertexData.

One of the following conditions is true:

  • A valid vertex shader and pixel shader was not set before calling DrawUserPrimitives. Both a valid vertex shader and pixel shader (or valid effect) must be set on the device before any draw operations may be performed.
  • vertexData is not a valid vertex buffer. A valid vertex buffer must be set on the device before any draw operations may be performed.

This method is intended for use when drawing dynamic geometry specified by the user. It supports only a single vertex stream. The effect of this call is to use the provided vertex data pointer and stride for vertex stream 0. It is invalid to have the declaration of the current vertex shader refer to vertex streams other than stream 0.

The vertex data passed to DrawUserPrimitives does not need to persist after the call. Access to the data is completed before returning from the call.

Xbox 360, Windows 7, Windows Vista, Windows XP

Community Additions