Making OF thread safe

hi people

i’d like to hear from anyone, who’s been working on making OF thread safe.

i am using openFrameworks with cocoa on mac os x across several dual head GPUs using a shared context. the apple displaylink framework polls every GPU to draw in a callback. the callback is synced to the screen refresh rate - but even better - it draws each of the GPU’s openGL contexts in parallel, giving me a potentially much sleeker performance. and it allows me to do intelligent locks pr. screencard, using the openGL context…

but, alas, openFrameworks stores a lot of the drawing state in globals, not thread specific storage or openGLstates that would be gpu specific. a good example is when ofSetColor() modifies a ofStyle object.

this means that i have to add a global lock in the drawRect callback, effectively making the four ati GPU’s wait for eachother, dropping the framerate radically.

ideally i would make sure that everything relating to creating and modifying persistent openGl structures (writing to the context - textures, displaylists, etc) only happens in a common update loop, that i would trigger from a 60hz timer. there, it would be safe to do a texture update.

then i would let each context drive it’s own drawRect calls, and not update any variables in the draw routines outside of the context’s own tread. they would have to wait for the update to release it’s lock - but they would not have to wait for eachother to draw…

so, right now i am thinking - this could be solved if all openFrameworks state information was in thread specific storage, making the all openFrameworks drawing and rendering calls threadsafe and reentrant.

anyone sharing this problem? anyone having similar ideas?

i realise it’s a biggie - but i think it’s worth it.

anyway - this is basically why an update/draw separation makes sense, no?