understanding removeAll impact on GLCanvas...

I hit this issue once before and for my main display, and I switched to using a CardLayout to flick between various scenes (GLCanvas) in my game.

Now I have a smaller area that I also need to switch between 2 GLCanvas. Initially I was adding and removing from a JPanel parent container. This seems to damage something within the GLCanvas state, even though I still have a solid reference to the GLCanvas, so it’s something about calling removeAll on a JPanel that contains a GLCanvas. I tried using my CardLayout work-around, but in this case I need the panel contents to be sifferent sizes which CardLayout doesn’t seem to handle (everything is as big as largest component?).

Any tips?

update. I’m using a shared context between all the canvases, and I wondering if this is related to textures. I’m gonna have anothe rplay later today and see if I can track down whats going on.

At least from the first post, it sounds like your gl context is being destroyed. This is entirely different from being garbage collected so it doesn’t matter which references you hold to it.

When a glcanvas is removed from the windowing environment, jogl tells the graphics card to destroy the internal context. When it’s added back, a new internal context is associated with the actual GLContext object we pass around.

Generally, if you have the shared context working correctly your textures and other objects shouldn’t go away - so you could still use them on your other GLCanvas. However, I think if you’re just sharing between glcanvas contexts and they’re all ‘destroyed’ at the same time, the graphics card might go ahead and clean it up. I’d recommend trying to create a 1x1 GLPbuffer and using that as the shared context (assuming you haven’t already).

HTH and good luck

well it was late by the time I got back to the code. But from what I can tell it’s Textures that get lost (I’m now using TextureIO). The geometry seems to render fine still. Also I use a text renderer which only renders a blank white box after being removeAll’d. The rest of the scene is unaffected, its only this small side panel that is damaged.

Thanks for the tip with PBuffers, but I already had an issue trying to use these, that many players graphics cards didn’t seem to support them, or maybe I was doing something horribly wrong with them…

In general though, should a removeAll work in the way I’m trying to use it?

IMO you’re asking for a bit of trouble if all you really need to do is switch what you’re drawing. I’d recommend just drawing something different into the canvas when it’s supposed to be ‘switched’. You can resize the canvas, too, without damaging the context so that will probably give you less headaches in the long run.

It’s a bit more than that. I’m switching between a jpanel with a canvas+jbutton, a jpanel just with only jbuttons, a jpanel with just a canvas, and a few other combinations. Sounds perfect for cardlayout, apart from they are all different sizes, which leaves me with removeAll as my only choice, or some ugly padding in smaller panels in the cardlayout.

update: I’m starting to suspect my texture code now. I thought I had textures loading only once, but it seems more like i call TextureIO.newTexture and enable for the first frame in every canvas derivative. So what’s the correct way to share Texture objects? should I be calling disable at some point before using in second contect?