Update: Most work is done! Unfortunately this didn't help the GL API as much as it helped the newstyle APIs like Vulkan/Metal/gfx-hal/wgpu, but it was a good improvement.
Windowing Side
[x] winit: raw-window-handle is supported as of 0.20.0-alpha3
[x] glutin: GL has problems in general with it, but glutin uses a new enough winit that it technically has the support.
[x] beryllium: Available in 0.1 series and via feature in 0.2 series
[x] ash: Ash doesn't track the extensions enabled, so it can't actually use raw-window-handle to automatically do anything for you. You're just on your own, which is what you'd expect from a minimal bindings library.
gfx-hal (technically the Instance type in gfx-backend-foo for one of gl, vulkan, dx12, etc) takes a &Window, but all types actually secretly have their version number as part of their type so it takes a &Window-v0.19.0. That's fine and all except there's a new 0.20.0-alpha2 out and people are supposed to be trying out that new alpha but they can't draw a picture because it's the wrong version so you get a type mismatch error. We can hardly alpha test the library if we can't even draw a picture. The backends have a plan for what to do: ignore their winit integration, possibly disable the winit feature entirely, and then use the create_surface_from_THING version for whatever raw window thing you have. This is annoying, but you can do it. The gfx-backend-vulkan crate has support forxlib, xcb, wayland, and even an existing vulkan surface. Honestly, all that create_surface does with the &Window is look inside the Window for the raw window data (using the right platform specific extension trait), and then call one of the other constructors anyway.
What we should do is cut out the whole middle step where gfx-hal has to know about the unstable winit crate, and we let it rely on a very stable interface that both winit and gfx-hal and other window libs and other graphical libs can all agree on.
We'll call the crate raw-window-handle (bikeshed here). The crate only needs a single trait and a support enum for the return value of the single method on that trait:
pub unsafe trait HasRawWindowHandle {
fn raw_window_handle(&self) -> RawHandleData;
}
pub enum RawHandleData {
Win32{ hwnd: *mut c_void},
XLib{ display: *mut c_void, window: u64 },
Cocoa{ .. } \
// etc, one for each windowing system,
// we prefer c_void and pointer casting instead of the "real" pointer
// types when possible so that it builds easily on all platforms.
}
Then winit implements this for Window, and gfx-hal backends can write create_surface(win: &impl HasRawWindowHandle), and end users trying to get the two to talk to each other stop having to match their versions up quite so tightly. The raw-window-handle crate can just be one of those "0.1 crates that basically never updates because it does the job fine as is" like libc, perhaps to become 1.0 once we've really kicked the tires a bit., perhaps never to even bother with 1.0 at all.
And that's something we could get done in just 1 month.
Update: Most work is done! Unfortunately this didn't help the GL API as much as it helped the newstyle APIs like Vulkan/Metal/gfx-hal/wgpu, but it was a good improvement.
Windowing Side
winit
:raw-window-handle
is supported as of 0.20.0-alpha3glutin
: GL has problems in general with it, butglutin
uses a new enoughwinit
that it technically has the support.beryllium
: Available in 0.1 series and via feature in 0.2 seriessdl2
: Issue opened, https://github.com/Rust-SDL2/rust-sdl2/issues/910Graphical Side
ash
: Ash doesn't track the extensions enabled, so it can't actually useraw-window-handle
to automatically do anything for you. You're just on your own, which is what you'd expect from a minimal bindings library.gfx-hal
added in https://github.com/gfx-rs/gfx/pull/3038wgpu
: Fixed in https://github.com/gfx-rs/wgpu-rs/pull/70glow
: Updated to a new enough glutin in https://github.com/grovesNL/glow/commit/7a73cf9a258ec326fd378cc4388ce1bb926a808e, though the GL limits still apply.original issue post follows:
gfx-hal
(technically theInstance
type ingfx-backend-foo
for one ofgl
,vulkan
,dx12
, etc) takes a&Window
, but all types actually secretly have their version number as part of their type so it takes a&Window-v0.19.0
. That's fine and all except there's a new0.20.0-alpha2
out and people are supposed to be trying out that new alpha but they can't draw a picture because it's the wrong version so you get a type mismatch error. We can hardly alpha test the library if we can't even draw a picture. The backends have a plan for what to do: ignore theirwinit
integration, possibly disable thewinit
feature entirely, and then use thecreate_surface_from_THING
version for whatever raw window thing you have. This is annoying, but you can do it. The gfx-backend-vulkan crate has support forxlib
,xcb
,wayland
, and even an existing vulkan surface. Honestly, all thatcreate_surface
does with the&Window
is look inside the Window for the raw window data (using the right platform specific extension trait), and then call one of the other constructors anyway.What we should do is cut out the whole middle step where
gfx-hal
has to know about the unstablewinit
crate, and we let it rely on a very stable interface that bothwinit
andgfx-hal
and other window libs and other graphical libs can all agree on.We'll call the crate
raw-window-handle
(bikeshed here). The crate only needs a single trait and a support enum for the return value of the single method on that trait:Then
winit
implements this forWindow
, andgfx-hal
backends can writecreate_surface(win: &impl HasRawWindowHandle)
, and end users trying to get the two to talk to each other stop having to match their versions up quite so tightly. Theraw-window-handle
crate can just be one of those "0.1 crates that basically never updates because it does the job fine as is" likelibc
, perhaps to become1.0
once we've really kicked the tires a bit., perhaps never to even bother with 1.0 at all.And that's something we could get done in just 1 month.