VAO如何保持缓冲区绑定? [英] How does VAO keep buffer bindings?

查看:132
本文介绍了VAO如何保持缓冲区绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力了解VAO如何准确地处理缓冲区映射. 我正在做什么,可以用下面的伪代码来描述:

I am struggling to understand how exactly VAO is handling buffer mapping. What I'm doing could be described in this pseudocode:

SetUp:
  BindVAO
  BindArrayBuffer
  glBufferData(GL_ARRAY_BUFFER, ExpectedMaxCount, NULL, GL_DYNAMIC_DRAW);//Allocate storage
  glEnableVertexAttribArray
  glVertexAttribPointer

  BindElementBuffer
  Allocate storage (no data yet)

  UnbindVAO
  UnbindArrayBuffer
  UnbindElementBuffer

Draw:
  SubArrayAndElementDataIfNeeded
  BindVAO
  DrawElements

  1. 在调用DrawElements时,OpenGL使用绑定的VAO解析数组和元素缓冲区绑定是否正确?进行Draw调用后,绑定的数组缓冲区为0,但元素缓冲区仍然是用于绘制的缓冲区.

  1. Is this correct that when DrawElements is called OpenGL uses bound VAO to resolve array and element buffer bindings? After a Draw call the bound array buffer is 0, but element buffer is still the one that was used to Draw.

在VAO设置期间是否必须分配缓冲区内存?如果在设置后调用BufferData,VAO会失效吗?

Is it mandatory to allocate buffer memory during VAO setup? Would VAO be invalidated if BufferData was called after setup?

推荐答案

我正在努力了解VAO如何准确地处理缓冲区映射.

I am struggling to understand how exactly VAO is handling buffer mapping.

在缓冲区"周围使用映射"一词时要非常小心;在处理缓冲区对象时具有一种特殊含义,您可能不希望这样做

Be very careful when using the word "mapping" around "buffers"; that has a specific meaning when dealing with buffer objects, one that you probably don't intend.

在调用DrawElements时,OpenGL使用绑定的VAO解析数组和元素缓冲区绑定是否正确?进行Draw调用后,绑定数组缓冲区为0,但是元素缓冲区仍然是用于绘制的缓冲区.

Is this correct that when DrawElements is called OpenGL uses bound VAO to resolve array and element buffer bindings? After a Draw call the bound array buffer is 0, but element buffer is still the one that was used to Draw.

一个与另一个无关.顾名思义,顶点数组对象包含 all 从数组中提取顶点数据所必需的状态.当您绑定一个时,所有状态都会返回到上下文中.

One has nothing to do with the other. A Vertex Array Object, as the name implies, contains all of the state that is necessary to pull vertex data from arrays. When you bind one, all of that state comes back into the context.

调用之后绑定数组缓冲区"之所以为0的原因是调用之前为 .绘图调用不会更改OpenGL状态.

The reason the "bound array buffer" is 0 after the call is because it was 0 before the call. Draw calls do not change OpenGL state.

此外,您似乎迷上了GL_ARRAY_BUFFER陷阱. GL_ARRAY_BUFFER绑定仅与三个功能有关: glVertexAttribPointerglVertexAttribIPointerglVertexAttribLPointer (查看模式?).这些是 only 函数,用于查看该绑定.他们要做的是获取调用这些函数时绑定到的缓冲区,并将该缓冲区与当前VAO关联. GL_ARRAY_BUFFER不是VAO状态的一部分.当您调用这三个函数之一时,缓冲区对象将仅与VAO 关联.拨打电话后,您可以将任何内容绑定到GL_ARRAY_BUFFER.

Furthermore, you seem to have fallen for the GL_ARRAY_BUFFER trap. The GL_ARRAY_BUFFER binding only matters to three functions: glVertexAttribPointer, glVertexAttribIPointer, and glVertexAttribLPointer (see a pattern?). These are the only functions that look at that binding. What they do is take the buffer that is bound at the time these functions are called and associates that buffer with the current VAO. GL_ARRAY_BUFFER is not part of the VAO's state. A buffer object becomes associated with a VAO only when you call one of those three functions. Once you make that call, you can bind whatever you want to GL_ARRAY_BUFFER.

GL_ELEMENT_ARRAY_BUFFER 是VAO状态的一部分.

GL_ELEMENT_ARRAY_BUFFER is part of the VAO's state.

在VAO设置期间是否必须分配缓冲区内存?如果在设置后调用BufferData,VAO会失效吗?

Is it mandatory to allocate buffer memory during VAO setup? Would VAO be invalidated if BufferData was called after setup?

从技术上讲不行,但是在存储之前不使用缓冲区是一种很好的形式.尤其是当它们是静态缓冲区时.

Technically no, but it's good form to not use a buffer until it has storage. Especially if they're static buffers.

这篇关于VAO如何保持缓冲区绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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