|
|
|
@ -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};
|
|
|
|
|
|
|
|
|
@ -254,7 +254,7 @@ impl State {
|
|
|
|
|
backends: wgpu::Backends::all(),
|
|
|
|
|
dx12_shader_compiler: Default::default(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// # Safety
|
|
|
|
|
//
|
|
|
|
|
// The surface needs to live as long as the window that created it.
|
|
|
|
@ -294,7 +294,9 @@ impl State {
|
|
|
|
|
// Shader code in this tutorial assumes an Srgb surface texture. Using a different
|
|
|
|
|
// one will result all the colors comming out darker. If you want to support non
|
|
|
|
|
// Srgb surfaces, you'll need to account for that when drawing to the frame.
|
|
|
|
|
let surface_format = surface_caps.formats.iter()
|
|
|
|
|
let surface_format = surface_caps
|
|
|
|
|
.formats
|
|
|
|
|
.iter()
|
|
|
|
|
.copied()
|
|
|
|
|
.filter(|f| f.describe().srgb)
|
|
|
|
|
.next()
|
|
|
|
@ -409,12 +411,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"),
|
|
|
|
@ -514,6 +514,7 @@ impl State {
|
|
|
|
|
self.surface.configure(&self.device, &self.config);
|
|
|
|
|
self.depth_texture =
|
|
|
|
|
texture::Texture::create_depth_texture(&self.device, &self.config, "depth_texture");
|
|
|
|
|
self.window.request_redraw();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fn input(&mut self, event: &WindowEvent) -> bool {
|
|
|
|
@ -584,7 +585,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")] {
|
|
|
|
@ -602,14 +603,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())
|
|
|
|
@ -628,7 +628,6 @@ pub async fn run() {
|
|
|
|
|
event_loop.run(move |event, _, control_flow| {
|
|
|
|
|
*control_flow = ControlFlow::Poll;
|
|
|
|
|
match event {
|
|
|
|
|
Event::MainEventsCleared => state.window().request_redraw(),
|
|
|
|
|
Event::WindowEvent {
|
|
|
|
|
ref event,
|
|
|
|
|
window_id,
|
|
|
|
@ -660,7 +659,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
|
|
|
|
|