Class VertexBuffer
public class VertexBuffer : GraphicsResource, IDisposable
- Inheritance
-
VertexBuffer
- Implements
- Derived
- Inherited Members
Constructors
VertexBuffer(GraphicsDevice, VertexDeclaration, int, BufferUsage)
public VertexBuffer(GraphicsDevice graphicsDevice, VertexDeclaration vertexDeclaration, int vertexCount, BufferUsage bufferUsage)
Parameters
graphicsDeviceGraphicsDevicevertexDeclarationVertexDeclarationvertexCountintbufferUsageBufferUsage
VertexBuffer(GraphicsDevice, VertexDeclaration, int, BufferUsage, bool)
protected VertexBuffer(GraphicsDevice graphicsDevice, VertexDeclaration vertexDeclaration, int vertexCount, BufferUsage bufferUsage, bool dynamic)
Parameters
graphicsDeviceGraphicsDevicevertexDeclarationVertexDeclarationvertexCountintbufferUsageBufferUsagedynamicbool
VertexBuffer(GraphicsDevice, Type, int, BufferUsage)
public VertexBuffer(GraphicsDevice graphicsDevice, Type type, int vertexCount, BufferUsage bufferUsage)
Parameters
graphicsDeviceGraphicsDevicetypeTypevertexCountintbufferUsageBufferUsage
Properties
BufferUsage
public BufferUsage BufferUsage { get; }
Property Value
VertexCount
public int VertexCount { get; }
Property Value
VertexDeclaration
public VertexDeclaration VertexDeclaration { get; }
Property Value
Methods
Dispose(bool)
The method that derived classes should override to implement disposing of managed and native resources.
protected override void Dispose(bool disposing)
Parameters
disposingboolTrue if managed objects should be disposed.
Remarks
Native resources should always be released regardless of the value of the disposing parameter.
GetData<T>(int, T[], int, int, int)
Get the vertex data froom this VertexBuffer.
public void GetData<T>(int offsetInBytes, T[] data, int startIndex, int elementCount, int vertexStride = 0) where T : struct
Parameters
offsetInBytesintThe offset to the first element in the vertex buffer in bytes.
dataT[]An array of T's to be filled.
startIndexintThe index to start filling the data array.
elementCountintThe number of T's to get.
vertexStrideintThe size of how a vertex buffer element should be interpreted.
Type Parameters
TThe struct you want to fill.
Remarks
Note that this pulls data from VRAM into main memory and because of that is a very expensive operation. It is often a better idea to keep a copy of the data in main memory.
GetData<T>(T[])
public void GetData<T>(T[] data) where T : struct
Parameters
dataT[]
Type Parameters
T
GetData<T>(T[], int, int)
public void GetData<T>(T[] data, int startIndex, int elementCount) where T : struct
Parameters
Type Parameters
T
GraphicsDeviceResetting()
The GraphicsDevice is resetting, so GPU resources must be recreated.
protected override void GraphicsDeviceResetting()
SetDataInternal<T>(int, T[], int, int, int, SetDataOptions)
protected void SetDataInternal<T>(int offsetInBytes, T[] data, int startIndex, int elementCount, int vertexStride, SetDataOptions options) where T : struct
Parameters
offsetInBytesintdataT[]startIndexintelementCountintvertexStrideintoptionsSetDataOptions
Type Parameters
T
SetData<T>(int, T[], int, int, int)
Sets the vertex buffer data, specifying the index at which to start copying from the source data array, the number of elements to copy from the source data array, and how far apart elements from the source data array should be when they are copied into the vertex buffer.
public void SetData<T>(int offsetInBytes, T[] data, int startIndex, int elementCount, int vertexStride) where T : struct
Parameters
offsetInBytesintOffset in bytes from the beginning of the vertex buffer to the start of the copied data.
dataT[]Data array.
startIndexintIndex at which to start copying from
data. Must be within thedataarray bounds.elementCountintNumber of elements to copy from
data. The combination ofstartIndexandelementCountmust be within thedataarray bounds.vertexStrideintSpecifies how far apart, in bytes, elements from
datashould be when they are copied into the vertex buffer. In almost all cases this should besizeof(T), to create a tightly-packed vertex buffer. If you specifysizeof(T), elements fromdatawill be copied into the vertex buffer with no padding between each element. If you specify a value greater thansizeof(T), elements fromdatawill be copied into the vertex buffer with padding between each element. If you specify0for this parameter, it will be treated as if you had specifiedsizeof(T). With the exception of0, you must specify a value greater than or equal tosizeof(T).
Type Parameters
TType of elements in the data array.
Remarks
If T is VertexPositionTexture, but you want to set only the position component of the vertex data,
you would call this method as follows:
Vector3[] positions = new Vector3[numVertices];
vertexBuffer.SetData(0, positions, 0, numVertices, vertexBuffer.VertexDeclaration.VertexStride);
Continuing from the previous example, if you want to set only the texture coordinate component of the vertex data,
you would call this method as follows (note the use of offsetInBytes:
Vector2[] texCoords = new Vector2[numVertices];
vertexBuffer.SetData(12, texCoords, 0, numVertices, vertexBuffer.VertexDeclaration.VertexStride);
SetData<T>(T[])
Sets the vertex buffer data. This is the same as calling SetData<T>(int, T[], int, int, int)
with offsetInBytes and startIndex equal to 0, elementCount equal to data.Length,
and vertexStride equal to sizeof(T).
public void SetData<T>(T[] data) where T : struct
Parameters
dataT[]Data array.
Type Parameters
TType of elements in the data array.
SetData<T>(T[], int, int)
Sets the vertex buffer data, specifying the index at which to start copying from the source data array,
and the number of elements to copy from the source data array. This is the same as calling
SetData<T>(int, T[], int, int, int) with offsetInBytes equal to 0,
and vertexStride equal to sizeof(T).
public void SetData<T>(T[] data, int startIndex, int elementCount) where T : struct
Parameters
dataT[]Data array.
startIndexintIndex at which to start copying from
data. Must be within thedataarray bounds.elementCountintNumber of elements to copy from
data. The combination ofstartIndexandelementCountmust be within thedataarray bounds.
Type Parameters
TType of elements in the data array.