Hi. This is the Java 3d subforum, not the Java3d one, isn’t it? So the place to ask questions about OpenGL and Java, too?
For a 2d game in OpenGL (yeah it’s 3d in 2d view) I’ve loads of textures to bind during game play. Many graphics appear on screen for some time and then disappear. Some of them re-appear some time later, some won’t come again.
Currently I’ve got some usage counter per texture. When a sprite uses one, the texture is bound and the usage counter incs. When a sprites disapears forever, its texture’s usage counter decs and when it’s zero the texture is unbound.
While this works, it’s fussily. Also, when new sprites appear and use the same texture an old disappeared sprite used to use, I’ve to rebind the texture. Since they’re being compressed on the fly this is an overhead which I’d like to avoid.
However, maybe this isn’t necessary at all. That’s the question. Would it be sufficient to unbind all textures just at the end of the level? And let the OpenGL driver do the rest? With rest I mean: when new textures are being bound, old ones which doesn’t fit into the gfx card are moved to the PC’s RAM anyway, isn’t it?
Any experiences?
How do high level 3d APIs using OpenGL solve this issue? When, for example, a user loads many 3d models which tons of textures and all of those models could appear in the scene graph? When do they bind the textures, and when unbind?
PS: With “bind” I mean something like this:
gl.glGenTextures(…) to get a new texture ID
then
gl.glBindTexture(GL.GL_TEXTURE_2D, texture’s ID);
With “unbind” I mean this:
gl.glDeleteTextures(texture’s ID)