问题
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);
回答1:
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.
回答2:
If you'd have waited for answers of your question How does glBufferData know which VBO to work on? this question had been answered as well.
OpenGL is a state machine and calls to glBindBuffer select, which buffer the following operations do work on.
来源:https://stackoverflow.com/questions/14172206/why-is-it-necessary-to-bind-a-buffer-more-than-once-in-succession