dynamicaly loading resources on a different thread

Started by Eternity, February 02, 2009, 16:03:56

Previous topic - Next topic

Eternity

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!

VeAr

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.

Eternity

that sounds feasible since i never touch the data in my VBO after its loaded anyway

il try it. thnx.


Eternity

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?

Matzon

you could of course always try it - but afaik, its very costly.

Eternity

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!