vertex_update_buffer_from_buffer

This function updates the contents of a vertex buffer using data in the given buffer.

IMPORTANT You cannot pass a frozen vertex buffer as the destination buffer.

Usage Notes

 

Syntax:

vertex_update_buffer_from_buffer(dest_vbuff, dest_offset, src_buffer[, src_offset, src_size]);

ArgumentTypeDescription
dest_vbuffVertex BufferThe vertex buffer to copy to
dest_offsetRealThe offset in the destination buffer to start writing the data
src_bufferBufferThe source buffer to copy from
src_offsetRealOPTIONAL The offset in bytes in the source buffer to start copying. Defaults to 0.
src_sizeRealOPTIONAL The size of the data in bytes to copy from the source buffer. Defaults to -1. When -1 the whole buffer is copied.

 

Returns:

N/A

 

Example:

vertex_format_begin();
vertex_format_add_position_3d();     // Three buffer_f32 values
vertex_format_add_texcoord();        // Two buffer_f32 values
vertex_format = vertex_format_end();

var _i = 0, _vertex_size = (3 + 2) * buffer_sizeof(buffer_f32), _buff = buffer_create(1000, buffer_fixed, 4);
repeat(51)
{
    repeat(3) buffer_write(_buff, buffer_f32, random(500));        // x, y, z
    repeat(2) buffer_write(_buff, buffer_f32, ((_i++ mod 6) < 3)); // u, v
}

vb = vertex_create_buffer_from_buffer_ext(_buff, vertex_format, 0, 30);
vertex_update_buffer_from_buffer(vb, 0, _buff, 40 * _vertex_size, 3 * _vertex_size);

The code above first creates a new vertex format that consists of a 3D position attribute and a texture coordinate attribute. It then initialises a couple of temporary variables: a loop counter, the source buffer and the size in bytes of a single vertex. The (3 + 2) refers to the three float values used to store a position and the two float values to store a UV coordinate. The buffer is then filled with some random values to create a total of 51 randomly positioned vertices, or 17 triangles, stored as pr_trianglelist (see Primitive Type Constant). After that, a new vertex buffer is created from the first 30 vertices in the buffer. Finally, the first three vertices in this vertex buffer are updated with a call to vertex_update_buffer_from_buffer; they are overwritten with the data of vertex index 40, 41 and 42 in the original buffer.