1
0
Fork 0

[WASM] Fix build error

This commit is contained in:
Florian RICHER 2022-06-22 20:24:40 +02:00
parent 94b59568b1
commit 1feca362a7
3 changed files with 8 additions and 11 deletions

View file

@ -9,7 +9,7 @@ use winit::{
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*; use wasm_bindgen::prelude::*;
use crate::render::{DefaultState, Renderer, State}; use crate::render::{DefaultState, Renderer};
mod camera; mod camera;
mod model; mod model;
@ -167,7 +167,7 @@ pub async fn run() {
} }
let mut renderer = Arc::from(Renderer::new(&window).await); 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) Arc::get_mut(&mut renderer)
.unwrap() .unwrap()
.set_state(Some(default_state)); .set_state(Some(default_state));

View file

@ -34,10 +34,8 @@ pub struct DefaultState {
pipelines: render::Pipelines, pipelines: render::Pipelines,
} }
impl super::State for DefaultState { impl DefaultState {
fn new(renderer: &Renderer) -> Self pub async fn new(renderer: &Renderer) -> Self
where
Self: Sized,
{ {
let global_bind_layout = render::GlobalBindLayout::new(&renderer.device); let global_bind_layout = render::GlobalBindLayout::new(&renderer.device);
let pipelines = let pipelines =
@ -119,12 +117,12 @@ impl super::State for DefaultState {
label: Some("camera_bind_group"), label: Some("camera_bind_group"),
}); });
let obj_model = async_std::task::block_on(resources::load_model( let obj_model = resources::load_model(
"cube.obj", "cube.obj",
&renderer.device, &renderer.device,
&renderer.queue, &renderer.queue,
global_bind_layout.get_texture_bind_layout(), global_bind_layout.get_texture_bind_layout(),
)).unwrap(); ).await.unwrap();
let light_uniform = LightUniform { let light_uniform = LightUniform {
position: [2.0, 2.0, 2.0], position: [2.0, 2.0, 2.0],
@ -208,7 +206,9 @@ impl super::State for DefaultState {
pipelines, pipelines,
} }
} }
}
impl super::State for DefaultState {
fn resize( fn resize(
&mut self, &mut self,
device: &wgpu::Device, device: &wgpu::Device,

View file

@ -9,9 +9,6 @@ use wgpu::{CommandEncoder, Queue, TextureView};
use winit::event::Event; use winit::event::Event;
pub trait State { pub trait State {
fn new(renderer: &Renderer) -> Self
where
Self: Sized;
fn resize( fn resize(
&mut self, &mut self,
device: &wgpu::Device, device: &wgpu::Device,