R – OpenGL textures with multiple display contexts

opengltextures

I have an undefined number of display context and each will display a texture. When I call glGenTextures I get the same name returned across all display contexts. Will this work? Even though they have the same name will they still store and display different textures? If not what should do to get around this?

Best Solution

Getting the same name from glGenTexture and having the same texture displayed is not the same thing.

Texture names are just integers at a context's discretion, usually starting with 1, and incrementing with every glGenTexture, but not necessarily so. An implementation is not required to work like that (although most do). However, you could in theory also get any more or less "random" number, such for example an integer that increments for any kind of object (i.e. not just textures, but also buffers and shaders), or even a 32 bit pointer address in the driver's address space, or some other esotheric thing. There is no requirement that a name must be something specific.

In legacy OpenGL, you could even make up your own names instead of using glGenTexture, but that is no longer legal now. I'm not sure what they thought when that was allowed, but anyway... :)

The same number (name) in a different context will usually be a different texture, or possibly no texture at all. So, if you do see the same texture in different context with the same texture name, then you either have shared contexts, or the driver is buggy.

Note that if you use wglCreateContextAttribsARB, the second parameter is the handle of an already existing context (or null). If you supply a context handle here, you will have shared contexts even without explicitly calling glShareLists. Maybe that is what happened by accident.

Related Question