-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Implemented support for creating a render surface from a canvas or offscreencanvas #6147
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
Conversation
|
How does this relate to the existing It's using |
The existing canvas field is a String, which is not helpful for referencing a
The goal of this PR is to allow OffscreenCanvas usage in bevy, mostly for moving bevy into a Web Worker and thus avoiding blocking the UI thread with rendering operations. This is not something winit supports (rust-windowing/winit#1518). btw, I just confirmed that this is working with bevy running in a web worker in a test application using this PR. |
3629022 to
eb5529e
Compare
|
Here is a minimal example for using bevy in a web worker using this PR: https://github.com/anlumo/bevy-webworker-test |
This PR is out of my area of expertise, but if you think this is a better solution, just replace that field. We're deliberately open to breaking changes to improve the API at this stage. |
|
I agree with Alice, breaking is not an issue, but having the api offers two ways around the same thing isn't nice. This api seems a little harder to use for the simple case of just passing the canvas id though.
Thanks ! That's quite interesting |
True, I've added a I've also removed the old selector-based entry! |
That's unfortunately no longer possible once it's using a web-sys type for canvas, and since it's already a special case there's no point to include the other flag on other platforms. An alternative would be to have a fake flag there for non-wasm32, like a |
|
I doubt it's a big deal if it's unavoidable, just wanted to surface that history. |
40d50a3 to
c2afbb7
Compare
|
Needs some testing from my side before I can remove the draft flag. |
c2afbb7 to
990b9ea
Compare
eb401a5 to
4190609
Compare
Virtual windows will by default not have a surface texture associated to them, but implementors can set the texture in `ExtractedWindow` manually. This is intended to be used when embedding games into other appications like editors or for running games headless.
9a20cd4 to
df2391d
Compare
…creencanvas elements on the wasm target. This only works when not using winit.
…ent. However, the bevy API doesn't allow for that yet.
…et for winit-based applications.
df2391d to
d9609c4
Compare
|
Rebased to new version of #6256 and also added winit support (without OffscreenCanvas, because winit doesn't support that at all right now). |
|
Holding off on this until #6256 is merged, since it changes around all the time at the moment, causing merge conflicts. |
|
Backlog cleanup: closing due to inactivity, and seeming lack of consensus. Lots of reorganisation and refactoring happening in the render space at the moment, likely to have significant bit rot. |
Objective
Solution
Changelog
bevy_window::window::AbstractWindowHandlethat can take either anHtmlCanvasElementorOffscreenCanvas.bevy_window::window::Window:new_canvasfor creating a Window based on a canvas element directly.new_canvas_selectorfor creating a Window based on a CSS-style selector.new_offscreen_canvasfor creating a Window with an offscreen canvas.WindowDescriptor::set_canvas_from_selectorandWindowDescriptor::set_canvasto allow winit to use a canvas element directly instead of creating its own (which is still supported).HtmlCanvasElement, but not anOffscreenCanvas. This is a limitation of winit.Migration Guide
Windowdoes no longer exists for non-wasm targets.WindowDescriptor::set_canvas_from_selectororWindowDescriptor::set_canvasinstead.