Struct VertexSource<T>
Represents a source of vertex data for rendering.
public struct VertexSource<T> where T : unmanaged
Type Parameters
TThe vertex structure type.
- Inherited Members
Remarks
VertexSource provides a view over a contiguous array of vertex data. The vertex type T must be a value type with sequential layout.
Constructors
VertexSource(T*, int)
Creates a vertex source from a memory pointer.
public VertexSource(T* data, int count)
Parameters
dataT*Pointer to vertex data.
countintNumber of vertices.
Properties
Count
Gets the number of vertices in this source.
public readonly int Count { get; }
Property Value
Data
Gets a pointer to the vertex data.
public readonly T* Data { get; }
Property Value
- T*
this[int]
Gets the vertex at the specified index.
public readonly T this[int index] { get; }
Parameters
indexintZero-based vertex index.
Property Value
- T
The vertex at the specified index.
Exceptions
- IndexOutOfRangeException
Thrown when index is out of bounds.
Methods
AsSpan()
Gets a read-only span over the vertex data.
public readonly ReadOnlySpan<T> AsSpan()
Returns
- ReadOnlySpan<T>
A read-only span of vertices.
FromArray(T[])
Creates a vertex source from a managed array.
[Obsolete("Use constructor within a fixed block instead. This method creates dangling pointers.", true)]
public static VertexSource<T> FromArray(T[] vertices)
Parameters
verticesT[]Array of vertex data.
Returns
- VertexSource<T>
A pinned vertex source.
Remarks
IMPORTANT: This method is unsafe and should not be used in production code. The returned VertexSource contains a pointer to memory that will become invalid once the fixed block exits. The array can be moved by the garbage collector.
Instead, use the constructor directly within a fixed block:
fixed (TVertex* ptr = vertices)
{
var source = new VertexSource<TVertex>(ptr, vertices.Length);
// Use source here
}
This method is deprecated and will be removed in a future version.