Sign in to follow this  
Phantom5800

Resources being loaded in separate thread from renderer

Recommended Posts

So, I have a threaded Resource Manager that queues up resources on the main thread, and then loads them on the resource thread. My question is, how do I handle creation of graphics resources? Obviously I can't create a gl resource (VBO, Texture, etc) on the resource thread. What is everyones opinion?

Do I force graphics resources to be loaded on the main thread? Or do I have some kind of check before using a graphics resource that says "If I haven't been initialized, do it now"? Or is there some other solution I haven't thought of that other people use?

Share this post


Link to post
Share on other sites
I use a lock-free queue, the loader thread will push elements and the graphics job(s) pull from it every frame. While GL's total lack of thread support (reason #456987 why Direct3D is better and you should use it, etc.) means you can't have more than one thread dequeuing items, you can probably use something very similar. The COFU idea is a bad one, IMHO, for a few reasons-- it's less predictable (queuing means all creates can happen in one, easily-trackable place and it's something of a data-parallel problem anyway) and it adds overhead to using a resource even after you've loaded it (branching once per resource per draw call is small but likely not entirely negligible, and that's without considering synchronization problems/ordering)

Share this post


Link to post
Share on other sites
Thanks for the advice. Unfortunately DirectX isn't really an option for me right now (cross platform engine without time to work on two renderers). After dealing with a race condition it all works nicely.

Share this post


Link to post
Share on other sites
http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=234543

I don't know much about OpenGL, but I did find this thread which seemed to confirm that you can load on other threads. What operating systems are you using and what version of OpenGL?

P.S. In my opinion your resource loader system sounds perfectly reasonable.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this