Python - Creating Vulkan surface on Gtk.Paned

Hi, could someone give tips on how the context and surface are currently created on Gtk.Paned? The documentation has deprecations and I do not see any recommended alternatives on Gtk4.

Hi,

That sounds confusing… Can you please describe what you are trying to achieve?

I’ve got Gtk.Paned set as below and want to create vulkan surface on the right frame. What is the current context and surface to be used by Gdk?

OK.

Then these previous discussions may give you some leads:

You’re thinking in GTK2/GTK3 terms: make a widget draw on a native windowing system surface, and then use that surface as the rendering target. This is not how GTK4 works.

For starters, widgets are not backed by a native windowing system surface: only the top level window has a surface, and it’s used to render the entire widget tree.

Secondly, GTK4 uses a retained tree of render operations; you cannot just draw your own content on the same surface at random times.

The appropriate way to deal with rendering with any drawing API that is not provided by GTK itself is to create an offscreen buffer, render to it, and then extract the backing buffer—a texture object in OpenGL, or better a dmabuf object on Linux—and create an immutable GdkTexture instance around it, which can then be rendered using the GtkSnapshot API in a custom widget.

I suggest you look at how GtkGLArea is implemented inside GTK.

3 Likes

This is applicable for both 2D and 3D presentation with Vulkan?
Like I could create a paintable surface or 3D mesh rendering and mouse controlled viewport behavior? Need to know it there are known limitations.

I’m not aware if someone already implemented such approach, so can’t tell about limitations…

You can lay out widgets with 3D transformations, but GTK is not a 3D toolkit.