Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please add support for the new raw-window-handle crate #910

Closed
Lokathor opened this issue Aug 15, 2019 · 13 comments
Closed

Please add support for the new raw-window-handle crate #910

Lokathor opened this issue Aug 15, 2019 · 13 comments

Comments

@Lokathor
Copy link

Recently the gamedev-wg has been trying to make it easier for windowing libs and graphical libs to agree on a protocol for communication. This has resulted in the raw-window-handle crate, where the window offers up its OS window handle thingy to the graphical lib upon request and then the graphical lib is able to do its startup.

In terms of SDL2, this would involve a call to https://wiki.libsdl.org/SDL_GetWindowWMInfo and then matching and converting the data over.

Tracking issue where this crate was discussed and crated if you have any questions: rust-gamedev/wg#26

@Cobrand
Copy link
Member

Cobrand commented Sep 10, 2019

I'd like to keep this crate dependency-free; however, I'm not against including it behind a feature, much like some crates have a "serde" feature and the like.

If someone would like to have a go at this, feel free to hit me up if you want some help! Although that should be a pretty straightforward integration overall.

@ghost
Copy link

ghost commented Jan 14, 2020

A friend and I did a little work to see what it would take to get raw-window-handle working at least on macos: https://github.com/lmcgrath/rust-sdl2-with-raw-window-handle. I'm posting this here as an example for how to make raw-window-handle work without changing the rust-sdl2 code. The key things I had to do for this was enabling the use-bindgen feature so I could get the macos-specific bindings to expose the NSWindow and then write a little objective-c to get the NSView from it.

The changes are mostly trivial, but given the cmake and native code dependency I'm curious if you would be interested in including the work? I can at least contribute the macos and X11 bindings!

@Cobrand
Copy link
Member

Cobrand commented Jan 15, 2020

It looks a little bit complicated and unconventional (to use ObjectiveC inside build.rs code or the like...), but I guess we have no choice. I am in favor of implementing raw-window-handle, but behind a feature gate like "raw-window-handle" or similar.

You can start with X11 and macos, we'll probably find people interested in other platforms as well as time goes by.

@Lokathor
Copy link
Author

  1. if you make the raw-window-handle crate an optional dependency it should automatically count as a feature with that same name people can cfg on and such.

  2. You probably don't need to write objective C itself, but I use the objc crate in how I did it: https://github.com/Lokathor/beryllium/blob/master/src/window/raw_window.rs#L41

@ghost
Copy link

ghost commented Jan 15, 2020

@Lokathor what are you running that's using the raw-window-handle implementation? I'm running wgpu-rs and it expects the ns_view field to be populated.

@Lokathor
Copy link
Author

I actually dont use it with anything since SDL2 can open a GL context all on its own.

Basically the wgpu-rs implementation is the one that's technically got the bug here. The raw-window-handle crate specifies that if you need a field that's given as null you should try to ask the OS for the missing field, so wgpu-rs needs to be fixed to handle a null ns_view.

Or you could figure out some sort of view, but i left it as null because when i asked "what view?" they said it was too hard to pick a default and the graphics api should pick somehow :P

@ghost
Copy link

ghost commented Jan 18, 2020

I opened a PR to get it into wgpu: gfx-rs/wgpu#453

@ghost
Copy link

ghost commented Jan 25, 2020

So I'm stuck. I need to be able to run bindgen to get the platform-specific struct members for the window handle, but the project doesn't build because the pixel constants' namespace in pixel.rs is different when running bindgen. Any advice for how to make this work?

@Lokathor
Copy link
Author

rifle through here, where I keep various bindings for various targets and SDL2 versions pre-generated: https://github.com/Lokathor/fermium/tree/master/src

@ghost
Copy link

ghost commented Jan 25, 2020

I'm not sure what I would do with these. What were you thinking?

@Lokathor
Copy link
Author

look at the appropriate struct in whatever file and just use that.

Or you could delve into SDL_syswm.h, but it's messy to look at, #ifdef all over

@ghost
Copy link

ghost commented Jan 25, 2020

I've got something working! Thanks for pointing me at your pregenerated files, that was super helpful. PR's in the works.

@Lokathor
Copy link
Author

Closing since this got merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants