【发布时间】:2020-09-23 22:49:56
【问题描述】:
我创建了一个带有 2 个顶点数组缓冲区的 VAO。第一个缓冲区包含顶点的坐标,而第二个缓冲区包含每个顶点的 4 个数据值(GLbyte 类型)。
/*
** Create a VAO and bind it
*/
glCreateVertexArrays(1, &vertex_array_object);
glBindVertexArray(vertex_array_object);
/*
** Create a buffer and initilise it
*/
glCreateBuffers(1, &vertex_buffer);
glNamedBufferStorage(vertex_buffer, sizeof(verticies), verticies, 0);
/*
** Bind the buffer to the VAO
*/
glVertexArrayVertexBuffer(vertex_array_object, 0, vertex_buffer, 0, sizeof(float)*3);
/*
** Specify the data format,
*/
glVertexArrayAttribFormat(vertex_array_object,0, 3, GL_FLOAT, GL_FALSE, 0);
/*
** Specify the vertex buffer binding for this attribute
*/
glVertexArrayAttribBinding(vertex_array_object,0,0);
/*
** Enable the attribute
*/
glEnableVertexArrayAttrib(vertex_array_object,0);
/*
** Now repeat for another buffer to hold per vertex data
**
** Create and initilise it
*/
glCreateBuffers(1, &nvd_buffer);
glNamedBufferStorage(nvd_buffer, sizeof(vectors), vectors, 0);
/*
** Bind the buffer to the VAO
*/
glVertexArrayVertexBuffer(vertex_array_object, 1, nvd_buffer, 0, sizeof(GLbyte)*4);
/*
** Specify the data format,
*/
glVertexArrayAttribFormat(vertex_array_object, 1, 4, GL_BYTE, GL_FALSE, 0);
/*
** Specify the vertex buffer binding for this attribute
*/
glVertexArrayAttribBinding(vertex_array_object,1,1);
/*
** Enable the attribute
*/
glEnableVertexArrayAttrib(vertex_array_object,1);
这一切正常,我的顶点着色器可以访问第二个缓冲区中的数据并将其传递给几何着色器,用于创建额外的点。
稍后我想更新第二个缓冲区中的数据,但我不知道该怎么做。我想我应该使用
glNamedBufferSubData(....)
但我不知道如何从 VAO 获取需要输入此函数的缓冲区。我知道我可以存储分配给“nvd_buffer”的原始值,但是有没有办法直接从 VAO 获取此信息,因为我知道我用来将缓冲区绑定到 VAO 的绑定索引
glVertexArrayVertexBuffer(vertex_array_object, 1, nvd_buffer, 0, sizeof(GLbyte)*4);
【问题讨论】: