Opengl calls / fbo's in threads

Hey all

is it possible to run opengl calls from a thread - or drawing into an fbo?

I’m having 5 effects (msa fluids, ofxfx,…) rendering into fbo’s in the main thread.
Then all FBO’s are blended to the output image using shaders.

Now, when running several effects the system slows down which isn’t a surprise.
It would help to render the effects to their respective fbo’s each in a separate thread; so I could render all 5 simultaneously while the main thread is on hold until the the slowest effect render is finished.
Then the main thread blends the fbo’s.

However; openGL is doing a number on me when called from a thread. Lots of errors, nullpointers, whatever. Any solutions for this?



Its very possible that im wrong :slight_smile:

But i think that you can not “draw” in a separate thread

i dont know why but i can not edit my answer, i know i read somewhere about that, here you can read about:

usually you can’t run openGL calls from different threads, and even if you could it wouldn’t make sense.

There’s a couple of things that you can do in openGL from a different thread like uploading or downloading textures using PBO’s but in most cases it really doesn’t make sense to do things in threads.

Threads run in the CPU while your GL code mostly runs in the GPU, in your graphics card, when you make a GL call it doesn’t run immediately, but instead the driver stores all the calls and data and runs them in the order that makes most sense. The GPU has lots of cores and will run processes in parallel as much as it can, so your effects are somehow already “threaded”. Using different CPU threads to start those calls won’t give you any speed increase even if you could

good points, thanks both! Never thought of it that way, but makes perfect sense :slight_smile:

So actually, I’d be better off buying a decent top-line gpu for speeding up the drawing process (and shader-based fx’s), and using threading for doing the update() function of purely cpu-based effects (eg particle fields) while the draw happens in the main thread.

Now a completely different question: does OF benefit from multi-gpu setups (using crossfire or SLI) for doing shaders?


[quote=“Kj1, post:5, topic:13264”]
Now a completely different question: does OF benefit from multi-gpu setups (using crossfire or SLI) for doing shaders?
[/quote] @Kj1 did you found an answer for this question?

nope, never did get my hands on a multi gpu setup so couldn’t test.