wasm WIP
This commit is contained in:
parent
a7ea7ee65b
commit
dc3bd2a433
6 changed files with 119 additions and 8 deletions
26
Cargo.lock
generated
26
Cargo.lock
generated
|
@ -268,6 +268,26 @@ version = "1.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b"
|
checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "console_error_panic_hook"
|
||||||
|
version = "0.1.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"wasm-bindgen",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "console_log"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "501a375961cef1a0d44767200e66e4a559283097e91d0730b1d75dfb2f8a1494"
|
||||||
|
dependencies = [
|
||||||
|
"log",
|
||||||
|
"web-sys",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "core-foundation"
|
name = "core-foundation"
|
||||||
version = "0.9.3"
|
version = "0.9.3"
|
||||||
|
@ -2241,7 +2261,10 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
|
"cfg-if",
|
||||||
"cgmath",
|
"cgmath",
|
||||||
|
"console_error_panic_hook",
|
||||||
|
"console_log",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"fs_extra",
|
"fs_extra",
|
||||||
"glob",
|
"glob",
|
||||||
|
@ -2252,6 +2275,9 @@ dependencies = [
|
||||||
"regex",
|
"regex",
|
||||||
"rust-embed",
|
"rust-embed",
|
||||||
"tobj",
|
"tobj",
|
||||||
|
"wasm-bindgen",
|
||||||
|
"wasm-bindgen-futures",
|
||||||
|
"web-sys",
|
||||||
"wgpu",
|
"wgpu",
|
||||||
"wgpu-types",
|
"wgpu-types",
|
||||||
"winit",
|
"winit",
|
||||||
|
|
20
Cargo.toml
20
Cargo.toml
|
@ -3,7 +3,12 @@ name = "wgpu-renderer"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
[lib]
|
||||||
|
crate-type = ["cdylib", "rlib"]
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "wgpu-renderer"
|
||||||
|
path = "src/main.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
winit = "0.27.5"
|
winit = "0.27.5"
|
||||||
|
@ -20,6 +25,19 @@ gltf = "1.0.0"
|
||||||
wgpu-types = "0.14.1"
|
wgpu-types = "0.14.1"
|
||||||
regex = "1.7.1"
|
regex = "1.7.1"
|
||||||
rust-embed = "6.4.2"
|
rust-embed = "6.4.2"
|
||||||
|
cfg-if = "1"
|
||||||
|
|
||||||
|
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||||
|
console_error_panic_hook = "0.1.6"
|
||||||
|
console_log = "0.2.0"
|
||||||
|
wgpu = { version = "0.14", features = ["webgl"]}
|
||||||
|
wasm-bindgen = "0.2"
|
||||||
|
wasm-bindgen-futures = "0.4.30"
|
||||||
|
web-sys = { version = "0.3", features = [
|
||||||
|
"Document",
|
||||||
|
"Window",
|
||||||
|
"Element",
|
||||||
|
]}
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
anyhow = "1.0.68"
|
anyhow = "1.0.68"
|
||||||
|
|
25
index.html
Normal file
25
index.html
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>wgpu-renderer</title>
|
||||||
|
<style>
|
||||||
|
canvas {
|
||||||
|
background-color: black;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body id="wasm-example">
|
||||||
|
<script type="module">
|
||||||
|
import init from "./pkg/wgpu_renderer.js";
|
||||||
|
init().then(() => {
|
||||||
|
console.log("WASM Loaded");
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
|
@ -17,9 +17,33 @@ pub async fn run() {
|
||||||
let mut state = State::new(&window).await;
|
let mut state = State::new(&window).await;
|
||||||
let mut last_render = Instant::now();
|
let mut last_render = Instant::now();
|
||||||
|
|
||||||
|
#[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
|
window
|
||||||
.set_cursor_grab(winit::window::CursorGrabMode::Confined)
|
.set_cursor_grab(winit::window::CursorGrabMode::Confined)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
window.set_cursor_visible(false);
|
window.set_cursor_visible(false);
|
||||||
|
|
||||||
// Event loop
|
// 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)]
|
use wgpu_renderer::run;
|
||||||
|
|
||||||
mod core;
|
|
||||||
mod shaders;
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
env_logger::init();
|
run();
|
||||||
pollster::block_on(core::window::run());
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue