0

I have a problem, when i destroy the openGL context and later recreate it and call glGenTextures then it's gave me already past used id(s). This is a problem because those ids are potentially still assigned to some texture wrapper that are in some background thread that didn't yet have the time to call glDeleteTextures. So when these background thread will call glDeleteTextures then they will delete new texture instead :(

so is their a way for force glGenTextures to be always auto incremented even after deleting/recreating the OpenGl context ?

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
noa
  • 59
  • 8
  • 2
    If you still are using a resource that was already freed then you have design problem at your hands – Amadeus Sep 28 '17 at 19:59
  • it's not my fault, it's android that decide the delete the context not me :( and when we play in multithread it's not easy to manage everything – noa Sep 28 '17 at 20:14

3 Answers3

1

No. You can not change OpenGL API implementation.

Your problem can be easily solved by not deleting the context until all operations that use it are finished, whatever thread uses that context.

By the way, deleting and recreating a context is expensive. I don't see a reason to do it.

Ripi2
  • 7,031
  • 1
  • 17
  • 33
  • "By the way, deleting and recreating a context is expensive. I don't see a reason to do it." ... android :) android delete the context when the app pause and resume :( – noa Sep 28 '17 at 20:12
  • Found [this](https://stackoverflow.com/questions/11067881/android-when-is-opengl-context-destroyed) and [this](https://gamedev.stackexchange.com/questions/12629/workaround-to-losing-the-opengl-context-when-android-pauses) – Ripi2 Sep 28 '17 at 20:25
  • thanks Ripi2! i found this video that explain the behavior: https://www.youtube.com/watch?v=NHVtLC5QOpo ... i try many think but their is no way to be sure android will not delete the context, and as you see in the demo, they say simply look for the answer of any opengl funtion if it's return error to know if android delete the openGL context :( crazy :( – noa Sep 28 '17 at 21:01
1

There is no way to make an OpenGL context remember which object names the last context used. However, that doesn't mean that you can't remember which names go with which contexts. It's fairly easy.

Every texture object that is going to be deleted should have two pieces of information: the texture name (the integer) and a value that represents the context that created the object. When you go to delete that texture, you first check to see if the context is the same context that created it. If not, then you just drop it on the floor.

The easiest way to do this is to have an atomic integer that gets incremented every time a context is created. Every time you create a texture, you also should get the context integer that goes along with it. When deleting textures, if the integer context in the texture doesn't match the current one, then you don't delete it.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
-1

According to Khronos specification:

Texture names returned by a call to glGenTextures are not returned by subsequent calls, unless they are first deleted with glDeleteTextures.

So you won't get an ID that is still in use.

Reaper
  • 747
  • 1
  • 5
  • 15