1

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?

genpfault
  • 51,148
  • 11
  • 85
  • 139
maxpayne
  • 1,111
  • 2
  • 21
  • 41
  • @genpfault What's wrong? Isn't it a right question? strange... – maxpayne Jun 19 '15 at 23:10
  • 2
    You probably got a close vote because you didn't post code. People often run into mysterious problems when wrapping OpenGL objects in C++. The reason is almost always that the objects get copied/assigned for some reason, but don't have proper copy semantics. See my answer here for some examples and background: http://stackoverflow.com/questions/28929452/mesh-class-called-with-default-constructor-not-working-opengl-c/28930189#28930189. – Reto Koradi Jun 19 '15 at 23:53
  • Thanks a lot Koradi.. Your answer all i was needed. Much appreciated.. – maxpayne Jun 20 '15 at 00:26
  • Hi Koradi, I found the issue, the problem is in multiple contexts of QGLWidget. I am creating multiple GLwindows with VBO rendering. When one window is activated/focused/selected/calling the mouse move event with makecurrent, vbo works fine, but when the other windows deactivated/defocused/deselected, it doesn't take effect from its own VBO object, but it take the last selected window's VBO. – maxpayne Jun 22 '15 at 08:29
  • For example, if I want to translate the object, I go to Qtreewidget and right click on it, and press translate, click on the QtreeWidget activate the QGLwidget and I update the VBO. Now I translate the second window's VBO object, it doesn't work. It only works if I move my mouse on both of the window's renderers because it calls the mouse move event with makecurrent() call. So, I tried every trick but nothing is working, I don't know why VBO doesn't work when the MDI window is not activated. – maxpayne Jun 22 '15 at 08:29

1 Answers1

0

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
datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • Thanks datenwolf, could you please check my latest comments answered to Koradi? I don't know how would I solve this issue? I just gave up on it. Should I use VAO now? – maxpayne Jun 22 '15 at 08:32
  • @furqan: Without seeing any of your actual code it's hard to give any useful advice. 10 lines of code are often worth ten thousand words. – datenwolf Jun 22 '15 at 20:34