The only things OpenGL contexts can share is objects. And even then, "container" objects cannot be shared. Container objects are objects whose primary purpose is to have other objects attached to them. Specifically, the following are container objects:
- Framebuffer objects
- Vertex array objects
- Transform feedback objects
- Program pipeline objects
All other objects can be shared.
Sharing objects is a context-based task, usually done either as part of the creation of the context or immediately afterwards. However, since this is done on the context itself, it cannot be a cross-platform operation. OpenGL only defines the behavior of the context, not how to manipulate the context object. The platform-specific APIs responsible for creating and managing contexts handle that: GLX, WGL, EGL, etc.
There are generally two ways this gets handled. One way is for the context creation function to take another context as a parameter; the newly created context will share all sharable objects with the given context. wglCreateContextAttribsARB
is the WGL context creation function that takes a context to share with the new one.
The other ways is to use a function immediately after creating the context. This function takes two contexts and shares objects between them. However, you should use such a function immediately after creating the context; you don't want to create objects in the destination context which might conflict with those already in the source. WGL has an older function, wglShareLists
, that shares objects between contexts. I know it only talks about display lists, but it shares all sharable objects.