Question

I'm trying to create an NSOpenGLContext, initialize my rendering engine, then create new NSOpenGLContexts using the share parameter from the first context. This doesn't work, and before I go on, what exactly is shared between a context? The documentation is a little light on this:

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

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

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

Most of those are for three types of tasks - creating vertex and shader programs, storing reference to attrib and uniform locations within the programs, creating vertex arrays, and binding a few textures.

Would you expect all of these items to be shared across contexts?

Was it helpful?

Solution

Function calls are not shared across context. Only objects. And only some objects.

In general, the objects that are shared are those that would be obviously prohibitive to have to re-create on another context. Either due to storing a lot of data, or relatively long setup time.

If you want a list, the following objects are shared:

  • Display lists
  • Textures
  • Renderbuffers
  • Buffer objects
  • Shaders and Programs

Notable objects that aren't shared:

  • Vertex array objects (the buffer objects that go in them are shared, but not the object itself)
  • Framebuffer objects (as with VAOs, only the things that go in them are shared)

An object being shared means that it maintains all state across the contexts. So if you modify state from one context, you will see it in the other. However, this also means you must synchronize your access to shared GL objects if you're using multiple threads. Otherwise race conditions and other badness can occur.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top