gtk-rs / gtk4-rs

Rust bindings of GTK 4
https://gtk-rs.org/gtk4-rs/
MIT License
1.8k stars 167 forks source link

Create WGPU widget similar to Gtk.GLArea #1278

Open nixigaj opened 1 year ago

nixigaj commented 1 year ago

I've been wanting to create a GUI app using WGPU and use GTK for window decorations on Linux/BSD. Using OpenGL this can be done using GLArea covering the entire window with the widget. I have seen requests for this but not seen any implementation.

sdroege commented 1 year ago

That's certainly possible but it would probably make sense for this to either a) be just an example in this repo, or b) an external crate that provides such a widget in a general way.

Do you intend to work on this?

i509VCB commented 1 year ago

It would be possible to use the gles backend quite easily for this (wgpu-hal has a way to create an Adapter from a glGetProcAddress like function). But there are limitations with the gles backend and the Vulkan backend would be preferred. However the Vulkan backend would either force gtk to initialize with Vulkan or share memory objects between apis.

For a minimum viable product using the gles backend would be fine, but long term some work will be needed in wgpu (or an auxillary crate) to import memory objects from other apis.

bilelmoussaoui commented 1 year ago

If someone wants to work on this, we could potentially have a crate that has useful "integration" widgets with the rest of the rust ecosystem. See also #1163

ThrashAbaddon commented 1 year ago

I'm interested in this for Linux and Windows.

Doublonmousse commented 2 months ago

I was thinking that using the gtk webkit would get us some of the way there (even if not necessarily ideal).

Epiphany (gnome's web browser) is using gtk4 as the ui toolkit and some of the demos of wgpu.rs work (only webgl2 though, not WebGPU).

So using WebKitGTK inside a gtk4 app would allow for webgl2-based wgpu applications to run. And maybe WebGPU later if support is added in the future.

Doublonmousse commented 3 weeks ago

I think there's a working implementation (at least on the architecture side) here : https://github.com/BartBM/wgpu-dma-buf that we could adapt for gtk.

What it does is wgpu -> dma-buf -> glcontext -> slint window or wgpu -> dma-buf -> glutin -> winit window Using dma-buf to go from wgpu to gl.

As gtk 4.14 and gtk-rs 0.9 exposes the dma-buf graphics offloading on linux, it should be possible to make the same thing work on linux with wgpu -> dma-buf -> gtk using the graphics offload feature.

Though that's linux-only for the moment (although it may come to windows in the future : https://gitlab.gnome.org/GNOME/gtk/-/issues/6869)

Maybe it's possible to adapt the other part and do wgpu -> dma-buf -> glutin -> glcontext (gtk) -> gtk window.

Now there are probably some things to adapt between OS to have this work on all platforms (with or without graphics offload) but it seems doable given that the same trick works with slint and glutin and it doesn't seem like there's too much conceptual difference between these and gtk.