Sdílet prostřednictvím


GraphicsDevice.DrawPrimitives Method

Renders a sequence of non-indexed geometric primitives of the specified type from the current set of data input streams.

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

Syntax

public void DrawPrimitives (
         PrimitiveType primitiveType,
         int startVertex,
         int primitiveCount
)

Parameters

  • primitiveType
    Describes the type of primitive to render.
  • startVertex
    Index of the first vertex to load. Beginning at startVertex, the correct number of vertices is read out of the vertex buffer.
  • primitiveCount
    Number of primitives to render. To determine the maximum number of primitives allowed, check MaxPrimitiveCount. The primitiveCount is the number of primitives as determined by the primitive type. If it is a line list, each primitive has two vertices. If it is a triangle list, each primitive has three vertices.

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:

  • VertexDeclaration is not a valid value. A valid vertex declaration must be set on the device before any draw operations can be performed.
  • A valid vertex shader and pixel shader was not set before calling DrawPrimitives. Both a valid vertex shader and pixel shader (or valid effect) must be set on the device before any draw operations may be performed. See How to: Use BasicEffect or How to: Create and Apply Custom Effects for more information on applying effects.
  • Vertices is not a valid vertex buffer. A valid vertex buffer must be set on the device before any draw operations may be performed.
  • The active render target and depth stencil surface do not have the same pixel size and multisampling type.

Remarks

DrawPrimitives should not be called with a single triangle at a time.

Example

The vertex stream of the graphics device must be set before any call to DrawPrimitives. The following example associates a user created vertex buffer of type VertexPositionNormalTexture with vertex stream 0 (zero) of the graphics device.

graphics.GraphicsDevice.Vertices[0].SetSource(
    vertexBuffer, 0,
    VertexPositionNormalTexture.SizeInBytes );

See Also

Tasks

How to: Draw Points, Lines, and Other 3D Primitives

Reference

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

Platforms

Xbox 360, Windows XP SP2, Windows Vista