What exactly is shared between two NSOpenGLContexts?

I am trying to create an NSOpenGLContext, initialize my rendering engine, and then create new NSOpenGLContexts using the share parameter from the first context. This does not work, and before I continue, what exactly is shared between the context? The documentation is highlighted a bit on this:

Shared contexts share all texture objects, display lists, vertex programs, fragment programs, and buffer objects created before and after sharing. The state of objects is also a general, but not other contextual state, such as the current color, texture coordinate settings, matrix and lighting settings, rasterization state and texture settings.

When I create my first NSOpenGLContext, I initialize my rendering engine, which calls the following types of calls:

  • glGenTextures, glActiveTexture, glBindTexture
  • glEnable
  • glUseProgram, glGetAttribLocation, glGetUniformLocation
  • glUniform1i, glUniform3f
  • glGenVertexArraysAPPLE, glBindVertexArrayAPPLE, glBindBuffer
  • glVertexAttribPointer, glEnableVertexAttribArray

Most of them are designed for three types of tasks: creating vertex and shader programs, storing attribute references and uniform locations in programs, creating vertex arrays and snapping several textures.

Do you expect all of these elements to be available in different contexts?

+4
source share
1 answer

Function calls are not used in context. Only objects. And only some objects.

In general, shared objects are those that are obviously not permissible for re-creation in a different context. Either due to the storage of a large amount of data, or the relatively long setup time.

If you need a list, the following are common objects:

  • Show Lists
  • textures
  • Renderbuffers
  • Buffer objects
  • Shaders and programs

Known objects that are not shared:

  • Vertex array objects (the buffer objects that go into them are shared, but not by the object itself)
  • Framebuffer objects (as in VAO, general information only).

A shared resource means that it supports all states in contexts. Therefore, if you change state from one context, you will see it in another. However, this also means that you must synchronize your access to shared GL objects if you use multiple threads. Otherwise, race conditions and other troubles may arise.

+4
source

Source: https://habr.com/ru/post/1398965/


All Articles