new rendering framework

This commit is contained in:
core 2023-11-06 21:56:19 -05:00
parent 313dca0483
commit 1d5d1f627d
Signed by: core
GPG Key ID: FDBF740DADDCEECF
7 changed files with 30 additions and 22 deletions

View File

@ -22,6 +22,7 @@ wasm-logger = "0.2"
serde-wasm-bindgen = "0.6"
chrono = "0.4"
itertools = "0.11"
winit = "0.29"
[dependencies.js-sys]
version = "0.3"

View File

@ -1,7 +1,6 @@
use web_sys::FileReader;
use crate::loadar2;
use crate::mode::Mode;
use crate::rendering::render;
use crate::scope::ScopeState;
pub fn should_newline(state: &mut ScopeState) -> bool {
@ -16,7 +15,6 @@ pub fn exec(state: &mut ScopeState, command: String) {
} else if command == "CLF RELOAD" {
state.command_buf = "SYSTEM PROCESSING".to_string();
state.command_buf_response_mode = true;
render(state).expect("rerender failed");
loadar2("file");
} else if command.starts_with("MODE SET") {
if tokens.len() < 3 {

View File

@ -1,5 +1,4 @@
pub mod utils;
pub mod rendering;
pub mod mode;
pub mod scope;
pub mod equirectangular;
@ -14,6 +13,10 @@ use js_sys::Uint8Array;
use log::info;
use wasm_bindgen::prelude::*;
use web_sys::{CanvasRenderingContext2d, HtmlCanvasElement};
use winit::dpi::PhysicalSize;
use winit::event_loop::EventLoop;
use winit::window::WindowBuilder;
use winit::platform::web::WindowExtWebSys;
use crate::command::{exec, should_newline};
use crate::mode::Mode;
use crate::mode::Mode::Reflectivity;
@ -33,15 +36,26 @@ pub fn __nxrd_browser_init() -> AbiScopeState {
wasm_logger::init(wasm_logger::Config::new(log::Level::Debug));
utils::set_panic_hook();
info!("wgpu setup");
let event_loop = EventLoop::new().expect("event loop creation failed");
let window = WindowBuilder::new().build(&event_loop).unwrap();
window.set_min_inner_size(Some(PhysicalSize::new(450, 400)));
web_sys::window()
.and_then(|win| win.document())
.and_then(|doc| {
let dst = doc.get_element_by_id("wasm-example")?;
let canvas = web_sys::Element::from(window.canvas().unwrap());
dst.append_child(&canvas).ok()?;
Some(())
})
.expect("Couldn't append canvas to document body.");
info!("initializing the scope");
info!("finding canvas element");
let document = web_sys::window().expect("window should exist").document().expect("document should exist");
let canvas = document.get_element_by_id("canvas").expect("canvas element should exist");
let canvas: web_sys::HtmlCanvasElement = canvas.dyn_into::<web_sys::HtmlCanvasElement>().map_err(|_| ()).expect("canvas is not a canvas");
let context = canvas.get_context("2d").expect("failed to get canvas rendering context").expect("canvas rendering context doesn't exist").dyn_into::<web_sys::CanvasRenderingContext2d>().map_err(|_| ()).expect("2d context is not a 2d context");
info!("finding form input element");
@ -51,10 +65,6 @@ pub fn __nxrd_browser_init() -> AbiScopeState {
let scope_state = ScopeState {
ar2: None,
scope_mode: Mode::RadarInoperative,
render_state: RenderState {
canvas,
context
},
file_input: file,
lat: 30.48500, // jacksonville
long: -81.70200, // jacksonville
@ -72,12 +82,14 @@ pub fn __nxrd_browser_init() -> AbiScopeState {
AbiScopeState(scope_state)
}
/*
#[wasm_bindgen]
pub fn render_abi(state: &mut AbiScopeState) {
rendering::render(&mut state.0).unwrap()
old_rendering::render(&mut state.0).unwrap()
}
*/
#[wasm_bindgen]
pub fn load_ar2(buf: &JsValue, scope: &mut AbiScopeState) {
let array = Uint8Array::new(buf);

View File

@ -5,7 +5,6 @@ use crate::mode::Mode;
pub struct ScopeState {
pub ar2: Option<Nexrad2Chunk>,
pub scope_mode: Mode,
pub render_state: RenderState,
pub file_input: HtmlInputElement,
pub lat: f64,
pub long: f64,

View File

@ -16,10 +16,6 @@
</style>
</head>
<body>
<canvas id="canvas">
Something went wrong while loading the canvas. Sorry :/
</canvas>
<input type="file" id="file" style="display: none;" />
<script src="bootstrap.js"></script>

View File

@ -1,7 +1,7 @@
import * as wasm from "./wasm/nexrad_browser.js";
await wasm.default();
let global_context = wasm.__nxrd_browser_init();
/*
function rescaleCanvas(canvas, ctx) {
var dpr = window.devicePixelRatio || 1;
// Get the size of the canvas in CSS pixels.
@ -40,4 +40,6 @@ document.getElementById("file").onchange = () => {
let render = () => { wasm.render_abi(global_context); requestAnimationFrame(render); }
requestAnimationFrame(render);
requestAnimationFrame(render);
*/