diff --git a/Cargo.toml b/Cargo.toml index 54fa66e..a365bba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,6 @@ [workspace] members = ["kubi", "kubi-server", "kubi-shared", "kubi-logging"] +default-members = ["kubi"] resolver = "2" [profile.release-with-debug] @@ -15,7 +16,7 @@ opt-level = 1 [profile.dev.package.uflow] opt-level = 3 -[profile.dev.package.glium] +[profile.dev.package.wgpu] opt-level = 3 [profile.dev.package.bracket-noise] diff --git a/kubi/src/assets/texture.rs b/kubi/src/assets/texture.rs index 33cf932..5dde5ac 100644 --- a/kubi/src/assets/texture.rs +++ b/kubi/src/assets/texture.rs @@ -47,7 +47,7 @@ pub fn load_asset_texture_array< //Ensure same size (skip if poisoned) if !img_dim.is_poisoned() { - let img_dim = img_dim.lock().unwrap(); + let mut img_dim = img_dim.lock().unwrap(); if let Some(current_size) = img_dim.replace(dim_nonzero) { assert!(dim_nonzero == current_size, "image dimensions do not match"); } diff --git a/kubi/src/events.rs b/kubi/src/events.rs index 2ccedb4..75d9095 100644 --- a/kubi/src/events.rs +++ b/kubi/src/events.rs @@ -81,10 +81,13 @@ pub fn process_glutin_events(world: &mut World, event: &Event<'_, ()>) { pub fn initial_resize_event( mut storages: AllStoragesViewMut, ) { - let renderer = storages.borrow::>>().unwrap(); + let size = { + let renderer = storages.borrow::>>().unwrap(); + UVec2::new(renderer.size.width, renderer.size.height) + }; storages.add_entity(( EventComponent, - WindowResizedEvent(UVec2::new(renderer.size.width, renderer.size.height)) + WindowResizedEvent(size) )); } diff --git a/kubi/src/lib.rs b/kubi/src/lib.rs index c383963..34415bb 100644 --- a/kubi/src/lib.rs +++ b/kubi/src/lib.rs @@ -213,6 +213,10 @@ pub fn kubi_main() { #[allow(clippy::collapsible_match, clippy::single_match)] match event { Event::WindowEvent { event, .. } => match event { + WindowEvent::Resized(new_size) => { + //this can be in a system but I don't care + world.borrow::>>().unwrap().resize(new_size); + } WindowEvent::CloseRequested => { log::info!("exit requested"); *control_flow = ControlFlow::Exit; @@ -234,16 +238,19 @@ pub fn kubi_main() { //Start rendering (maybe use custom views for this?) let target = { let renderer = world.borrow::>>().unwrap(); - renderer.render() + renderer.begin() }; - world.add_unique_non_send_sync(RenderTarget(target)); + world.add_unique_non_send_sync(target); //Run render workflow world.run_workload(render).unwrap(); //Finish rendering - let target = world.remove_unique::().unwrap(); - target.0.finish().unwrap(); + { + let target = world.remove_unique::().unwrap(); + let renderer = world.borrow::>>().unwrap(); + renderer.end(target); + } //After frame end world.run_workload(after_frame_end).unwrap(); diff --git a/kubi/src/rendering.rs b/kubi/src/rendering.rs index e664645..bf08a13 100644 --- a/kubi/src/rendering.rs +++ b/kubi/src/rendering.rs @@ -18,8 +18,11 @@ pub mod selection_box; pub mod entities; #[derive(Unique)] -#[repr(transparent)] -pub struct RenderTarget(pub ()); +pub struct RenderTarget { + pub output: wgpu::SurfaceTexture, + pub view: wgpu::TextureView, + pub encoder: wgpu::CommandEncoder, +} #[derive(Unique)] #[repr(transparent)] @@ -116,7 +119,7 @@ impl Renderer { }, None, ).await.unwrap(); - + // surf. format let surface_capabilities = surface.get_capabilities(&adapter); @@ -141,7 +144,9 @@ impl Renderer { }; surface.configure(&device, &config); - Self { window, instance, surface, adapter, device, queue, size, config } + Self { + window, instance, surface, adapter, device, queue, size, config, + } } /// do not call from async functions @@ -150,14 +155,27 @@ impl Renderer { } /// Start a new frame - pub fn render() -> RenderTarget { - todo!() + pub fn begin(&self) -> RenderTarget { + //Surface texture + let output = self.surface.get_current_texture().unwrap(); + //View + let view = output.texture.create_view(&wgpu::TextureViewDescriptor::default()); + //Encoder + let encoder = self.device.create_command_encoder(&wgpu::CommandEncoderDescriptor { + label: Some("RenderEncoder"), + }); + RenderTarget { output, view, encoder } } + pub fn end(&self, target: RenderTarget) { + self.queue.submit([target.encoder.finish()]); + target.output.present(); + } + /// Resize the surface /// ## Panics: /// - ...if any dimension is equal to zero - pub fn resize(&self, new_size: PhysicalSize) { + pub fn resize(&mut self, new_size: PhysicalSize) { //XXX: just check instead? assert!(new_size.width > 0, "width cannot be zero"); assert!(new_size.height > 0, "height cannot be zero");