为什么有必要连续多次绑定一个缓冲区? [英] Why is it necessary to bind a buffer more than once in succession?

查看:117
本文介绍了为什么有必要连续多次绑定一个缓冲区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
glBufferData如何知道要在哪个VBO上工作?

Possible Duplicate:
How does glBufferData know which VBO to work on?

我已经在VBO和渲染缓冲区的示例代码中(在一本O'Reilly的书中)注意到绑定进行了多次.这背后的原因是什么?例如,您可能将其放在OpenGL例程的顶部:

I've noticed in sample code (in an O'Reilly book) for both VBOs and render buffers that the binding is done more than once. What is the reasoning behind this? For example, you might have this at the top of an OpenGL routine:

  glGenBuffers(1, &m_vertexBuffer); 
  glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer);

然后在绘制图形之前,请先进行以下操作:

And then before doing the drawing, you do it again:

  glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer); 
  glVertexPointer(3, GL_FLOAT, sizeof(Vertex), 0);
  //on to the drawing routine

删除其中任何一个都会导致图形不显示,为什么它需要绑定两次?

Removing either of these causes the drawing to not appear, so why does it need binding twice?

另一个例子,我们首先这样做:

Another example first we do this:

// Create & bind the color buffer so that the caller can allocate its space.      
   glGenRenderbuffersOES(1, &m_colorRenderbuffer); 
   glBindRenderbufferOES(GL_RENDERBUFFER_OES, m_colorRenderbuffer);

然后,在创建顶点等之后,我们稍后再做一次:

Then, after creating vertices, etc, we later we do it again:

   // Bind the color buffer for rendering. 
      glBindRenderbufferOES(GL_RENDERBUFFER_OES, m_colorRenderbuffer);

推荐答案

不必连续多次绑定同一缓冲区.一次就足够了.在带有数组缓冲区的示例中,如果在绘制例程之前绑定到另一个(或默认值为0)缓冲区,则绘制可能不会出现.

It is not necessary to bind the same buffer more than once in succession. It is enough to do it once. In your sample with array buffer, drawing might not appear if you are making a binding to another (or a default 0) buffer before drawing routine.

这篇关于为什么有必要连续多次绑定一个缓冲区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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