I would like to render to a SkSurface on a background thread using SkiaSharp with OpenGl. After rendering on the background thread is done, I would like to (as quickly as possible) draw the result of the background-render to a SKGLWPFElement (which, as an UIElement is associated with the foreground / UI thread).
So far,
- I am able to create the background GRContext (apparingly with a GL context that is associated with the background thread). I do this in a hackish way, creating an “OpenTK.GLControl” which is used for nothing but to create the GLContext, which I then “MakeCurrent” on the background thread.
- I have the SKGLWPFElement added to the WPF form that I can render to in the foreground thread. So rendering to both, independently, works fine.
Now, what I would like to finally do, is to render the BG’s surface to a SkImage and then render that SkImage (created in the background) to the foreground thread associated surface of the SKGLWPFElement. However, unfortunately this last step does not work (at least not without getting the pixels from the BG SKImage through the CPU to a FG SkImage, which is undesirable because leaving the GPU is supposedly slow).
The problem seems to be that an SkImage created in one GL Context cannot by default drawn in a different GL Context. I have also read, that there is a possibility to have resources (such as SkImage) shared between GL Contexts. And there even seems to be a low level OpenGl function that enables the sharing between GL Contexts (it’s called wglShareLists). It takes two parameters, the two handles of GL contexts between which the Resource sharing should be allowed. Also, I am able to get the GL Context handle of my background GLControl / Gl Context.
How can I get the underlying GL Context handle of the SKGLWPFElement or of it’s GRContext?