-
-
Notifications
You must be signed in to change notification settings - Fork 477
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
wasm-unknown-unknown support #1167
Comments
If someone wants to do it, I'll be happy to accept it. |
I'm working on this. If it's been two weeks and there's no update assume I'm lost at sea and ping me. |
Let's consider the difference between winit's "emscripten" and "web" Window structures, respectively. #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct WindowId(usize);
impl WindowId {
pub unsafe fn dummy() -> Self {
WindowId(0)
}
}
pub struct Window2 {
cursor_grabbed: Mutex<bool>,
cursor_visible: Mutex<bool>,
is_fullscreen: bool,
events: Box<Mutex<VecDeque<::Event>>>,
}
pub struct Window {
window: Arc<Window2>,
} mod backend {
pub struct Canvas {
raw: HtmlCanvasElement,
...
}
}
pub struct Window {
canvas: backend::Canvas,
previous_pointer: RefCell<&'static str>,
position: RefCell<LogicalPosition>,
} In many ways I think that the web one is better. The emscripten struct maintains no identifying information. The emscripten implementation, when asked for it's id, always returns 0. When setting HTML state, the emscripten implementation either uses an API that doesn't specify a target or passes a null pointer (both of these actions result in emscripten falling back to it's own internally-tracked reference to the canvas object). The web one maintains a reference to the canvas object. The creation function creates the canvas element. It's not clear to me where (or if) that gets inserted into the document (it's possible that that's beyond glutin's scope). State queries and modifications act on that reference. Where this falls down is that glutin requires that Context implement Send + Sync. At it's core, the Canvas reference (via The easiest solution is to modify the web implementation to maintain a singleton reference outside of it's struct. It's bad but it's bad in a similar way to how the emscripten implementation is bad. Better solutions aren't coming to me right off the bat. But maybe posting this will spark some conversation. Either way I will try the easy way and report back. |
I haven't given up on this but I'm expanding my thesis a bit. Bear with me. |
So there are two outstanding issues that I see with bringing wasm32-unknown-unknown support to glutin. Firstly, as outlined above, glutin's requirement that the window context implement the synchronization traits is problematic with regards to the web. References to a canvas element (or any JS references for that matter) cannot be shared between threads. There are definitely hacks to get around this but that would mean that glutin's API is writing checks that it's implementation can't cash. An honest implementation for the web will require a relaxation of those trait requirements. Secondly, one of the primary benefits from using this library is being able to initialize a GL context via Between these two issues, I'm not sure bringing wasm32-unknown-unknown support to glutin is valuable. That said, winit's web improvements + glow together offer what I think is a compelling replacement on web. |
I'm not familiar with how how As for the requirement of |
Implementing Yeah, relaxing the requirements for that trait from being global to being native-only would resolve the first problem. Really, it should be relaxed for web platforms, though, including emscripten. Does that sound reasonable to you? |
WebGL is fundamentally binary-incompatible with OpenGL. It's a JavaScript API, with quite a few differences. It would require an OpenGL implementation that acts as a translation layer, which is what emscripten does. I'm currently working on a crate that would provide a similar thing, but as a standalone library that works on |
What about adding optional integration with |
+1 for glow, it also supports wasm-unknown-emscripten |
This should be reiterated, given that winit is not involved anymore. |
I would support having a way to return a The only issue is that |
Well, glutin will likely hit We can probably have some sort of a shim between us and glow, so the glow wouldn't be exposed. |
@grovesNL Are you planning on making any breaking changes to |
Some summary from the IRC, at least my points on how it could be done. If we plan on having web target along other backends, we could do the following:
The most complicated part is to setup the glue for the I'm not quite sure how extensions work here, maybe a special method could be needed for web to query for certain extensions. Maybe we should change the extensions API in general to be more However, maybe we don't need to handle web specifically? Users doing web likely has separate code to initialize the web platform and they could create the glow context there, and if they have native code, they could use glutin for that and cfg it out in their gl platform init code. cc @grovesNL , since they know WebGl and likely could say whether it's even worth to try add all of that to glutin. I'm myself not that certain. |
This is exactly how I've seen things done. A The most useful thing for me (if I could provide a single data point) would be a mapping of But take that with a huge grain of salt because I haven't seriously considered what that would entail. Nor do I think it's a major stumbling block as it's sort of "write it once and forget it" code. Nor do I really think that glutin would be a good home for that mapping. |
Are there any plans to support the wasm-unknown-unknown target with wasm-bindgen? That seems to be where most of the community is headed.
The text was updated successfully, but these errors were encountered: