loading textures, but keeping framerate fixed

Hello,

I have a little OpenGL-application and want to load large textures in the background ‘on-the-fly’.
Is this possible without affecting a fixed framerate ???
I have not much experiences with thread-programming, so I would be very glad, if someone would have some tips for me… :smiley:

dj3hut1

The best way to do this, would be to have a separate thread that loads the texture from disk, using TextureIO.newTextureData()
when that is done, you pass it to your main rendering thread. This main rendering thread uploads it to the videocard by doing TextureIO.newTexture(yourTextureData)
This way, the main rendering thread does not have to wait for the texture to load from disk.

hello,

thanks for your answer.

but how to keep the framerate fixed?
Is it possible to start and stop the texture-loading thread, so that I can use surplus time for it (time that is not used for rendering)?

For example : I want to have a fixed framerate of 40 FPS and my rendering needs 0.015 s.
So I can use 1s / 40 - 0.015 s = 0.025s - 0.015s = 0.010s for loading the texture (which takes 6s or more at all).

dj3hut1

This is fairly easily accomplished using Java’s threading capbilities - make sure your rendering thread is higher priority than the texture loading thread, and have it sleep for 10 ms every time a frame is rendered (the code would be Thread.currentThread().sleep(10) while in the render thread). This will yield execution to the next lowest priority (or, if htere were other threads with the same priority as the render thread, they would execute). I’m not sure how much you’ll be wasting in threading overhead, but you may need to fiddle around with instead doing something like a 40 ms sleep every four render loops or something similar.

fixing the framerate on the side of the renderthread is actually pretty easy:
you use the FPSAnimator class as your renderloop.

As eteq said: if you don’t want the texture loading thread to get in the way of the renderer, you just give it a lower priority.

hello,

thank you very much for your answers.
i didn’t thougt it would be so easy… :slight_smile:

dj3hut1