OpenGL顶点缓冲区混淆
有人愿意解释一下 VertexBuffer、VertexArray、VertexBufferObject 和 VertexArrayObject 之间的区别吗? ?我什至不确定这些术语是否代表不同的事物,但我已经看到它们都出现在 OpenGL 规范中。
我知道 VertexBuffer 仅包含顶点而没有其他内容,一旦绑定,一旦设置了顶点指针,我就可以使用 DrawArrays 来绘制它。我已经这样做过很多次了。
我正在使用我认为是 VertexArray 的东西,它存储设置的任何顶点缓冲区的状态以及任何顶点指针。绑定 VertexArray 会自动绑定顶点缓冲区并设置顶点指针。我也(大部分)成功地使用了这个。
但是什么是VertexBufferObject和VertexArrayObject?他们更好吗? VertexArray 不能提供我需要的一切吗?
Would someone care to explain the difference to be between a VertexBuffer, a VertexArray, a VertexBufferObject, and a VertexArrayObject? I'm not even sure if these are all terms for different things, but I've seen all of them appear in the OpenGL spec.
I know that a VertexBuffer simply contains vertices and nothing else, once bound, and once I've set the vertex pointers, I can use DrawArrays to draw it. I've done it this way many times.
I am using what I think is a VertexArray, which stores the state of any vertex buffers that are set, and also any vertex pointers. Binding a VertexArray automatically binds the vertex buffer and sets the vertex pointers. I have used this (mostly) successfully too.
But what is a VertexBufferObject, and a VertexArrayObject? Are they better? Doesn't VertexArray give me everything I need?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
顶点数组只是程序中(在地址空间内)的一些数据,您可以通过提供指向它的指针来告知 OpenGL。
虽然比单独指定每个顶点更有效,但它们仍然存在性能问题。 GL 必须在调用 DrawElements(或类似函数)时进行复制,因为这是唯一可以确定数据有效的时间(毕竟,没有什么可以阻止您立即覆盖数据)。这意味着并行性存在重大障碍,因此存在性能问题。
顶点缓冲区对象(“顶点缓冲区”)是您不拥有的原始数据块,即它们不在您的地址空间中。您可以使用 Copy(Sub)Data 将数据复制到缓冲区对象中,也可以将其临时映射到地址空间。一旦取消映射缓冲区,它就不再属于您。巨大的优势在于,现在 GL 可以决定如何处理它以及何时上传它。它知道数据将是有效的,因为您无法访问它。这使得 CPU/GPU 并行性变得更加容易。
顶点数组 abjects 有点用词不当。其中没有顶点或数组。它们只是一种“状态描述块”,封装了一个或多个顶点缓冲区对象的绑定(包括任何 VertexAttribPointer 调用)。因此,它们既是一个方便的函数,而且效率更高(函数调用更少),但并不是绝对必要的。您也可以手动完成 VAO 所做的任何事情。
A vertex array is simply some data in your program (inside your address space) that you tell OpenGL about by providing a pointer to it.
While more efficient than specifying every single vertex individually, they still have performance issues. The GL must make a copy at the time you call DrawElements (or a similar function), because that is the only time it can be certain that the data is valid (after all, nothing prevents you from overwriting the data right away). This means that there is a significant hindrance to parallelism, and thus a performance issue.
Vertex buffer objects ("vertex buffers") are raw blocks of data that you do not own, i.e. they are not in your address space. You can either copy data into the buffer object with Copy(Sub)Data or by temporarily mapping it to your address space. Once you unmap the buffer, it does no longer belong to you. The huge advantage is that now the GL can decide what to do with it, and when to upload it. It knows that the data will be valid, because you cannot access it. This makes CPU/GPU parallelism a lot easier.
Vertex array abjects are a bit of a misnomer. There are no vertices or arrays in them. They are merely a kind of "state description block" which encapsulate the bindings of one or several vertex buffer objects (including any VertexAttribPointer calls). As such, they are both a convenience function and somewhat more efficient (fewer function calls), but not strictly necessary. You could do anything that a VAO does by hand, too.
GL_ARRAY_BUFFER
的命令。GL_ELEMENT_ARRAY_BUFFER
命令。GL_ARRAY_BUFFER
.GL_ELEMENT_ARRAY_BUFFER
.