I'm working on a multithreaded OpenGL compositing engine. I have a set of shaders which I'm sharing among multiple contexts. For performance reasons, I'd like to avoid compiling a separate instance of each shader program for each thread.
But, if multiple threads happen to use the same program object and I try to set different uniforms on each thread, the uniform values get mixed up since uniform values are stored with the shared program object.
So far I see my options as:
- compile a separate program object for each thread (which wastes time and resources), or
- for each shared program object, serialize the process of setting uniforms and rendering (which largely defeats the benefits of multithreading)
Or is there a better way? (I.e., is there a way to store an OpenGL program object's uniforms per-context instead of per-program?)
Edit: I need to support users back through Mac OS 10.6 for a few more months, so until then I'm stuck with OpenGL 2.1 plus whatever extensions are available on Mac OS 10.6. ARB_separate_shader_objects appears in Mac OS 10.8, if I understand correctly.
来源:https://stackoverflow.com/questions/20020181/how-to-store-an-opengl-program-objects-uniforms-per-context-instead-of-per-prog