什么是顶点数组对象? [英] What are Vertex Array Objects?

查看:128
本文介绍了什么是顶点数组对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今天才从本教程开始学习OpenGL: http://openglbook.com/the-book /
我进入了第2章,在这里画了一个三角形,并且我了解了VAO之外的所有内容(这个缩写好吗?).本教程具有以下代码:

I am just starting to learn OpenGL today from this tutorial: http://openglbook.com/the-book/
I got to chapter 2, where I draw a triangle, and I understand everything except VAOs (is this acronym OK?). The tutorial has this code:

glGenVertexArrays(1, &VaoId);
glBindVertexArray(VaoId);

虽然我知道代码是必需的,但我不知道它是做什么的.尽管在这一点上我从未使用过VaoId(除非要销毁它),但是如果没有它,代码将无法运行.我假设这是因为必须将其绑定,但是我不知道为什么.这个确切的代码是否仅需要成为每个OpenGL程序的一部分?本教程将VAO解释为:

While I understand that the code is necessary, I have no clue what it does. Although I never use VaoId past this point (except to destroy it), the code does not function without it. I am assuming this is because it is required to be bound, but I don't know why. Does this exact code just need to be part of every OpenGL program? The tutorial explains VAOs as:

顶点数组对象"(或VAO)是描述顶点属性如何存储在顶点缓冲对象"(或VBO)中的对象.这意味着VAO不是存储顶点数据的实际对象,而是顶点数据的描述符.顶点属性可以通过glVertexAttribPointer函数及其两个姊妹函数glVertexAttribIPointer和glVertexAttribLPointer来描述,我们将在下面探究其中的第一个.

A Vertex Array Object (or VAO) is an object that describes how the vertex attributes are stored in a Vertex Buffer Object (or VBO). This means that the VAO is not the actual object storing the vertex data, but the descriptor of the vertex data. Vertex attributes can be described by the glVertexAttribPointer function and its two sister functions glVertexAttribIPointer and glVertexAttribLPointer, the first of which we’ll explore below.

我不了解VAO如何描述顶点属性.我没有以任何方式描述它们.它是否从glVertexAttribPointer获取信息?我想一定是这样. VAO仅仅是glVertexAttribPointer提供信息的目的地吗?

I don't understand how the VAO describes the vertex attributes. I have not described them in any way. Does it get the information from the glVertexAttribPointer? I guess this must be it. Is the VAO simply a destination for the information from glVertexAttribPointer?

另一方面,我关注的教程是否可以接受?我应该注意什么,或者要遵循更好的教程吗?

On a side note, is the tutorial I am following acceptable? Is there anything I should watch out for or a better tutorial to follow?

推荐答案

傻名" OpenGL ARB小组委员会为您提供了顶点数组对象".

"Vertex Array Object" is brought to you by the OpenGL ARB Subcommittee for Silly Names.

将其视为几何对象. (作为旧的SGI Performer程序员,我称它们为geoset.)对象的实例变量/成员是您的顶点指针,普通指针,颜色指针,attrib N指针,...

Think of it as a geometry object. (As an old time SGI Performer programmer, I call them geosets.) The instance variables/members of the object are your vertex pointer, normal pointer, color pointer, attrib N pointer, ...

第一次绑定VAO时,您可以通过以下方式分配这些成员

When a VAO is first bound, you assign these members by calling

glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer...;
glEnableClientState(GL_NORMAL_ARRAY); glNormalPointer...;

,依此类推.启用了哪些属性,您提供的指针存储在VAO中.

and so on. Which attributes are enabled and the pointers you supply are stored in the VAO.

之后,当再次绑定VAO时,所有这些属性和指针也将变为最新.因此,一个glBindVertexArray调用等效于之前设置所有属性所需的所有代码.在无需创建自己的结构或对象的情况下,在函数或方法之间传递几何图形非常方便.

After that when you bind the VAO again, all the those attributes and pointers also become current. So one glBindVertexArray call is equivalent to all the code previously needed to set up all the attributes. It's handy for passing geometry around between functions or methods without having to create your own structs or objects.

(一次设置,多次使用是使用VAO的最简单方法,但是您也可以通过绑定属性并执行更多的使能/指针调用来更改属性.VAO不是常数.)

(One time setup, multiple use is the easiest way to use VAOs, but you can also change attributes just by binding it and doing more enable/pointer calls. VAOs are not constants.)

有关帕特里克问题的更多信息:

More info in response to Patrick's questions:

新创建的VAO的默认值为空(AFAIK).根本没有几何图形,甚至没有顶点,因此,如果尝试绘制几何图形,则会出现OpenGL错误.这是合理的理智,例如将所有内容初始化为False/NULL/zero".

The default for a newly created VAO is that it's empty (AFAIK). No geometry at all, not even vertexes, so if you try to draw it, you'll get an OpenGL error. This is reasonably sane, as in "initialize everything to False/NULL/zero".

设置时只需要glEnableClientState. VAO会记住每个指针的启用/禁用状态.

You only need to glEnableClientState when you set things up. The VAO remembers the enable/disable state for each pointer.

是的,VAO将存储glEnableVertexAttribArrayglVertexAttrib.旧的顶点,法线,颜色,...数组与属性数组,顶点==#0等相同.

Yes the VAO will store glEnableVertexAttribArray and glVertexAttrib. The old vertex, normal, color, ... arrays are the same as attribute arrays, vertex == #0 and so on.

这篇关于什么是顶点数组对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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