Godot Version
4.6.x
Question
I’m experimenting with using SkiaSharp to do some 2d vector rendering in a Godot project. The initial setup was surprisingly easy, just adding the nuget package to the project and I was quickly able to setup a CPU-based rendering system where I render Skia stuff into a bitmap pixel buffer and then copy that buffer content into a Godot Image and create an Texture from it I can render in Godot. So far so good.
However, Skia (and the C# SkiaSharp version) has extensive support for GPU accelleration, and ideally I’d like to use this instead of needing to render on the CPU and transfer the data to the GPU for each update.
This involves getting a reference to a valid GPU context to pass to the Skia rendering system (either OpenGL for Compatibility renderer or Vulkan in Mobile/Forward+ seem to be supported) and ideally also getting a GPU backend reference to a texture you’ve set up to use as a rendering target for the Skia rendering. This way I could do all the rendering on the GPU and get the output in a texture I could hopefully use right away to render in Godot for great performance.
However, I haven’t found a way to find this reference to the gpu context Godot is using. At least nothing Skia will accept and be able to use. You can find an example of someone else trying to do something similar and not succeeding here: [BUG] Failed to obtain vulkan context · Issue #3312 · mono/SkiaSharp · GitHub
The SkiaSharp documentation also mentions that you’re responsible to making the context active for it to do its drawing, so I guess I’d also need to hook this into the Godot rendering system somehow to make sure the Skia draw calls are called during the rendering cycle when Godot has the context active (maybe just have it be called from some control _draw method?).
Does anyone know how of a way to get a C# reference to the CPU context (OpenGL/vulkan) used by Godot to use for interfacing with other rendering systems like this? Or better yet, has anyone else managed to get an GPU accelerated rendering with SkiaSharp working in a Godot project?
(Edit: fixed reference link)