LWJGL Forum

Programming => OpenGL => Topic started by: Eternity on February 02, 2009, 16:03:56

Title: dynamicaly loading resources on a different thread
Post by: Eternity on February 02, 2009, 16:03:56
hey

im trying to write a decent resource loader for my engine. im pretty much done but i have one problem that i cant seem to find any way around

my resource loader loads resources at the same time my render thread is rendering... and as far as i know theres no way to make GL calls on 2 threads at the same time (althouh i hope im wrong)

how can i make my setup work?
any ideas?

Thnx in Advance!
Title: Re: dynamicaly loading resources on a different thread
Post by: VeAr on February 03, 2009, 09:34:06
My approach is:

OpenGL thread:
Allocate VBO, PBO
Map VBO, PBO to direct buffer (ByteBuffer)

Other thread:
Load data into the mapped buffers

OpenGL thread:
Release the mappings
Use the loaded stuff

Not just you can load in multiple threads this way, but you are loading into OpenGL managed memory directly, without the need for OpenGL to copy the data itself. The drawback is that once loaded into the mapped buffers, you cant access those data from Java any more without getting a performance hit.
Title: Re: dynamicaly loading resources on a different thread
Post by: Eternity on February 03, 2009, 13:53:14
that sounds feasible since i never touch the data in my VBO after its loaded anyway

il try it. thnx.

Title: Re: dynamicaly loading resources on a different thread
Post by: Eternity on February 03, 2009, 14:09:06
actualy ive just thought of another possible solution but this invloves switching contexts at most twice per frame.

my question is: how costly is Display.releaseContext(); and Display.makeCurrent(); can i safely use them to switch from and back to my rendering thread at most each frame?
Title: Re: dynamicaly loading resources on a different thread
Post by: Matzon on February 03, 2009, 17:54:56
you could of course always try it - but afaik, its very costly.
Title: Re: dynamicaly loading resources on a different thread
Post by: Eternity on February 03, 2009, 18:15:19
il figure something out

since the game im creating with my engine relies heavely on billboards instead of actual models i might get away with it performance wise

else il just do what veAr suggested

Thnx!