multithreading woes

Started by
4 comments, last by evilchicken 22 years, 4 months ago
how do you go about generating opengl textures across threads? I cant seem to use the textures I generate in a worker thread, from the main thread.
Advertisement
You need a way to signal the main thread that the worker thread has finished creating the textures before it tries to use them...

Could you be more specific about what fails?

Magmai Kai Holmlor
- Not For Rent
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Note that OpenGL is not reentrant, so be sure to keep all your GL calls to one thread.

That said, I think you''d need to have a "global" store of data/memory in which you create the textures. Realize, though, that you''ll then need to synchronize access using mutexes and all those other lovely multithreading issues.

Other than that, I can offer no specifics. Sorry, hope I helped.

Start Here!
yeah, I was alittle vague.

The problem is that I have a thread dedicated to recving network packets, and in that thread I call a function that loads game data. Now it appears glTexImage2D() does not put the texture in a "global" store and is only local to my worker thread.

Im pretty sure there is a way to tell OpenGL to stick the texture in a "global" store, but as you said I would have to open up a whole new can of worms.

So what Im planning to do is just throw a flag in the worker thread that signals the main thread to load the stuff in there.
A rendering context can only be used in one thread at a time. If you want the second thread to create textures for the main thread, you need to move the rendering context over to the second thread before uploading the texture. When done, you must move it back to the main thread. Also make sure you don''t move the thread to the second thread when the main thread is still drawing. All this requires some synchronization.

As you say, best way it so tell the main thread to do it instead.
Wouldn''t it be best for the worker thread to send a message to the main thread to upload the texture?

This topic is closed to new replies.

Advertisement