wgpu basics
This commit is contained in:
parent
1d5d1f627d
commit
6d003d2c98
|
@ -10,13 +10,16 @@ pub mod colors;
|
|||
use std::io::Cursor;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use js_sys::Uint8Array;
|
||||
use log::info;
|
||||
use log::{debug, info};
|
||||
use wasm_bindgen::prelude::*;
|
||||
use web_sys::{CanvasRenderingContext2d, HtmlCanvasElement};
|
||||
use winit::dpi::PhysicalSize;
|
||||
use winit::event_loop::EventLoop;
|
||||
use winit::event::{ElementState, Event, WindowEvent};
|
||||
use winit::event::WindowEvent::KeyboardInput;
|
||||
use winit::event_loop::{EventLoop, EventLoopWindowTarget};
|
||||
use winit::keyboard::KeyCode;
|
||||
use winit::window::WindowBuilder;
|
||||
use winit::platform::web::WindowExtWebSys;
|
||||
use winit::platform::web::{WindowExtWebSys, EventLoopExtWebSys};
|
||||
use crate::command::{exec, should_newline};
|
||||
use crate::mode::Mode;
|
||||
use crate::mode::Mode::Reflectivity;
|
||||
|
@ -46,13 +49,33 @@ pub fn __nxrd_browser_init() -> AbiScopeState {
|
|||
web_sys::window()
|
||||
.and_then(|win| win.document())
|
||||
.and_then(|doc| {
|
||||
let dst = doc.get_element_by_id("wasm-example")?;
|
||||
let dst = doc.get_element_by_id("canvas-container")?;
|
||||
// If you see an error here, your IDE is not compiling for webassembly
|
||||
let canvas = web_sys::Element::from(window.canvas().unwrap());
|
||||
dst.append_child(&canvas).ok()?;
|
||||
Some(())
|
||||
})
|
||||
.expect("Couldn't append canvas to document body.");
|
||||
|
||||
// If you see an error here, your IDE is not compiling for webassembly
|
||||
event_loop.spawn(move |event: Event<_>, window: &EventLoopWindowTarget<_>| {
|
||||
match event {
|
||||
Event::WindowEvent { ref event, window_id} => {
|
||||
match event {
|
||||
KeyboardInput { event, .. } => {
|
||||
debug!("{:?}", event.physical_key);
|
||||
if event.physical_key == KeyCode::Escape {
|
||||
window.exit();
|
||||
}
|
||||
},
|
||||
WindowEvent::CloseRequested => { window.exit(); },
|
||||
_ => {}
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
});
|
||||
|
||||
info!("initializing the scope");
|
||||
|
||||
let document = web_sys::window().expect("window should exist").document().expect("document should exist");
|
||||
|
|
|
@ -1,8 +1,19 @@
|
|||
<html>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>NEXRAD Browser</title>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<style>
|
||||
#canvas {
|
||||
#canvas-container {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
canvas {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
image-rendering: pixelated;
|
||||
|
@ -16,6 +27,8 @@
|
|||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="canvas-container"></div>
|
||||
|
||||
<input type="file" id="file" style="display: none;" />
|
||||
|
||||
<script src="bootstrap.js"></script>
|
||||
|
|
Loading…
Reference in New Issue