Skip to main content
GameDev.net gamedev.net
🔒 Locked

Multithreading and OpenGL problem

Started by LPVOID_CH Dec 3, 2005 at 8:22 AM 5 replies 1k views
Original Post
LPVOID_CH
LPVOID_CH
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
------------------------<< deltasoft games >>Homepage: http://www.deltasoftgames.ch
Stani R
Stani R
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.
OrangyTang
OrangyTang
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. :)
LPVOID_CH
LPVOID_CH
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.
------------------------<< deltasoft games >>Homepage: http://www.deltasoftgames.ch
OrangyTang
OrangyTang
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.
LPVOID_CH
LPVOID_CH
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
------------------------<< deltasoft games >>Homepage: http://www.deltasoftgames.ch

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.