Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is shareable between OpenGL contexts and how to enable sharing

Tags:

opengl

I'm making a CAD software that will create different OpenGL contexts for similar view (if they aren't showing the same thing).

I would like to share much data as possible between them OpenGL contexts, especially VBOs and shaders.

I want to know what I can share and how I share them, in a cross-platform way and possibly with plain OpenGL 3.2 (no engine).

like image 850
Devilish Spirits Avatar asked Apr 27 '19 21:04

Devilish Spirits


People also ask

What is shared context in OpenGL?

A context's objects can be shared with other contexts. Most OpenGL objects are sharable, including Sync Objects and GLSL Objects. Container Objects are not sharable, nor are Query Objects. Any object sharing must be made explicitly, either as the context is created or before a newly created context creates any objects.

What is the OpenGL context?

An OpenGL rendering context is a port through which all OpenGL commands pass. Every thread that makes OpenGL calls must have a current rendering context. Rendering contexts link OpenGL to the Windows windowing systems. An application specifies a Windows device context when it creates a rendering context.

What is a rendering context?

A rendering context is a container for state information. When you designate a rendering context as the current rendering context, subsequent OpenGL commands modify that context's state, objects attached to that context, or the drawable object associated with that context.

What is OpenGL profile?

OpenGL (Open Graphics Library) is a cross-language, cross-platform application programming interface (API) for rendering 2D and 3D vector graphics. The API is typically used to interact with a graphics processing unit (GPU), to achieve hardware-accelerated rendering.


1 Answers

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.

like image 200
Nicol Bolas Avatar answered Sep 23 '22 02:09

Nicol Bolas