Howdy-
I’m rendering to several GLJPanels with some texture mapping. I’m trying to determine when I need to allocate a new texture id. I’d ideally like to have code that I can call at any time from display() saying “use texture foo”, without having to do any external initialization, or tracking whether I’ve initialized the texture in that context previously. E.g., just call:
TextureManager.bind(“RedBrick”, gl)
and it will register the new texture (via glGenTextures) as needed, or reuse a previously allocated texture id if it has one. To do this, I was maintaining a map from gl instances to texture ids for each texture. If the map had no entry for a gl, I called glGenTextures and added a new entry to the map.
This mostly works. But the gl object changes for a GLJPanel as the viewport is increased in size, causing my code to think it needs to reallocate the texture. But it appears that the new GL context has a shared context with the original context (in which I already allocated the texture.) So the result is that I’ve allocated the same texture twice (and gotten two different ids), presumably wasting memory somewhere.
How can I reliably determine which rendering context I’m in, so that I can correctly allocate new texture ids only when its necessary?
Or, is the usual OpenGL-ism to create all the viewports with shared contexts, in which case I only need to track whether or not I’ve registered the texture at least once? (I’m new to OpenGL coding.)
And as a random aside, do I need to be concerned about the memory footprint of the textures I allocate and bind, separately from the size of the textures actually used during rendering? Does the GL driver do the right magic to swap textures in/out of video RAM automatically?
Thanks!