Use Ganesh with OpenGL
Use OpenGL when your host already owns a WGL, GLX, EGL, CGL, or OpenGL ES context. SkiaSharp does not create that platform context for you, and it must be current on the calling thread whenever Ganesh makes GL calls.
Create the Ganesh context
Once the platform GL context is current, create a GRGlInterface to resolve its entry points and pass it to GRContext.CreateGl:
// A platform GL context is already current on this thread.
using var glInterface = GRGlInterface.Create();
using var context = GRContext.CreateGl(glInterface);
GRContext.CreateGl() also has a parameterless overload that assembles the interface from the current context.
Wrap the current framebuffer
To draw into a window framebuffer, query its identifier, stencil bits, and sample count from OpenGL, then describe it with GRGlFramebufferInfo:
var glInfo = new GRGlFramebufferInfo((uint)framebuffer, colorType.ToGlSizedFormat());
using var renderTarget = new GRBackendRenderTarget(
width, height, sampleCount, stencilBits, glInfo);
using var surface = SKSurface.Create(
context, renderTarget, GRSurfaceOrigin.BottomLeft, colorType);
Draw and flush the surface as described in the shared Ganesh surface flow, then present or swap buffers with your windowing API.
Keep OpenGL current during cleanup
A GRContext and its resources are not thread-safe. Keep the same platform GL context current while disposing surfaces, backend targets, and the GRContext; cleanup can make GL calls.