Table of Contents

Struct IndexBufferHelper

Namespace
Stride.Graphics
Assembly
Stride.Graphics.dll
public readonly struct IndexBufferHelper
Inherited Members

Examples

Reading the indices of a mesh:

Model.Meshes[0].Draw.IndexBuffer.AsReadable(Services, out IndexBufferHelper helper, out int count)
var indices = helper.To32Bit();

Constructors

IndexBufferHelper(IndexBufferBinding, IServiceRegistry, out int)

Fetch this buffer and create a helper to read from it.

public IndexBufferHelper(IndexBufferBinding binding, IServiceRegistry services, out int count)

Parameters

binding IndexBufferBinding

The bindings for this buffer

services IServiceRegistry

The service used to retrieve the buffer from disk/GPU if it wasn't found through other means

count int

The amount of indices this buffer holds

Examples

Reading the indices of a mesh:

Model.Meshes[0].Draw.IndexBuffer.AsReadable(Services, out IndexBufferHelper helper, out int count)
var indices = helper.To32Bit();

Remarks

This operation loads the buffer from disk, or directly from the gpu. It is very slow, avoid calling this too often if at all possible.

IndexBufferHelper(IndexBufferBinding, byte[], out int)

Fetch this buffer and create a helper to read from it.

public IndexBufferHelper(IndexBufferBinding binding, byte[] dataOuter, out int count)

Parameters

binding IndexBufferBinding

The bindings for this buffer

dataOuter byte[]
count int

The amount of indices this buffer holds

Examples

Reading the indices of a mesh:

Model.Meshes[0].Draw.IndexBuffer.AsReadable(Services, out IndexBufferHelper helper, out int count)
var indices = helper.To32Bit();

Remarks

This operation loads the buffer from disk, or directly from the gpu. It is very slow, avoid calling this too often if at all possible.

Fields

Binding

public readonly IndexBufferBinding Binding

Field Value

IndexBufferBinding

DataOuter

Full index buffer, does not account for the binding offset or length

public readonly byte[] DataOuter

Field Value

byte[]

Properties

DataInner

Effective index buffer, handles the binding offset

public Span<byte> DataInner { get; }

Property Value

Span<byte>

Methods

CopyTo(Span<int>)

public void CopyTo(Span<int> dest)

Parameters

dest Span<int>

CopyTo(Span<ushort>)

public void CopyTo(Span<ushort> dest)

Parameters

dest Span<ushort>

Is32Bit(out Span<int>, out Span<ushort>)

Branch to read the buffer as a 16 or 32 bit buffer, does not allocate

public bool Is32Bit(out Span<int> data32, out Span<ushort> data16)

Parameters

data32 Span<int>
data16 Span<ushort>

Returns

bool

Examples

if (Is32Bit(out var d32, out var d16))
{
    foreach (var value in d32)
    {
        // Your logic for 32 bit
    }
}
else
{
    foreach (var value in d16)
    {
        // Your logic for 16bit
    }
}

To16Bit()

Does not allocate if the buffer is already 16 bit, otherwise allocates a new ushort[] and copies the data into it

public Span<ushort> To16Bit()

Returns

Span<ushort>

To32Bit()

Does not allocate if the buffer is already 32 bit, otherwise allocates a new int[] and copies the data into it

public Span<int> To32Bit()

Returns

Span<int>