WGL Current context is no longer current after calling Display::new(...)
baehny opened this issue · 3 comments
Creating a new display with Display::new(...)
using WGL, changes the current OpenGL context, or to be more precise unsets the current context. This is caused by the construction and destruction of a temporary context in glutin::wgl::load_extra_functions
.
Call of load_extra_functions
in Display::new
wglMakeCurrent(..)
in load_extra_functions(...)
I'm not sure if there is a good way to restore the original context, but I think this behaviour should atleast be described in the documentation of glutin::wgl::load_extra_functions
and Display::new
.
I hope I have some spare time to provide a suggestion in the next days.
I think the issue is that we even try to do more than one display, because the intention was that you don't do that, but we never added some protection against that.
It's true that we can restore things btw, but what's your use case with multiple displays?
Yes, I created multiple windows and called Display::new
for every window. I could probably refactore my code to create a single instance of Display
. However, finding the issue took me some time so maybe there is a solution that prevents that kind of problem in the first place.
@baehny the Display
is accessible from literally any object, like config
, surface
, etc, so you can create a config and just pass it around getting the display from it.
Yeah, we could probably restore the current context, but it's implicit and could result in un desired behavior.
Glutin should basically disallow creating multiple displays referring to the same native display more than once, since it's how it should work. Display is usually a singleton under the hood (based on native display). It just on windows we must create context + window to get the OpenGL icd loader working, so we can setup context later correctly.