buffer_create_from_vertex_buffer_ext

此函数分配一部分内存作为游戏中的缓冲区,并使用之前创建的 顶点缓冲区 中一系列顶点的顶点数据填充它。

该函数返回对缓冲区的引用,该引用应存储在变量中并用于对缓冲区的所有进一步函数调用。该函数获取要使用的顶点缓冲区的引用 (例如,由函数 vertex_create_buffer 返回),并使用以下常量来定义缓冲区类型:

缓冲区类型常数
常量描述
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.

除了缓冲区类型外,您还必须为缓冲区设置字节对齐。该值将根据您希望存储在缓冲区中的数据而有所不同,在大多数情况下,值为 1 是完全正确的。但是请注意,对于某些操作,特定的对齐是必不可少的,不正确的对齐可能会导致错误(有关对齐的更多详细信息,请参阅缓冲区对齐)。以下是显示哪些值最适合每种数据类型的通用指南(如有疑问,请使用 1 的对齐方式):

最后两个参数用于指定要复制到新创建的缓冲区中的顶点数据的范围。起始顶点可以是 0 到顶点数 -1 之间的任意位置,然后给出从该点开始复制的顶点数。您可以在顶点缓冲区上使用函数 vertex_get_number 来获取存储的顶点总数。

注意 顶点缓冲区是 1 字节对齐的,但您可以根据您想要如何处理数据来创建具有任何对齐方式的缓冲区,因为顶点数据只是原始内存复制到缓冲区。

注意 当您不再需要此类动态创建的资源时,请务必将其从内存中删除,以防止内存泄漏,因此当您使用完创建的缓冲区后,应将其释放再次使用 buffer_delete

 

语法:

buffer_create_from_vertex_buffer_ext(vertex_buffer, type, alignment, start_vertex, num_vertices)

参数类型描述
vertex_bufferVertex Buffer对要使用的顶点缓冲区的引用。
type缓冲区类型常数要创建的缓冲区的类型(参见下面的常量列表)。
alignmentReal缓冲区的字节对齐方式。
start_vertexReal起始顶点。
num_verticesReal要复制的顶点总数。

 

返回:

Buffer

 

例子:

var _v_num = vertex_get_number(model_buff);
player_buffer = buffer_create_from_vertex_buffer_ext(model_buffer, buffer_grow, 1, 0, _v_num - 1);

上面的代码将内存分配给缓冲区,然后将给定顶点缓冲区中所有顶点的数据复制到其中,返回新缓冲区。它存储在变量 player_buffer 中以供将来使用。