每个BindBuffer之后都需要VertexAttribPointer吗?
我注意到,除非重新调用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
tibur 已经回答了实际的问题,但我想我应该添加一些上下文。
glBindBuffer(GL_ARRAY_BUFFER, ...)
本身不执行任何操作。将其视为glVertexAttribPointer
的额外参数。请记住,您可以将多个缓冲区绑定到不同的属性(例如 attrib 0 使用 vbo 1,而 attrib 1 和 2 使用 vbo 2)。对于该设置,您会看到什么 API 顺序?
对于实际的 API,它是这样的:
为什么规范会这样工作?好吧,它的向后兼容性正在抬头。当 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 toglVertexAttribPointer
.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:
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).根据 OpenGL OpenGL 规范,第 51 页(缓冲区对象状态) ,数组指针对应的状态存储缓冲区ID。这意味着如果您想更改用于绘制的缓冲区对象,您需要调用
glVertexAttribPointer
函数。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.