次の方法で共有


VertexBuffer.SetData Generic Method (T , Int32, Int32, SetDataOptions)

Sets the vertex buffer data, specifying the start index and number of elements in the vertex buffer.

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

Syntax

public void SetData<T> (
         T[] data,
         int startIndex,
         int elementCount,
         SetDataOptions options
) where T : ValueType

Type Parameters

  • T
    The type of data in the vertex buffer.

Parameters

  • data
    The array from which to copy the vertex buffer data.
  • startIndex
    Index of the element in the array at which to start copying.
  • elementCount
    Number of elements in the array.
  • options
    Option that specifies whether existing data in the buffer will be kept after this operation. Discard is not valid on Xbox 360, but dynamic geometry may be rendered on the Xbox 360 by using DrawUserPrimitives or DrawUserIndexedPrimitives instead of setting the data for the vertex buffer.

Remarks

Warning

In the Draw method of an Xbox 360 game, vertex buffers, index buffers, and textures should not be written using when they are intended to be used for rendering. This condition may lead to graphics corruption or crashes. To avoid this potential issue, use DrawUserPrimitives or DrawUserIndexedPrimitives as the preferred alternative to VertexBuffer.SetData for dynamic vertex generation.

This is because, in cases where the size of the back buffer and depth stencil buffer exceed the size of the Xbox 360 10 MB of embedded memory (EDRAM), predicated tiling is utilized on this platform to compensate for the additional memory requirements. Predicated tiling is a process by which scene rendering is performed multiple times on subsections of the final render target dimensions.

When predicated tiling has been triggered, the drawing commands contained in the Draw function are not submitted until Present is called. (Note that Draw implicitly calls Present at the end of this method.) In this case, these resources are not available for modification until the GPU is finished with presenting the entire frame.

Example

This example demonstrates how to create a vertex buffer to hold a list of vertices and set the data for the vertex buffer to the array of vertices.

// Initialize the vertex buffer, allocating memory for each vertex.
vertexBuffer = new VertexBuffer( graphics.GraphicsDevice,
    VertexPositionNormalTexture.SizeInBytes * (pointList.Length),
    ResourceUsage.None,
    ResourceManagementMode.Automatic );

// Set the vertex buffer data to the array of vertices.
vertexBuffer.SetData<VertexPositionNormalTexture>( pointList );

Prior to drawing the vertices, set the source of the vertex stream for the graphics device by setting the desired vertex stream from GraphicsDevice.Vertices. The following code uses vertex stream zero, so GraphicsDevice.Vertices[0] is set to the vertex buffer created in step (1).

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

See Also

Concepts

Predicated Tiling

Tasks

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

Reference

GraphicsDevice.DrawUserPrimitives Generic Method
VertexBuffer Class
VertexBuffer Members
Microsoft.Xna.Framework.Graphics Namespace

Platforms

Xbox 360, Windows XP SP2, Windows Vista