Load Textures in Background while Rendering

Hey guys,

I’m relatively new to JOGL and have a problem that I’ve been unable to answer through about 8 hours of trying code and searching google.

I am rendering a scene by running a Thread on an awt.Canavs implementing Runnable (the run method essentially goes into a loop that each iteration repositions the camera, redraws the shapes, and swaps the buffers onto the canvas).

Currently when I load textures, I load them from TextureData (which I pre-create in another thread) inside the loop (which pauses the rendering, since the loop is on a single thread). I would like to export the texture generation to another thread and continue rendering, updating the render once the texture becomes available (probably using a volatile boolean to switch on while waiting for the texture to generate). Is this possible?

Do you load it into GL directly ?

[quote]I would like to export the texture generation to another thread and continue rendering, updating the render once the texture becomes available (probably using a volatile boolean to switch on while waiting for the texture to generate). Is this possible?
[/quote]
Actually, YES and NO. if you were not loading directly to GL, then you meant loading data from reading the data file and yes you be able to send a new Thread for this loading process.
If you were loading into GL, then you meant using 2 Thread sharing the same GL context, which is afaik NOT possible.

A good way to reduce the time your rendering loop is stalled, is to split the Image in Tiles and/or using GL subtextures functions to upload the data to GL, one sample at a time. This means that you either read the source file partially, or hardly split the file into parts that will be read one each other. What shouldn’t be done is to open the source file and read the whole data at once before to upload it.

I use for myself a Tile cache to load big textures.

Thanks for your help broumbroum.

I am loading it into GL directly. I had already more or less come to the conclusion that I couldn’t share contexts between threads that I probably couldn’t run a hack to make it work. However, this looks more promising:

Is there an example of this you could direct me to?

Thanks again!

Of course I can suggest you my own API http://sourceforge.net/projects/sf3jswing/files/ .
Download sf3jswing-jigaxtended and sf3jswing-jxakernel.

  1. compile jxakernel for your arch. (ant jar)
  2. copy the dist/yourOS/unsigned/sf3jswing-jxakernel.jar to sf3jswing-jigaxtended/lib/yourOS/yourarch/.
  3. compile jigaxtended. (ant jar), you should get dist/yourOS/unsigned/…jars which include the full API.

Then Tile Caching is implemented into the net.sf.jiga.xtended.impl.Sprite . You make it happen by loading a texture tiles cache with setTilemodeEnabled(true) setTextureModeEnabled(true) , loadResource() and retrieve the Sf3Texture cache with getTexData()

For the Sprite to load fine, it must be loaded all LWJGL natives libraries at once.
You can do it instantly by running JXAenvUtils.loadEnvironment() at startup.

PLZ tell me what you think ! you may directly post into the forum below.
::slight_smile: