I’ve been playing around with a custom
GtkPaintable somewhat similar to the
GskShaderPaintable implemented as part of gtk4-demo. Ideally, the paintable would be able to determine the renderer that is in use, and be able dispatch to specialized snapshot implementations (i.e. fall back to drawing to a texture on the CPU if not using the GL renderer). Unfortunately, either I don’t know where to look, or the API seems to be somewhat lacking for implementing this:
The documentation suggests to
gsk_gl_shader_compile()to test whether the shader can be used. However, that requires access to the
GskRendererwhich can be obtained as
gtk_native_get_renderer(gtk_widget_get_native(widget)). From a paintable, that doesn’t really work since it prevents decoupling of the paintable and the widget that it is contained in. That should be possible though, because at snapshot time, the renderer is known. So if the
gtk_snapshot_get_renderer()method, such a separation would be easy to realize since then the paintable has access to the renderer on snapshot.
More generally, there doesn’t seem to be a way to actually tell what renderer is in use: The renderer implementations are private, i.e.
GSK_IS_GL_RENDERERand the like are not exposed in the API. In
paintable->snapshot(), a workaround might be to get the GL context through
gdk_gl_context_get_current(), I’m not sure whether that being non-
NULLreally corresponds to the GL renderer/some other renderer being in use, though. Is this true?
I guess there’s not really a clear question in the above, unless I’m actually missing some way to achieve what I want. I did grep through the gsk/gdk/gtk sources, though, and that doesn’t really appear to be the case. Then, please see this as a suggestion for future API.
Thanks for any comments!
(The actual use case is here is probably totally overkill and I should just go for rendering to a
GdkTexture, so it’s rather about learning a little about GTK plumbing and GL.)