每个BindBuffer之后都需要VertexAttribPointer吗?

发布于 2024-09-18 22:33:44 字数 98 浏览 4 评论 0原文

我注意到,除非重新调用 VertexAttribPointer,否则在 BindBuffer 之后不会有着色器的输入。有必要吗?着色器在写入时可能不会改变,而只会改变所使用的缓冲区。

I noticed that unless I re-call VertexAttribPointer, there's not input to shaders after a BindBuffer. Is that necessary? The shaders may not change in writing but only the buffers used.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

酸甜透明夹心 2024-09-25 22:33:44

tibur 已经回答了实际的问题,但我想我应该添加一些上下文。

glBindBuffer(GL_ARRAY_BUFFER, ...) 本身不执行任何操作。将其视为 glVertexAttribPointer 的额外参数。

请记住,您可以将多个缓冲区绑定到不同的属性(例如 attrib 0 使用 vbo 1,而 attrib 1 和 2 使用 vbo 2)。对于该设置,您会看到什么 API 顺序?

对于实际的 API,它是这样的:

glBindBuffer(GL_ARRAY_BUFFER, 1);
glVertexAttribPointer(0, ...)
glBindBuffer(GL_ARRAY_BUFFER, 2);
glVertexAttribPointer(1, ...)
glVertexAttribPointer(2, ...)

glDraw*(...)

为什么规范会这样工作?好吧,它的向后兼容性正在抬头。当 VBO 被引入时,glVertexPointer 等人。没有任何参数来传递要使用的缓冲区对象。它要么是每个语义的许多新入口点(VertexPointer/NormalPointer/TexCoordPointer...),要么它本身就是一个额外的入口点,它只是充当 *Pointer 调用的额外参数。他们选择了后者(作为旁注,这也是您必须在缓冲区内传递偏移量作为指针的原因)。

tibur already answered to the actual question, but I thought I'd add some context.

glBindBuffer(GL_ARRAY_BUFFER, ...) by itself does not do anything. Think of it as an extra argument to glVertexAttribPointer.

Remember, you can bind multiple buffers to different attributes (say attrib 0 uses vbo 1, while attrib 1 and 2 use vbo 2). What API order would you see for that setup ?

With the actual API, it's something like:

glBindBuffer(GL_ARRAY_BUFFER, 1);
glVertexAttribPointer(0, ...)
glBindBuffer(GL_ARRAY_BUFFER, 2);
glVertexAttribPointer(1, ...)
glVertexAttribPointer(2, ...)

glDraw*(...)

Why would the specification work that way ? Well, it's backwards compatibility rearing its head. When VBOs were introduced, glVertexPointer et al. did not have any parameter to pass which buffer object to use. Either it was many new entrypoints for each semantic (VertexPointer/NormalPointer/TexCoordPointer...), or it was an extra entrypoint by itself, which just was acting as an extra parameter to the *Pointer calls. They chose the latter (as a side note, this is also why you have to pass an offset inside the buffer as a pointer).

恋你朝朝暮暮 2024-09-25 22:33:44

根据 OpenGL OpenGL 规范,第 51 页(缓冲区对象状态) ,数组指针对应的状态存储缓冲区ID。这意味着如果您想更改用于绘制的缓冲区对象,您需要调用glVertexAttribPointer函数。

glBindBuffer(1);
glVertexPointer(...);
glDrawArrays(...); /// Drawing will use buffer 1

glBindBuffer(2);
glDrawArrays(...); /// Drawing will still use buffer 1

glVertexPointer(...);
glDrawArrays(...); /// Drawing will now use buffer 2

According to OpenGL OpenGL specifications, page 51 (Buffer Object State), the state corresponding to the array pointers stores the buffer ID. That means that if you want to change the buffer object to draw with, you need to recall glVertexAttribPointer function.

glBindBuffer(1);
glVertexPointer(...);
glDrawArrays(...); /// Drawing will use buffer 1

glBindBuffer(2);
glDrawArrays(...); /// Drawing will still use buffer 1

glVertexPointer(...);
glDrawArrays(...); /// Drawing will now use buffer 2
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文