OpenGL:缓冲到 VBO 后我还需要一个顶点数组吗?
OpenGL: Do I still need an array of vertices after buffering to VBO?
假设我有一个顶点数组和一个 VBO 指针:
std::vector<Vertex> vertices;
GLuint vbo;
glBindBuffer(GL_ARRAY_BUFFER, vbo);
现在我缓冲数据:
glBufferData(
GL_ARRAY_BUFFER,
vertices.size()*sizeof(Vertex),
&vertices[0],
GL_STATIC_DRAW
);
如果我理解正确,由于 GL_STATIC_DRAW
,我仍然需要保留顶点数组。但是,如果我将其更改为 GL_STATIC_COPY
,那么所有数据都将被复制到 GPU 的内存中,这样我就可以释放 vertices
使用的内存。那是对的吗?如果是这样,为什么我们需要 *_DRAW
?由于 GPU 的内存限制,这有用吗?另外 GL_STATIC_READ
是如何工作的?
所有这些都在 glBufferData()
手册页中进行了解释。
https://www.opengl.org/sdk/docs/man/html/glBufferData.xhtml
您不需要在程序内存中保留额外的副本。 glBufferData()
的全部目的是将数据从你的程序复制到 OpenGL 缓冲区,一旦复制完成,你就可以用你的程序内存做任何你想做的事。
If data is not NULL, the data store is initialized with data from this pointer.
不要使用 GL_STATIC_COPY
,那是不正确的。文档内容如下:
COPY
The data store contents are modified by reading data from the GL, and used as the source for GL drawing and image specification commands.
因此 GL_STATIC_COPY
仅适用于不同 OpenGL 缓冲区之间的内部副本,不适用于从您的应用程序到 OpenGL 的副本。使用 DRAW
.
假设我有一个顶点数组和一个 VBO 指针:
std::vector<Vertex> vertices;
GLuint vbo;
glBindBuffer(GL_ARRAY_BUFFER, vbo);
现在我缓冲数据:
glBufferData(
GL_ARRAY_BUFFER,
vertices.size()*sizeof(Vertex),
&vertices[0],
GL_STATIC_DRAW
);
如果我理解正确,由于 GL_STATIC_DRAW
,我仍然需要保留顶点数组。但是,如果我将其更改为 GL_STATIC_COPY
,那么所有数据都将被复制到 GPU 的内存中,这样我就可以释放 vertices
使用的内存。那是对的吗?如果是这样,为什么我们需要 *_DRAW
?由于 GPU 的内存限制,这有用吗?另外 GL_STATIC_READ
是如何工作的?
所有这些都在 glBufferData()
手册页中进行了解释。
https://www.opengl.org/sdk/docs/man/html/glBufferData.xhtml
您不需要在程序内存中保留额外的副本。 glBufferData()
的全部目的是将数据从你的程序复制到 OpenGL 缓冲区,一旦复制完成,你就可以用你的程序内存做任何你想做的事。
If data is not NULL, the data store is initialized with data from this pointer.
不要使用 GL_STATIC_COPY
,那是不正确的。文档内容如下:
COPY
The data store contents are modified by reading data from the GL, and used as the source for GL drawing and image specification commands.
因此 GL_STATIC_COPY
仅适用于不同 OpenGL 缓冲区之间的内部副本,不适用于从您的应用程序到 OpenGL 的副本。使用 DRAW
.