Compiling shaders on a separate thread


#1

Hey, I want to compile shaders on a separate thread so that the whole program doesn't freeze while it's processing. To do this I've read that you need to create another thread with a new context, then share that context with the original. You can then compile the shader asynchronously, then swap it out with the current shader when compilation has finished.

I've experiemented with shared contexts in Juce.

I set up the first context like this:


    openGLContext.setRenderer(this);
    openGLContext.attachTo(*this);
    openGLContext.setContinuousRepainting(true);

Then, when that context has initialised (i.e. newOpenGLContextCreated called) I do this to initialise the compiler context:



shaderCompilerContext.setNativeSharedContext(openGLContext.getRawContext());
    shaderCompilerContext.extensions.initialise();
    compileThread = new CompileThread(this);
    compileThread->startThread();

However, when I compile the shader, it fails but the error message is empty. I know the shader code is correct. So it must be something to do with the shared context stuff, or the multithreading. 

Any ideas?

 

Thanks,

 

Rob


#2

Just a link to any sort of working Juce code that uses shared contexts is all I'm looking for really. Google shows me nothing, even searching for the older shareWith method.

Thanks