wasm WIP
This commit is contained in:
parent
a7ea7ee65b
commit
dc3bd2a433
6 changed files with 119 additions and 8 deletions
|
@ -17,9 +17,33 @@ pub async fn run() {
|
|||
let mut state = State::new(&window).await;
|
||||
let mut last_render = Instant::now();
|
||||
|
||||
window
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
{
|
||||
std::panic::set_hook(Box::new(console_error_panic_hook::hook));
|
||||
console_log::init().expect("could not initialize logger");
|
||||
|
||||
// Winit prevents sizing with CSS, so we have to set
|
||||
// the size manually when on web.
|
||||
use winit::dpi::PhysicalSize;
|
||||
window.set_inner_size(PhysicalSize::new(1920, 1080));
|
||||
|
||||
use winit::platform::web::WindowExtWebSys;
|
||||
web_sys::window()
|
||||
.and_then(|win| win.document())
|
||||
.and_then(|doc| doc.body())
|
||||
.and_then(|body| {
|
||||
let canvas = web_sys::Element::from(window.canvas());
|
||||
body.append_child(&canvas).ok()
|
||||
})
|
||||
.expect("Couldn't append canvas to document body.");
|
||||
}
|
||||
#[cfg(not(target_arch = "wasm"))]
|
||||
{
|
||||
window
|
||||
.set_cursor_grab(winit::window::CursorGrabMode::Confined)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
window.set_cursor_visible(false);
|
||||
|
||||
// Event loop
|
||||
|
|
22
src/lib.rs
Normal file
22
src/lib.rs
Normal file
|
@ -0,0 +1,22 @@
|
|||
#![allow(clippy::needless_return)]
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
mod core;
|
||||
mod shaders;
|
||||
|
||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen(start))]
|
||||
pub fn run() {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
{
|
||||
std::panic::set_hook(Box::new(console_error_panic_hook::hook));
|
||||
console_log::init_with_level(log::Level::Warn).expect("Couldn't initialize logger");
|
||||
wasm_bindgen_futures::spawn_local(core::window::run());
|
||||
}
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
env_logger::init();
|
||||
pollster::block_on(core::window::run());
|
||||
}
|
||||
}
|
|
@ -1,9 +1,5 @@
|
|||
#![allow(clippy::needless_return)]
|
||||
|
||||
mod core;
|
||||
mod shaders;
|
||||
use wgpu_renderer::run;
|
||||
|
||||
fn main() {
|
||||
env_logger::init();
|
||||
pollster::block_on(core::window::run());
|
||||
run();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue