void SetData( System.Span<T> data, int elementOffset )
void SetData( List<T> data, int elementOffset )

robot_2Generated
code_blocksInput

Description

The SetData method of the GpuBuffer class is used to upload data from the CPU to the GPU. This method allows you to specify a span of data to be copied into the GPU buffer starting at a specified offset. This is useful for updating a portion of the buffer without affecting the entire data set.

Usage

To use the SetData method, you need to have an instance of GpuBuffer and a data source that you want to upload to the GPU. The data source should be a System.Span<T> where T is the type of data you are working with. You also need to specify the elementOffset, which indicates the starting position in the buffer where the data should be copied.

Ensure that the buffer has been properly initialized and that the data span does not exceed the buffer's capacity starting from the specified offset.

Example

// Define a data structure
struct MyData
{
    public float Value;
}

// Create a GpuBuffer instance
GpuBuffer<MyData> buffer = new GpuBuffer<MyData>(10);

// Prepare data to upload
MyData[] data = new MyData[]
{
    new MyData { Value = 1.0f },
    new MyData { Value = 2.0f }
};

// Use SetData to upload data to the GPU buffer starting at offset 0
buffer.SetData(data, 0);

// Clean up
buffer.Dispose();