One caveat: to be completely safe, we need to ensure that the gl_context is not current to any other thread (e.g. the snapshoting thread) when we make current in the destructor. You would guess that destroying a thread with a current context (e.g. when the internal snapshotting thread is destroyed) would unbind that context, but unfortunately, at least in Mesa, that's not the case. That is:
T1: create context C
T2: make current C
T2: ~destroy
T1: make current C => fails at least with Mesa, haven't tried on the phone
This sounds like a problem with Mesa since the current context is thread specific state, and it make no sense to keep a context associated with a non-existent thread, but perhaps the spec is vague and Mesa interprets it differently. We should verify the expected behavior with Khronos and fix Mesa if needed.
One caveat: to be completely safe, we need to ensure that the gl_context is not current to any other thread (e.g. the snapshoting thread) when we make current in the destructor. You would guess that destroying a thread with a current context (e.g. when the internal snapshotting thread is destroyed) would unbind that context, but unfortunately, at least in Mesa, that's not the case. That is:
T1: create context C
T2: make current C
T2: ~destroy
T1: make current C => fails at least with Mesa, haven't tried on the phone
This sounds like a problem with Mesa since the current context is thread specific state, and it make no sense to keep a context associated with a non-existent thread, but perhaps the spec is vague and Mesa interprets it differently. We should verify the expected behavior with Khronos and fix Mesa if needed.