Sure, I currently use a schema that is similar to what MediaTracker does with bufferedImage images.
The goal is to provide a loading process that operates outside the main thread, isn't it ? It uses one java class, mainly, java.util.Timer and its associated member TimerTask.
in a few words, the Timer is needed to perform sequential tasks in a separate Thread, whose tasks provide a simple state report when invoked. Thereafter the loading is completed, the opengl Thread can get access to the data and complete the loading with texture declarations and bindings.
Hence, a loader class is created and all loading stuff are forwarded to an underlying statical Timer that receives tasks as TimerTask, scheduled and processed as needed. The class is set to LOADING and when the Timertask is completed, set to LOADED.
The openGL Thread must be continuously monitoring the loader class state. When a loader class becomes LOADED it calls a method of the loader class that will be invoked in the opengl thread and creates textures.
C=class; T=Thread
C : LoaderClass -> loadData() -> LOADING ->Timer.scheduleTask(TimerTask.run() { readFromFile, LOADED}
T : timerThread (handled by Timer) : wait for new timerTasks - Timertask scheduled ? -> TimerTask.run()
T : openglThread (handled by LWJGL) : Renderer -> monitor the LoaderClass.getState() - LOADED ? -> LoaderClass.loadGLdata()
|_ LOADING ? -> render next frame
- something that is NOT possible is loading GL textures from an external thread while you render.
- we could figure out a model that'd invoke arbitrary Threads and acquire locks on the GL context without using Timer, but this is not permitted by opengl that only allows ONE Thread owning the lock.
- Timer is efficient because it asserts that only ONE Task at a time is processed and on the SAME THREAD.
- if the Timer thread would acquire the GLContext, then it will be admitted that the loading occurs on another thread, but you still wouldn't be able to render simultanously, so the screen may appear black or frozen while the LoaderClass loads the data.