OpenGL: Strange bahaviour of VBO deletion?

396 views Asked by At

I am getting a strange issue in Vertex Buffer Object (VBO). I created a class that includes VBO creation and deletion. I delete all the VBOs (with glDeleteBuffers()) in the destructor of the class.

Now I created 2 OpenGL context windows each running with VBO class. Now when I close one GLwindow its destructor calls and VBO also gets deleted, but the strange things is this destructor effect on the 2nd window, the object running on the second window disappears. When I render with deprecated glVertex3fv, I can see the object but not with VBO. If I don't delete VBO with the destructor of the GLwindow class, everything works fine. Shouldn't I delete VBO with each context deletion?

My question is why it is happening? I know OpenGL is a state machine but can't we make a complete new independent class object?

I noticed the same effect with (glDeleteTextures()) If I don't delete texture with the destructor, nothing strange happens but if I delete one Glwindows texture, it effect on the 2nd Glwindow rendered and texture gets disappear.

Is it known issue or its only happening with me?

1

There are 1 answers

2
datenwolf On BEST ANSWER

Reto Koradi already mentioned copy semantics. Another thing to keep in mind is that OpenGL allows context sharing, i.e. some objects are shared between the OpenGL contexts and deleting in one context deletes it from all contexts. Objects transcending shared contexts are

  • textures
  • buffer objects that are bound using glBindBuffer
  • render buffers

among the objects not transcending shared contexts are

  • framebuffer objects
  • vertex array objects