Obviously the scope of an OpenGL texture unit is no wider than a single process — on the same system, multiple processes can each glActiveTexture(GL_TEXTURE0); glBindTexture(...);
, and things work just fine — textures don't get mixed up between processes.
But, among shared OpenGL contexts within a single process, are texture units independent or shared?
In other words, can I expect this to work?
// Create a base context and bind one texture to GL_TEXTURE0
CGLContextObj baseContext = createGLContext(NULL);
{
CGLContextObj cgl_ctx = baseContext;
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, 1);
// ...render continuously...
}
// On a separate thread, create a context shared with baseContext and bind a _different_ texture to GL_TEXTURE0
{
CGLContextObj cgl_ctx = createGLContext(baseContext);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, 2);
// ...render continuously...
}
...or, on the second context, should I be using GL_TEXTURE1
?
Is this documented anywhere? (I've scoured the opengl.org man pages and wiki, but didn't find anything explaining this scenario. For example, http://www.opengl.org/wiki/OpenGL_Context says that texture, buffer, and program objects are shared, but says nothing about texture units.)
Effectively context resource sharing is limited to objects that actually define a data store, and is disabled by default in most window system implementations.
Each context maintains its own state machine, the only things you share in this example are the texture objects themselves. That is to say, you can use the same texture name (GLuint
ID) to reference the texture between contexts, but texture unit state is completely unique to each context.
If you issue a draw command from one context where texture A is bound to unit 0 then the shader will use texture A anytime it samples from texture unit 0. If you issue the same draw command from a context where texture B is bound to unit 0, then the shader will sample texture B.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With