I’m currently porting a Direct3D9 based rendering path to OpenGL. I’m not sure how should I handle lost device in OpenGL or detect it so that to prevent a crash if another full screen application took over control of the device and its resources.
At what point I need to recreate the resources (textures/buffers/shaders/…) and what’s the equivalent to D3D Reset device in OpenGL?
OpenGL doesn’t have any concept of a lost device (not does it have any concept of an exclusive mode); if any handling is necessary the driver will do it for you.
But what if the competing application is Direct3D and it took exclusive ownership of the device? Does OpenGL take care of this internally?
But what if the competing application is Direct3D and it took exclusive ownership of the device?
You’re really overthinking this. MSDN defines exclusive mode as:
“Exclusive mode means that devices created by any other Direct3D object can neither assume full-screen operations nor allocate video memory.”
Nothing here is said about OpenGL applications; they are governed by the OpenGL specification which does not allow implementations to spontaneously lose data.
The only time when OpenGL allows any data to be lost is during the mapping of a buffer object. That is, while a buffer is mapped, it’s data could possibly be lost. When you unmap a buffer, you can test the return value to see if this has happened.
I don’t think it would be able to get exclusive mode if another app was using it, even if in a non-exclusive mode. CreateDevice or Reset would likely fail.
Take that with a grain of salt - it’s something that would need to be tested.