buffer_create_from_vertex_buffer

This function allocates a portion of memory as a buffer in your game filled with the data from a previously created vertex buffer.

The function returns a reference to the buffer that should be stored in a variable and used for all further function calls to the buffer. The function takes a reference to the vertex buffer to use (as returned by the function vertex_create_buffer, for example) with the following constants being used to define the buffer type:

Buffer Type Constant
ConstantDescription
buffer_fixedA buffer of fixed size.
buffer_growA buffer that will "grow" dynamically as data is added
buffer_wrapA buffer where the data will "wrap". When the data being added reaches the limit of the buffer size, the overwrite will be placed back at the start of the buffer, and further writing will continue from that point.
buffer_fastA special "stripped" buffer that is extremely fast to read/write to. Can only be used with buffer_u8 data types, and must be 1 byte aligned.

Apart from the buffer type, you will also have to set the byte alignment for the buffer. This value will vary depending on the data that you wish to store in the buffer, and in most cases a value of 1 is perfectly fine. However, be aware that for some operations a specific alignment is essential, and an incorrect alignment may cause errors (for further details on alignment see Buffers). The following is a general guide to show which values are most appropriate for each data type (when in doubt, use an alignment of 1):

NOTE Vertex buffers are 1 byte aligned, but you can create the buffer with any alignment depending on how you want to treat the data, as the vertex data is simply a raw memory copy into the buffer.

NOTE It's important that you remove any dynamically created resources like this from memory when you no longer need them to prevent memory leaks, so when you are finished with the buffer that you have created you should free it up again using buffer_delete.

NOTE The vertex buffer used to create the new buffer is not removed from memory either and you should use the function vertex_delete_buffer when it is no longer required.

 

Syntax:

buffer_create_from_vertex_buffer(vertex_buffer, type, alignment)

ArgumentTypeDescription
vertex_bufferVertex BufferA reference to the vertex buffer to use.
typeBuffer Type ConstantThe type of buffer to create (see the constants list above).
alignmentRealThe byte alignment for the buffer

 

Returns:

Buffer

 

Example:

player_buffer = buffer_create_from_vertex_buffer(model_buffer, buffer_grow, 1);

The above code allocates memory to a buffer then copies the data from the given vertex buffer into it, returning the new buffer which is stored in the variable player_buffer, for future use.