I'm really fighting with this, and there's gotta be a better way. I'm a complete newb and am probably just being stupid
My game can run in several distinct modes, and it's possible the user can play an entire game and only ever enter one mode. So classes for modes are only loaded as needed. This is causing a problem with texture loading.
As I understand it textures should only really be loaded in init(), but loading them in display() should work too since I've got the GL thread's full attention. Obviously loading textures in display() is not ideal, but it's also not bad because the first calls to display() are usually trivial things like displaying menus and such. By the time the game is really running everything is loaded and fine.
So what I've done is in init() I've requested 100 textures from glGenTextures(). Then I keep track of which ones of those I've handed out.
Whenever someone needs a texture loaded, they give their InputStream and the tga is loaded from disk into a TGAImage object, a texture name (int) is assigned to it, and all of this is shoved into a simple Texture object which goes into a java.util.List.
If on display() the renderer notices the list isn't empty, it goes and loads those textures. This is already getting ugly, but it gets worst when the two threads go after that list at the same time, getting concurrent modification exceptions. The thought of synchronizing the whole process is not appealing, so I'm thinking there's gotta be a better way. Restructuring my game to load everything at the beginning would be a ton of work.