mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
[rs] Merge #569
569: Reorder framework canvas setup for web r=kvark a=grovesNL winit only appends the canvas element once the window is built, and we need the canvas to exist before `create_surface` can use it. So we can just reorder the calls to build the window before using `create_surface` on the web backend in framework. Also temporarily no-op debug markers for the web until we have them in gecko. Even though they're technically unimplemented, we can still proceed without them. Co-authored-by: Joshua Groves <josh@joshgroves.com>
This commit is contained in:
@@ -80,9 +80,6 @@ async fn setup<E: Example>(title: &str) -> Setup {
|
||||
);
|
||||
};
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
console_log::init().expect("could not initialize logger");
|
||||
|
||||
let event_loop = EventLoop::new();
|
||||
let mut builder = winit::window::WindowBuilder::new();
|
||||
builder = builder.with_title(title);
|
||||
@@ -93,6 +90,22 @@ async fn setup<E: Example>(title: &str) -> Setup {
|
||||
}
|
||||
let window = builder.build(&event_loop).unwrap();
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
{
|
||||
use winit::platform::web::WindowExtWebSys;
|
||||
console_log::init().expect("could not initialize logger");
|
||||
std::panic::set_hook(Box::new(console_error_panic_hook::hook));
|
||||
// On wasm, append the canvas to the document body
|
||||
web_sys::window()
|
||||
.and_then(|win| win.document())
|
||||
.and_then(|doc| doc.body())
|
||||
.and_then(|body| {
|
||||
body.append_child(&web_sys::Element::from(window.canvas()))
|
||||
.ok()
|
||||
})
|
||||
.expect("couldn't append canvas to document body");
|
||||
}
|
||||
|
||||
log::info!("Initializing the surface...");
|
||||
|
||||
let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY);
|
||||
@@ -101,7 +114,6 @@ async fn setup<E: Example>(title: &str) -> Setup {
|
||||
let surface = instance.create_surface(&window);
|
||||
(size, surface)
|
||||
};
|
||||
|
||||
let adapter = instance
|
||||
.request_adapter(&wgpu::RequestAdapterOptions {
|
||||
power_preference: wgpu::PowerPreference::Default,
|
||||
@@ -109,7 +121,6 @@ async fn setup<E: Example>(title: &str) -> Setup {
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let optional_features = E::optional_features();
|
||||
let required_features = E::required_features();
|
||||
let adapter_features = adapter.features();
|
||||
@@ -168,7 +179,6 @@ fn start<E: Example>(
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
let spawner = {
|
||||
use futures::{future::LocalFutureObj, task::SpawnError};
|
||||
use winit::platform::web::WindowExtWebSys;
|
||||
|
||||
struct WebSpawner {}
|
||||
impl LocalSpawn for WebSpawner {
|
||||
@@ -180,18 +190,6 @@ fn start<E: Example>(
|
||||
}
|
||||
}
|
||||
|
||||
std::panic::set_hook(Box::new(console_error_panic_hook::hook));
|
||||
|
||||
// On wasm, append the canvas to the document body
|
||||
web_sys::window()
|
||||
.and_then(|win| win.document())
|
||||
.and_then(|doc| doc.body())
|
||||
.and_then(|body| {
|
||||
body.append_child(&web_sys::Element::from(window.canvas()))
|
||||
.ok()
|
||||
})
|
||||
.expect("couldn't append canvas to document body");
|
||||
|
||||
WebSpawner {}
|
||||
};
|
||||
|
||||
|
||||
@@ -90,15 +90,15 @@ impl crate::ComputePassInner<Context> for ComputePass {
|
||||
}
|
||||
|
||||
fn insert_debug_marker(&mut self, _label: &str) {
|
||||
unimplemented!()
|
||||
// TODO
|
||||
}
|
||||
|
||||
fn push_debug_group(&mut self, _group_label: &str) {
|
||||
unimplemented!()
|
||||
// TODO
|
||||
}
|
||||
|
||||
fn pop_debug_group(&mut self) {
|
||||
unimplemented!()
|
||||
// TODO
|
||||
}
|
||||
|
||||
fn dispatch(&mut self, x: u32, y: u32, z: u32) {
|
||||
@@ -263,15 +263,15 @@ impl crate::RenderPassInner<Context> for RenderPass {
|
||||
}
|
||||
|
||||
fn insert_debug_marker(&mut self, _label: &str) {
|
||||
unimplemented!()
|
||||
// TODO
|
||||
}
|
||||
|
||||
fn push_debug_group(&mut self, _group_label: &str) {
|
||||
unimplemented!()
|
||||
// TODO
|
||||
}
|
||||
|
||||
fn pop_debug_group(&mut self) {
|
||||
unimplemented!()
|
||||
// TODO
|
||||
}
|
||||
|
||||
fn execute_bundles<'a, I: Iterator<Item = &'a ()>>(&mut self, _render_bundles: I) {
|
||||
@@ -1465,13 +1465,13 @@ impl crate::Context for Context {
|
||||
}
|
||||
|
||||
fn command_encoder_insert_debug_marker(&self, encoder: &Self::CommandEncoderId, label: &str) {
|
||||
unimplemented!()
|
||||
// TODO
|
||||
}
|
||||
fn command_encoder_push_debug_group(&self, encoder: &Self::CommandEncoderId, label: &str) {
|
||||
unimplemented!()
|
||||
// TODO
|
||||
}
|
||||
fn command_encoder_pop_debug_group(&self, encoder: &Self::CommandEncoderId) {
|
||||
unimplemented!()
|
||||
// TODO
|
||||
}
|
||||
|
||||
fn render_bundle_encoder_finish(
|
||||
|
||||
Reference in New Issue
Block a user