I’m looking into an issue where a call to
wglCreateContextAttribsARB() fails when I try to create a shared OpenGL context.
I use GLFW to create a basic window and GL 4.1 context. I retrieve the HDC and GL context. I pass the HDC and GL context into a new thread and do the whole OpenGL context creation flow there (i.e. creating a dymmy context, retrieve the function pointer to
wglCreateContextAttribsARB() etc.). When I call
wglCreateContextAttribsARB() it fails with an INVALID_OPERATION.
My guess is that I get a INVALID_OPERATION because of this paragraph from the specs:
If the OpenGL server context state for exists in an address space that cannot be shared with the newly created context, if was created on a different device context than the one referenced by hDC, or if the contexts are otherwise incompatible (for example, one context being associated with a hardware device driver and the other with a software renderer), then ERROR_INVALID_OPERATION is generated.
Though if I’m correct, the address should be the same, but I’m not 100% certain about that. What I do know, is that when I copy/paste the code which is executed in the thread to my main thread, that everything works and the call to
wglCreateContextAttribsARB() returns a new context.
Is it possible that it’s not allowed to create a GL context in thread A and another one in thread B, where thread B shares the context from thread A … and should they be created in the same thread? I tested with creating two contexts from the main thread and then use the second context in another thread and that also works fine.