Jump to content
  • Advertisement
Sign in to follow this  
LPVOID_CH

OpenGL Multithreading and OpenGL problem

This topic is 4728 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!