每个BindBuffer之后需要VertexAttribPointer吗? [英] is VertexAttribPointer needed after each BindBuffer?

查看:142
本文介绍了每个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.

推荐答案

tibur已经回答了实际问题,但我想我会添加一些上下文.

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

glBindBuffer(GL_ARRAY_BUFFER, ...)本身不执行任何操作.可以将它视为glVertexAttribPointer的附加参数.

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

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

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 ?

使用实际的API,就像这样:

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*(...)

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

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).

这篇关于每个BindBuffer之后需要VertexAttribPointer吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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