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

book_4_sparkGenerated
code_blocksInput

Description

The SetData method is used to upload data from the CPU to the GPU buffer. This method allows you to specify a span of data to be copied into the buffer, starting at a specified offset within the buffer. 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 will be copied.

Ensure that the buffer has been properly initialized and that the data being uploaded fits within the buffer's capacity, starting from the specified offset.

Example

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

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

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

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

// Clean up
buffer.Dispose();