Sign in to follow this  
LPVOID_CH

OpenGL Multithreading and OpenGL problem

Recommended Posts

hi everybody i implemented multithreading in my opengl application. i have a therad for all the rendering job. i have to create the opengl context in this thread (with SDL) otherwise it doesen't work. now i want to load textures in background in a other therad. but this doesen't work, glGenTextures fails. i have to call the texture loading function in the reander thread. but i want to avoid this. how can i call opengl commands (here glGenTextures) in other threads so that they work. thanks

Share this post


Link to post
Share on other sites
The call fails because there's no OGL context in the other thread. I've never done OGL with multithreading so my advice is limited, but I think you'll have to create another context in the loading thread and sync between them.

Share this post


Link to post
Share on other sites
Easiest is to keep all the loading in a separate thread, except for the final step of actually calling GL to upload the texture data. All the heavy lifting will be independant of GL (loading from disk, decompression, image conversion) then you do the last tiny bit of work in your rendering thread. No need for awkward context sharing. :)

Share this post


Link to post
Share on other sites
thx

i already implemented this solution and it works fine. the data is loaded in the loader thread an then the glGenTexture is called in the ogl thred. for loading one tex this is no problem. but what, when i have to do a lot of glGenTexture and texture generationg calls? i think this will slow down the fps for a few seconds. well, this wouldn't bother anyone, but it would be nice to do a smooth background loading without fps lacks.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You can look into platform specific extensions (like wglShareLists).

In general, on PC platforms, multithreading with the 3D API doesn't win much. Where you will win big is dividing your scene graph and other processing using MP.

Share this post


Link to post
Share on other sites
Quote:
Original post by LPVOID_CH
i think this will slow down the fps for a few seconds. well, this wouldn't bother anyone, but it would be nice to do a smooth background loading without fps lacks.

Think or know?

If its a problem you can limit the number of actual gl texture creates done per frame and defer any extra to the next, which just means your textures arrive a tad later but keeps the smoothness. However you aren't gonna need it.

Share this post


Link to post
Share on other sites
i'll keep the texture loading in the rendering thread and only call a limited amout of gl loading functions per frame.

thanks for the suggestions

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