Transferring Data Between Buffers

This page gives an overview of how you can transfer data between buffers and vertex buffers.

At the lowest level, a buffer is a contiguous region in memory that consists of bytes. Using the functions buffer_read and buffer_write (and buffer_peekbuffer_poke and buffer_fill) basic data types can be written into a buffer. On top of this, these basic data types can be combined to create data structures where each entry in the structure follows a given format.

Stride

Items stored in a buffer in such a structured way all take up the same number of bytes. This is the number of bytes to move to go from one item to the next and is called the stride.

Buffer to Buffer

The following functions allow copying parts of data from one buffer to another: 

Buffer to Vertex Buffer

A vertex buffer is a special type of buffer. The vertex format determines what data is written to the buffer and in which order. You don't have to write the values directly, but can call functions such as vertex_position_3d, vertex_colourvertex_texcoord, etc.

A few things are specific to vertex buffers: 

The following schematic shows how the data in a vertex buffer maps to the data in a buffer, and the other way around: 

TIP You can use the function vertex_format_get_info to get information on how the data of a vertex in a given format is laid out in a buffer.

The following functions can be used to transfer data between buffers and vertex buffers and vice versa: