GtkPaintable: Obtain GskRenderer during snapshot?

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 GskRenderer which 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 GtkSnapshothad a 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_RENDERER and 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-NULL/NULL really 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.)

Answering this would require to know what you want to do.

Generally no, you cannot get the renderer and that’s fine, you should just render using the snapshot object you get during snapshot(). If you want to render using GL directly, use a GtkGLArea.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.