Table of Contents

Struct VertexSource<T>

Namespace
Xui.GPU.Software
Assembly
Xui.Runtime.Software.dll

Represents a source of vertex data for rendering.

public struct VertexSource<T> where T : unmanaged

Type Parameters

T

The 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

data T*

Pointer to vertex data.

count int

Number of vertices.

Properties

Count

Gets the number of vertices in this source.

public readonly int Count { get; }

Property Value

int

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

index int

Zero-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

vertices T[]

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.