I'm trying to understand why the OPENGL backend can't seem to work more than one window/context at a time. In DisplayWGL.cpp DisplayWGL::makeCurrent is where eglMakeCurrent is supposed to change the context by proxy.
However, every time I pass a display/surface/context triplet through this, that are distinct, when it gets to its guard it always prevents calling wglMakeCurrent:
if (newDC != currentContext.dc || newContext != currentContext.glrc)
{
ASSERT(newDC != 0);
if (!mFunctionsWGL->makeCurrent(newDC, newContext))
{
// TODO(geofflang): What error type here?
return egl::EglContextLost() << "Failed to make the WGL context current.";
}
currentContext.dc = newDC;
currentContext.glrc = newContext;
}
The net effect of this is the first created context is always the current context even after eglMakeCurrent appears to succeed. Calls to glViewport (for example) that work with the same app under D3D11 and non-ANGLE context change the viewport of the first made/bound context's instead of the context that last called eglMakeCurrent.
In the same function at the top it has:
CurrentNativeContext ¤tContext = mCurrentNativeContexts[std::this_thread::get_id()];
For me this vector has 1 element, suggesting 1 thread. The currentContext.dc and currentContext.glrc members are always different when
DisplayWGL::makeCurrent is entered. It looks like it's already matching the values it's compared to in the guard. That suggests that it's already done the change. But if it did then the real wglMakeCurrent context shouldn't be changing the viewport for the first made context in fact.
There's no other calls to wglMakeCurrent in my app I'm seeing this with. I.e. ANGLE is fully in control of OpenGL/WGL. At least I'm pretty sure (I make mistakes sometimes.)
What's glaring is if I look for mFunctionsWGL->makeCurrent in that file, I see this all over the place in the file. This is actually calling wglMakeCurrent. It doesn't add to me why ANGLE would changing the current context autonomously all over the place. It seems like there should only one path to it that's delegated to the user via eglMakeCurrent, but if not it seems like any one of these could be a source of problems. But I never actually see it called via eglMakeCurrent, so it seems like the simplest explanation is somehow this guard always fails for multiple windows/contexts and so the context never changes.
What's worse is after eglDestroyContext maybe it can't switch to a new context. I filed a bug earlier today (
https://bugs.chromium.org/p/angleproject/issues/detail?id=6092) that gets trapped in ClearError because there's no context when it calls glGetError in a loop. At the time I reported the bug I thought this was because I had some wglMakeContext(0,0) calls in places that I felt (probably rightly) were interfering with ANGLE. (The bug is clear cut regardless of what triggers it) however in this case I've removed those to make sure there's no interference, and still encounter this bug after
eglDestroyContext, suggesting this is another way to enter the same ClearError endless loop bug.
I think my build is kosher. I don't know what could account for this other than everyone else is putting their contexts/windows on separate threads. Anyway I hope this post is productive. Sorry if not. I worry I'm being overbearing today. Here (
https://groups.google.com/g/angleproject/c/qnQo1kK1vKQ) is another post from earlier, I'm really trying to get one backend that can work for my short term needs. D3D11 doesn't seem to handle resizing windows well, whereas OPENGL does, but doesn't seem to handle more than one window at a time. At least not in my set up.