I am creating an application using OpenGL (4.2). By default, the rendering is done on a panel in a window, it works without issues, but the panel can be docked/undocked, which causes the underlying window handle to change, therefore I am recreating the context.
There are no errors (glGetError = GL_NO_ERROR), the context exists (wglGetCurrentContext returns nonzero).
// This snippet happens in response to window handle changed.
fDC := GetDC(Handle); // Always recreate DC
if not fIsGlInitialized then
fRC := CreateRenderingContextVersion(fDC, ...); // Only one RC
wglMakeCurrent(fDC, fRC); // Edit: Fails with ERROR_INVALID_PIXEL_FORMAT
fIsGlInitialized := True;
InitOpenGL(); // Reload OpenGL function pointers just in case
However, after the handle changes, there is nothing rendered (the panel just has default gray color).
What is the correct way of recreating the context, assuming I want to keep my OpenGL objects (such as VAOs)?
Tried recreating the rendering context: Causes Invalid Operation on glBindVertexArray with VAO created in the old context.
Tried using wglShareLists: Same error although I am not sure I used it correctly, I have seen people complaining it's legacy and some drivers are buggy, also I don't need multiple living contexts.
Tried creating new rendering context, using wglCopyContext(oldRC, fRC, GL_ALL_ATTRIB_BITS) and wglDeleteContext(oldRC), causes the same error.
wglMakeCurrentreturn? About context sharing: Please check which objects can be shared; VAOs are not sharable.wglMakeCurrentreturns True at first, but False after docking withGetLastErrorERROR_INVALID_PIXEL_FORMAT. If VAOs can't be transferred, what is the proper way of handling this, recreate all buffers from scratch in the new context?glGenBuffers) are shared and do not have to be copied. Note, that the VAO itself does not store any data, it only stores which buffers are bound and to which attachment points they are bound. The data itself still resides in the buffer objects.