1+ pub mod prelude;
2+ pub mod resources;
13mod buffer;
24mod camera;
35mod light;
46mod pipeline;
5- pub mod prelude;
6- pub mod resources;
77mod shader_canvas;
88
99pub use buffer:: * ;
@@ -16,12 +16,15 @@ pub use shader_canvas::*;
1616
1717#[ cfg( not( target_arch = "wasm32" ) ) ]
1818use pollster:: FutureExt ;
19- pub use rand;
2019
21- // use cgmath::*;
2220use std:: ops:: Deref ;
21+ use std:: path:: Path ;
22+ use std:: path:: PathBuf ;
2323use std:: sync:: Arc ;
24- use std:: time:: { Duration , Instant } ;
24+
25+ pub use rand;
26+
27+ use instant:: { Duration , Instant } ;
2528use wgpu:: util:: { BufferInitDescriptor , DeviceExt } ;
2629use winit:: application:: ApplicationHandler ;
2730use winit:: event_loop:: EventLoopProxy ;
@@ -89,8 +92,8 @@ impl Display {
8992 let config = wgpu:: SurfaceConfiguration {
9093 usage : wgpu:: TextureUsages :: RENDER_ATTACHMENT ,
9194 format : surface_format,
92- width : size. width ,
93- height : size. height ,
95+ width : size. width . max ( 1 ) ,
96+ height : size. height . max ( 1 ) ,
9497 present_mode : surface_caps. present_modes [ 0 ] ,
9598 alpha_mode : surface_caps. alpha_modes [ 0 ] ,
9699 view_formats : vec ! [ ] ,
@@ -259,7 +262,7 @@ impl UniformBinding {
259262}
260263
261264pub trait Demo : ' static + Sized + wgpu:: WasmNotSend + std:: fmt:: Debug {
262- fn init ( display : & Display ) -> impl std:: future:: Future < Output = anyhow:: Result < Self > > + wgpu:: WasmNotSend ;
265+ fn init ( display : & Display , path : & Path ) -> impl std:: future:: Future < Output = anyhow:: Result < Self > > + wgpu:: WasmNotSend ;
263266 fn resize ( & mut self , display : & Display ) ;
264267 fn update ( & mut self , display : & Display , dt : Duration ) ;
265268 fn render ( & mut self , display : & mut Display ) ;
@@ -312,15 +315,22 @@ impl<D: Demo + 'static> ApplicationHandler<anyhow::Result<(Display, D)>> for App
312315 if let Some ( proxy) = self . proxy . take ( ) {
313316 let window = window. clone ( ) ;
314317 let setup_future = async move {
318+ #[ cfg( not( target_arch = "wasm32" ) ) ]
319+ let res_dir = std:: env:: current_dir ( ) ?. join ( "res" ) ;
320+ #[ cfg( target_arch = "wasm32" ) ]
321+ let res_dir = PathBuf :: new ( ) ;
322+
315323 let display = Display :: new ( window) . await ?;
316- let demo = D :: init ( & display) . await ?;
324+ let demo = D :: init ( & display, & res_dir ) . await ?;
317325 anyhow:: Ok ( ( display, demo) )
318326 } ;
319327
320328 #[ cfg( target_arch = "wasm32" ) ]
321329 wasm_bindgen_futures:: spawn_local ( async move {
330+ log:: info!( "1" ) ;
322331 let result = setup_future. await ;
323332
333+ log:: info!( "2" ) ;
324334 proxy
325335 . send_event ( result)
326336 . expect ( "Unable to send (display, demo)" ) ;
@@ -420,7 +430,18 @@ impl<D: Demo + 'static> ApplicationHandler<anyhow::Result<(Display, D)>> for App
420430}
421431
422432pub fn run < D : Demo > ( ) -> anyhow:: Result < ( ) > {
423- // wgpu_subscriber::initialize_default_subscriber(None);
433+ #[ cfg( not( target_arch = "wasm32" ) ) ]
434+ {
435+ env_logger:: init ( ) ;
436+ }
437+ #[ cfg( target_arch = "wasm32" ) ]
438+ {
439+ use wgpu:: web_sys:: wasm_bindgen:: UnwrapThrowExt ;
440+ console_error_panic_hook:: set_once ( ) ;
441+ console_log:: init_with_level ( log:: Level :: Info ) . unwrap_throw ( ) ;
442+ }
443+
444+ log:: info!( "run" ) ;
424445
425446 let event_loop = EventLoop :: with_user_event ( ) . build ( ) ?;
426447 let mut app = App :: < D > :: new ( & event_loop) ;
0 commit comments