简体   繁体   中英

Should I delete `Vertex Buffer Object` after binding it to `Vertex Array Objects`?

I created a VBO (Vertex Buffer Object) and VAO (Vertex Array Objects) and did this:

glBindVertexArray(vao);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(...);
glVertexAttribPointer(...);
glEnableVertexAttribArray(0);
glBindVertexArray(0);

Can I delete the vbo after I did this and then draw with the vao assuming everything is in order?

I know that the buffers bind to the vao so I am assuming I can.

The problem is, if I delete the buffer on my computer (Intel graphics) it works great (everything is displayed correctly), but on my friend computer (AMD) there is nothing displayed.

What could be the problem with that?

(By the way, if I don't delete the buffers the program works both on my computer and on my friend's)

Yes, as per OpenGL 4.5, it is legal to delete it after you unbind the VAO .

2.6.1.2 Name Deletion and Object Deletion

If an object is deleted while it is currently in use by a GL context, its name is immediately marked as unused, and some types of objects are automatically unbound from binding points in the current context, as described in section 5.1.2. However, the actual underlying object is not deleted until it is no longer in use. This situation is discussed in more detail in section 5.1.3.

5.1.2 Automatic Unbinding of Deleted Objects

When a buffer, texture, or renderbuffer object is deleted, it is unbound from any bind points it is bound to in the current context, and detached from any attachments of container objects that are bound to the current context, as described for DeleteBuffers, DeleteTextures, and DeleteRenderbuffers. [...] Attachments to unbound container objects, such as deletion of a buffer attached to a vertex array object which is not bound to the context, are not affected and continue to act as references on the deleted object , as described in the following section.

5.1.3 Deleted Object and Object Name Lifetimes

When a buffer, texture, sampler, renderbuffer, query, or sync object is deleted, its name immediately becomes invalid (eg is marked unused), but the underlying object will not be deleted until it is no longer in use .

A buffer, texture, sampler, or renderbuffer object is in use if any of the following conditions are satisfied:

  • the object is attached to any container object
  • [...]

So either it's an AMD driver bug, or the situation is not as you describe.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM