Preloading texture data

I have an application that uses a GLAutoDrawable whose rendering is controlled by the event dispatch thread. During application startup I would like to upload a bunch of textures to avoid rendering pauses while the application is running. During this texture uploading I would also like to show some sort of progress indicator. My question is how I can achieve this. As far as I can tell the only GLAutoDrawable concept that I could use for this is the init method but, since this is called by the edt, this wouldn’t work well with the progress indicator. I’ve been thinking in the direction of making an initial glcontext which is not controlled by the edt, uploading the textures to that and then sharing this context with the eventual GLAutoDrawable, but it’s not really clear to me how I should make this work. Any ideas?

I haven’t tried this, but:

  • call getContext().setSynchronized( true )
  • launch a worker thread that essentially makes the context current, uploads the textures, and releases the context
  • …to be on the safe side, use synchronization to avoid any operations on the context from the EDT, while the worker thread is busy…
  • display a modal wait dialog from the EDT, a reference of which is passed down the worker thread, and is disposed when the worker is finished

That ought to work, good luck!

That sounds like it could work, but it’s a bit too low level jogl. I have my own abstraction layer that allows me to switch between gl4java, jogl and jsr-231, so I would need something that can sort of work on all three…

The Grand Canyon demo does something similar to this. It used to manually use swapBuffers() functionality in GL4Java but the way this was redone in the context of JOGL (as far as I remember; I don’t have the source code in front of me, but you can download it) is by having an application-level flag indicating when the textures are done being preloaded and do something like load one at a time at the top of your display() callback, updating the progress bar with each one.

That sounds like a good idea. Thanks for the tip.