MCPcopy Create free account
hub / github.com/Rust-GPU/rust-gpu / start

Function start

examples/runners/wgpu/src/graphics.rs:408–478  ·  view source on GitHub ↗
(
    #[cfg(target_os = "android")] android_app: winit::platform::android::activity::AndroidApp,
    options: &Options,
)

Source from the content-addressed store, hash-verified

406
407#[allow(clippy::match_wild_err_arm)]
408pub fn start(
409 #[cfg(target_os = "android")] android_app: winit::platform::android::activity::AndroidApp,
410 options: &Options,
411) {
412 let mut event_loop_builder = EventLoopBuilder::with_user_event();
413 cfg_if::cfg_if! {
414 if #[cfg(target_os = "android")] {
415 android_logger::init_once(
416 android_logger::Config::default()
417 .with_max_level("info".parse().unwrap()),
418 );
419
420 use winit::platform::android::EventLoopBuilderExtAndroid;
421 event_loop_builder.with_android_app(android_app);
422 } else if #[cfg(target_arch = "wasm32")] {
423 std::panic::set_hook(Box::new(console_error_panic_hook::hook));
424 console_log::init().expect("could not initialize logger");
425 } else {
426 env_logger::init();
427 }
428 }
429 let event_loop = event_loop_builder.build();
430
431 // Build the shader before we pop open a window, since it might take a while.
432 let initial_shader = maybe_watch(
433 options,
434 #[cfg(not(any(target_os = "android", target_arch = "wasm32")))]
435 {
436 let proxy = event_loop.create_proxy();
437 Some(Box::new(move |res| match proxy.send_event(res) {
438 Ok(it) => it,
439 // ShaderModuleDescriptor is not `Debug`, so can't use unwrap/expect
440 Err(_err) => panic!("Event loop dead"),
441 }))
442 },
443 );
444
445 let window = winit::window::WindowBuilder::new()
446 .with_title("Rust GPU - wgpu")
447 .with_inner_size(winit::dpi::LogicalSize::new(1280.0, 720.0))
448 .build(&event_loop)
449 .unwrap();
450
451 cfg_if::cfg_if! {
452 if #[cfg(target_arch = "wasm32")] {
453 use winit::platform::web::WindowExtWebSys;
454 // On wasm, append the canvas to the document body
455 web_sys::window()
456 .and_then(|win| win.document())
457 .and_then(|doc| doc.body())
458 .and_then(|body| {
459 body.append_child(&web_sys::Element::from(window.canvas()))
460 .ok()
461 })
462 .expect("couldn't append canvas to document body");
463 wasm_bindgen_futures::spawn_local(run(
464 options.clone(),
465 event_loop,

Callers

nothing calls this directly

Calls 2

maybe_watchFunction · 0.85
buildMethod · 0.45

Tested by

no test coverage detected