OpenGL 顶点缓冲区混淆 [英] OpenGL vertex buffer confusion

查看:89
本文介绍了OpenGL 顶点缓冲区混淆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人愿意解释一下 VertexBufferVertexArrayVertexBufferObjectVertexArrayObject<之间的区别吗?/em>?我什至不确定这些是否都是不同事物的术语,但我已经看到它们都出现在 OpenGL 规范中.

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.

我知道 VertexBuffer 只包含顶点而不包含其他任何东西,一旦绑定,一旦我设置了顶点指针,我就可以使用 DrawArrays 来绘制它.我已经这样做过很多次了.

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.

我正在使用我认为是 VertexArray 的东西,它存储设置的任何顶点缓冲区的状态,以及任何顶点指针.绑定一个 VertexArray 会自动绑定顶点缓冲区并设置顶点指针.我也(大部分)成功地使用了这个.

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.

但是什么是 VertexBufferObjectVertexArrayObject?他们更好吗?VertexArray 没有提供我需要的一切吗?

But what is a VertexBufferObject, and a VertexArrayObject? Are they better? Doesn't VertexArray give me everything I need?

推荐答案

顶点数组只是程序中(在地址空间内)的一些数据,您通过提供指向它的指针告诉 OpenGL.
虽然比单独指定每个顶点更有效,但它们仍然存在性能问题.GL 必须在您调用 DrawElements(或类似函数)时进行复制,因为这是唯一可以确定数据有效的时间(毕竟,没有什么可以阻止您立即覆盖数据).这意味着并行性存在重大障碍,从而导致性能问题.

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.

顶点缓冲区对象(顶点缓冲区")是您不拥有的原始数据块,即它们不在您的地址空间中.您可以使用 Copy(Sub)Data 或通过将数据临时映射到您的地址空间来将数据复制到缓冲区对象中.一旦取消映射缓冲区,它就不再属于您.巨大的优势是现在 GL 可以决定如何处理它,以及何时上传它.它知道数据将是有效的,因为您无法访问它.这使得 CPU/GPU 并行化变得更加容易.

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.

顶点数组对象有点用词不当.其中没有顶点或数组.它们只是一种状态描述块",它封装了一个或多个顶点缓冲区对象(包括任何 VertexAttribPointer 调用)的绑定.因此,它们既是一个方便的函数,也更有效(更少的函数调用),但不是绝对必要的.您也可以手动完成 VAO 所做的任何事情.

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.

这篇关于OpenGL 顶点缓冲区混淆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆