dioxus icon indicating copy to clipboard operation
dioxus copied to clipboard

Is it possible to render directly in WGPU handle?

Open PooyaEimandar opened this issue 1 year ago • 4 comments

Specific Demand

Is it possible to render directly in WGPU handle?

Implement Suggestion

If we can directly render to WGPU element, this would be a great possibility for game industry to integrate their game and game engine with this GUI.

PooyaEimandar avatar Mar 17 '23 16:03 PooyaEimandar

We were just discussing embedding Blitz (Dioxus' WGPU renderer) into other windows and game engines (specifically bevy) on discord (here). Currently this is not possible, but it would definitely be a great feature to support in the future.

Here is a summary of the discussion:

Blitz needs to be more abstracted over async runtime and allow rendering outside of a window.

Tokio/Async runtime: We only use the channels and select macro from tokio, we could probably use a library that is not specific to tokio that support those two things. We do need some async runtime, but I think it should be fairly easy to be agnostic here.

Rendering/Viewports: Currently we only render to a window. We could be able to create an abstraction that would allow different options, but I think Tao or winit is still a good default to export. We need something that emits events that can be converted into Dioxus events (handled here) and has a window size.

The code that is related to the Tao window currently would need to be converted into something more like a viewport. It wouldn't be the window that the bevy app runs in, just something with a size inside of that window that the Blitz UI is rendered into that can capture events

You don't need direct access, but there needs to be a size so that layout can work, and events so that elements can respond to actions

For Blitz, my main concern is how this would effect the complexity of adding future features that could be more specific to the windowing library we mainly use. For example, first class support for keyboard shortcuts could be available in Tao, but not Bevy.

Something that could alleviate this is a more raw API for something like Bevy that supports rendering and events, but not more Tao specific features like shortcuts, taskbar, etc.

This is not a priority for me in the near future (I would like to develop widgets, more support for html elements+attributes, and accessibility integration first), but I would be happy to get someone started implementing this if anyone is interested in contributing!

ealmloff avatar Mar 17 '23 17:03 ealmloff

hey I'd like to see dioxus with bevy, but I'm fairly new with rust, but I've done Haskell and I work with web, so i think i can teach myself most concepts as I go.

if someone can give me a bit of a pointer where to get started and an estimate how much work this feature needs I'd be willing to invest a bit of time to make it happen

epsilonhalbe avatar Feb 17 '24 10:02 epsilonhalbe

Wry recently added support for embedding a webview into a raw window including a wgpu window: https://github.com/tauri-apps/wry/blob/dev/examples/wgpu.rs. Using that example to build support into dioxus would be much easier than getting blitz to a point where it can render most apps.

We currently use tao which is tauri's fork of winit, but it sounds like tao does not plan to support this in the future https://github.com/tauri-apps/tao/issues/616. We could try switching to winit if we don't use any tao specific features. There is quite a bit of code in dioxus desktop related to winit, but the APIs are also very similar in some places so I'm unsure how much work it would be to move over to winit

ealmloff avatar Feb 19 '24 15:02 ealmloff

@epsilonhalbe take a look: https://github.com/JMS55/bevy_dioxus

king0952 avatar Feb 21 '24 06:02 king0952

For folks that want to render dioxus into a wgpu context, we now have a few options:

  • use blitz / dioxus-blitz: http://github.com/dioxusLabs/blitz
  • use bevy_dioxus: https://github.com/JMS55/bevy_dioxus

For folks looking for a native renderer not based on wgpu, check out:

  • freya http://github.com/marc2332/freya

As much as I want to close this issue, the underlying problem remains that dioxus-desktop in theory can render to wgpu, but in practice, that's a winit-only feature (AFAIK) and would require desktop jumping from tao to winit.

jkelleyrtp avatar Jul 25 '24 20:07 jkelleyrtp