Drawing to ofFBO in a thread

I’m making a multichannel audio visualizer of sorts that draws the spectrum of each channel into an FBO. However once I get up to 5-6 channels, I start running out of computer resources, so I thought I should draw to the FBOs in separate threads.

Would this be possible? I read that using OpenGL in separate threads is not possible, but in my case I’m drawing using the CPU… Any advice here would be much appreciated!

Hi,
If you are drawing to the screen you do so via openGL, not via CPU. Although there are a lot of different ways on how to draw to opengl, some very efficient, some very inefficient.

Sound in OF already runs on a different thread, so you need to handle with care how to draw audio data.

As all audio data comes in on a single buffer, regardless of the number of channels it has, you are probably performing the FFT all at the same time. Although if you are doing the FFT in the audioIn callback function, it it takes to long for it to finish you might end up dropping audio frames, so having it done on a different thread might prove useful.

Last thing is how you draw.
calling ofBeginShape(), ofAddVErtex(...), etc is super slow. Instead you should use an ofMesh or better an ofVboMesh.
Using any of these shouldnt be a problem when drawing and shouldnt slow down you app.

Oh, and technically speaking you can make openGL calls from any thread, but it can be a nightmare trying to manage it, thus OF has this restricted to the main thread.

1 Like