diff --git a/src/lib.rs b/src/lib.rs index c855e4b..1a57227 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,7 +9,7 @@ use winit::{ #[cfg(target_arch = "wasm32")] use wasm_bindgen::prelude::*; -use crate::render::{DefaultState, Renderer, State}; +use crate::render::{DefaultState, Renderer}; mod camera; mod model; @@ -167,7 +167,7 @@ pub async fn run() { } let mut renderer = Arc::from(Renderer::new(&window).await); - let default_state = Box::from(DefaultState::new(renderer.deref())); + let default_state = Box::from(DefaultState::new(renderer.deref()).await); Arc::get_mut(&mut renderer) .unwrap() .set_state(Some(default_state)); diff --git a/src/render/renderer/default_state.rs b/src/render/renderer/default_state.rs index d204f79..1475322 100644 --- a/src/render/renderer/default_state.rs +++ b/src/render/renderer/default_state.rs @@ -34,10 +34,8 @@ pub struct DefaultState { pipelines: render::Pipelines, } -impl super::State for DefaultState { - fn new(renderer: &Renderer) -> Self - where - Self: Sized, +impl DefaultState { + pub async fn new(renderer: &Renderer) -> Self { let global_bind_layout = render::GlobalBindLayout::new(&renderer.device); let pipelines = @@ -119,12 +117,12 @@ impl super::State for DefaultState { label: Some("camera_bind_group"), }); - let obj_model = async_std::task::block_on(resources::load_model( + let obj_model = resources::load_model( "cube.obj", &renderer.device, &renderer.queue, global_bind_layout.get_texture_bind_layout(), - )).unwrap(); + ).await.unwrap(); let light_uniform = LightUniform { position: [2.0, 2.0, 2.0], @@ -208,7 +206,9 @@ impl super::State for DefaultState { pipelines, } } +} +impl super::State for DefaultState { fn resize( &mut self, device: &wgpu::Device, diff --git a/src/render/renderer/mod.rs b/src/render/renderer/mod.rs index acd2399..5d9acc9 100644 --- a/src/render/renderer/mod.rs +++ b/src/render/renderer/mod.rs @@ -9,9 +9,6 @@ use wgpu::{CommandEncoder, Queue, TextureView}; use winit::event::Event; pub trait State { - fn new(renderer: &Renderer) -> Self - where - Self: Sized; fn resize( &mut self, device: &wgpu::Device,