|
|
|
@ -8,12 +8,12 @@ use winit::{
|
|
|
|
|
window::Window,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#[cfg(target_arch="wasm32")]
|
|
|
|
|
#[cfg(target_arch = "wasm32")]
|
|
|
|
|
use wasm_bindgen::prelude::*;
|
|
|
|
|
|
|
|
|
|
mod model;
|
|
|
|
|
mod texture;
|
|
|
|
|
mod resources;
|
|
|
|
|
mod texture;
|
|
|
|
|
|
|
|
|
|
use model::{DrawModel, Vertex};
|
|
|
|
|
|
|
|
|
@ -286,6 +286,7 @@ impl State {
|
|
|
|
|
width: size.width,
|
|
|
|
|
height: size.height,
|
|
|
|
|
present_mode: wgpu::PresentMode::Fifo,
|
|
|
|
|
alpha_mode: wgpu::CompositeAlphaMode::Auto,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
surface.configure(&device, &config);
|
|
|
|
@ -388,12 +389,10 @@ impl State {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
log::warn!("Load model");
|
|
|
|
|
let obj_model = resources::load_model(
|
|
|
|
|
"cube.obj",
|
|
|
|
|
&device,
|
|
|
|
|
&queue,
|
|
|
|
|
&texture_bind_group_layout,
|
|
|
|
|
).await.unwrap();
|
|
|
|
|
let obj_model =
|
|
|
|
|
resources::load_model("cube.obj", &device, &queue, &texture_bind_group_layout)
|
|
|
|
|
.await
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
|
|
|
|
|
label: Some("shader.wgsl"),
|
|
|
|
@ -558,7 +557,7 @@ impl State {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg_attr(target_arch="wasm32", wasm_bindgen(start))]
|
|
|
|
|
#[cfg_attr(target_arch = "wasm32", wasm_bindgen(start))]
|
|
|
|
|
pub async fn run() {
|
|
|
|
|
cfg_if::cfg_if! {
|
|
|
|
|
if #[cfg(target_arch = "wasm32")] {
|
|
|
|
@ -576,14 +575,13 @@ pub async fn run() {
|
|
|
|
|
.build(&event_loop)
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(target_arch = "wasm32")]
|
|
|
|
|
{
|
|
|
|
|
// 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(450, 400));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use winit::platform::web::WindowExtWebSys;
|
|
|
|
|
web_sys::window()
|
|
|
|
|
.and_then(|win| win.document())
|
|
|
|
@ -634,7 +632,9 @@ pub async fn run() {
|
|
|
|
|
match state.render() {
|
|
|
|
|
Ok(_) => {}
|
|
|
|
|
// Reconfigure the surface if it's lost or outdated
|
|
|
|
|
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => state.resize(state.size),
|
|
|
|
|
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => {
|
|
|
|
|
state.resize(state.size)
|
|
|
|
|
}
|
|
|
|
|
// The system is out of memory, we should probably quit
|
|
|
|
|
Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit,
|
|
|
|
|
// We're ignoring timeouts
|
|
|
|
|