0

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

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);
4

2 回答 2

1

如果您一直在等待问题的答案glBufferData 如何知道要处理哪个 VBO? 这个问题也得到了回答。

OpenGL 是一个状态机并调用 glBindBuffer 选择,它缓冲以下操作。

于 2013-01-05T13:34:04.307 回答
0

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

于 2013-01-05T14:24:18.663 回答