diff --git a/crates/components/src/map_view.rs b/crates/components/src/map_view.rs index cd603fcf..3515d559 100644 --- a/crates/components/src/map_view.rs +++ b/crates/components/src/map_view.rs @@ -380,6 +380,13 @@ impl MapView { let time = ui.input(|i| i.time); self.map_view .increment_animation_time(&graphics_state, time); + + self.map_view.grid.display.update_viewport_size( + &graphics_state.render_state, + [canvas_rect.size().x, canvas_rect.size().y], + ui.ctx().pixels_per_point(), + ); + self.map_view .paint(&graphics_state, ui.painter(), canvas_rect); diff --git a/crates/components/src/tilepicker.rs b/crates/components/src/tilepicker.rs index 937df0a4..1f052c5a 100644 --- a/crates/components/src/tilepicker.rs +++ b/crates/components/src/tilepicker.rs @@ -17,6 +17,7 @@ use fragile::Fragile; use itertools::Itertools; +use luminol_graphics::Renderable; use std::sync::Arc; use std::time::Duration; @@ -54,21 +55,21 @@ struct Callback { impl luminol_egui_wgpu::CallbackTrait for Callback { fn paint<'a>( &'a self, - info: egui::PaintCallbackInfo, + _: egui::PaintCallbackInfo, render_pass: &mut wgpu::RenderPass<'a>, _callback_resources: &'a luminol_egui_wgpu::CallbackResources, ) { let resources = self.resources.get(); let graphics_state = self.graphics_state.get(); - resources.tiles.draw(graphics_state, &[true], render_pass); + resources.tiles.draw(graphics_state, render_pass); if self.coll_enabled { resources.collision.draw(graphics_state, render_pass); } if self.grid_enabled { - resources.grid.draw(graphics_state, &info, render_pass); + resources.grid.draw(graphics_state, render_pass); } } } @@ -233,6 +234,12 @@ impl Tilepicker { .intersect(scroll_rect.translate(canvas_rect.min.to_vec2())); let scroll_rect = absolute_scroll_rect.translate(-canvas_rect.min.to_vec2()); + self.resources.grid.display.update_viewport_size( + &graphics_state.render_state, + [scroll_rect.size().x, scroll_rect.size().y], + ui.ctx().pixels_per_point(), + ); + self.viewport.set_proj( &graphics_state.render_state, glam::Mat4::orthographic_rh( diff --git a/crates/graphics/src/map.rs b/crates/graphics/src/map.rs index 5b1cc44d..03434ee2 100644 --- a/crates/graphics/src/map.rs +++ b/crates/graphics/src/map.rs @@ -37,7 +37,6 @@ pub struct MapView { pub pano_enabled: bool, pub coll_enabled: bool, pub grid_enabled: bool, - pub enabled_layers: Vec, } impl MapView { @@ -145,7 +144,6 @@ impl MapView { pano_enabled: true, coll_enabled: false, grid_enabled: true, - enabled_layers: vec![true; map.data.zsize()], }) } @@ -197,8 +195,7 @@ impl crate::Renderable for MapView { } } - self.tiles - .draw(graphics_state, &self.enabled_layers, render_pass); + self.tiles.draw(graphics_state, render_pass); for (_, event) in self.events.iter() { event.draw(graphics_state, render_pass); @@ -215,8 +212,7 @@ impl crate::Renderable for MapView { } if self.grid_enabled { - // self.grid - // .draw(graphics_state, info, &mut render_bundle_encoder); + self.grid.draw(graphics_state, render_pass); } } } diff --git a/crates/graphics/src/primitives/collision/mod.rs b/crates/graphics/src/primitives/collision/mod.rs index 484b9a21..faf9b772 100644 --- a/crates/graphics/src/primitives/collision/mod.rs +++ b/crates/graphics/src/primitives/collision/mod.rs @@ -172,8 +172,10 @@ impl Collision { ) { self.instances.set_passage(render_state, passage, position) } +} - pub fn draw<'rpass>( +impl crate::Renderable for Collision { + fn draw<'rpass>( &'rpass self, graphics_state: &'rpass GraphicsState, render_pass: &mut impl wgpu::util::RenderEncoder<'rpass>, diff --git a/crates/graphics/src/primitives/grid/display.rs b/crates/graphics/src/primitives/grid/display.rs index d7e2320d..fb5ddfa5 100644 --- a/crates/graphics/src/primitives/grid/display.rs +++ b/crates/graphics/src/primitives/grid/display.rs @@ -83,23 +83,19 @@ impl Display { } } - pub(super) fn update_viewport_size( + pub fn update_viewport_size( &self, render_state: &luminol_egui_wgpu::RenderState, - info: &egui::PaintCallbackInfo, + viewport_size_in_pixels: [f32; 2], + pixels_per_point: f32, ) { - let viewport_size = info.viewport_in_pixels(); - let viewport_size = [ - viewport_size.width_px as f32, - viewport_size.height_px as f32, - ]; - let pixels_per_point = info.pixels_per_point.max(1.).floor(); + let pixels_per_point = pixels_per_point.max(1.).floor(); let data = self.data.load(); - if data.viewport_size_in_pixels != viewport_size + if data.viewport_size_in_pixels != viewport_size_in_pixels || data.pixels_per_point != pixels_per_point { self.data.store(Data { - viewport_size_in_pixels: viewport_size, + viewport_size_in_pixels, pixels_per_point, ..data }); diff --git a/crates/graphics/src/primitives/grid/mod.rs b/crates/graphics/src/primitives/grid/mod.rs index 363771e0..1dd609fe 100644 --- a/crates/graphics/src/primitives/grid/mod.rs +++ b/crates/graphics/src/primitives/grid/mod.rs @@ -63,27 +63,18 @@ impl Grid { bind_group, } } +} - pub fn draw<'rpass>( +impl crate::Renderable for Grid { + fn draw<'rpass>( &'rpass self, graphics_state: &'rpass GraphicsState, - info: &egui::PaintCallbackInfo, render_pass: &mut impl wgpu::util::RenderEncoder<'rpass>, ) { - #[repr(C)] - #[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)] - struct VertexPushConstant { - viewport: [u8; 64], - display: [u8; 16], - } - render_pass.set_pipeline(&graphics_state.pipelines.grid); render_pass.set_bind_group(0, &self.bind_group, &[]); - self.display - .update_viewport_size(&graphics_state.render_state, info); - self.instances.draw(render_pass); } } diff --git a/crates/graphics/src/primitives/tiles/mod.rs b/crates/graphics/src/primitives/tiles/mod.rs index 3eccff34..d7c9e754 100644 --- a/crates/graphics/src/primitives/tiles/mod.rs +++ b/crates/graphics/src/primitives/tiles/mod.rs @@ -38,6 +38,7 @@ pub struct Tiles { pub instances: Instances, pub display: Display, pub viewport: Arc, + pub enabled_layers: Vec, pub bind_group: wgpu::BindGroup, } @@ -78,12 +79,14 @@ impl Tiles { &graphics_state.bind_group_layouts.tiles, ); + let enabled_layers = vec![true; tiles.zsize()]; + Self { autotiles, atlas, instances, display, - + enabled_layers, bind_group, viewport, } @@ -115,23 +118,18 @@ impl Tiles { .set_opacity(&graphics_state.render_state, opacity, layer); } } +} - pub fn draw<'rpass>( +impl crate::Renderable for Tiles { + fn draw<'rpass>( &'rpass self, graphics_state: &'rpass GraphicsState, - enabled_layers: &[bool], render_pass: &mut impl wgpu::util::RenderEncoder<'rpass>, ) { - #[repr(C)] - #[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)] - struct VertexPushConstant { - viewport: [u8; 64], - autotiles: [u8; 48], - } - render_pass.set_pipeline(&graphics_state.pipelines.tiles); - for layer in enabled_layers + for layer in self + .enabled_layers .iter() .enumerate() .filter_map(|(l, e)| e.then_some(l)) diff --git a/crates/ui/src/tabs/map/mod.rs b/crates/ui/src/tabs/map/mod.rs index 0172766a..2c1492fb 100644 --- a/crates/ui/src/tabs/map/mod.rs +++ b/crates/ui/src/tabs/map/mod.rs @@ -220,8 +220,13 @@ impl luminol_core::Tab for Tab { ui.checkbox(&mut self.view.map_view.pano_enabled, "👁"); ui.end_row(); - for (index, layer) in - self.view.map_view.enabled_layers.iter_mut().enumerate() + for (index, layer) in self + .view + .map_view + .tiles + .enabled_layers + .iter_mut() + .enumerate() { ui.columns(1, |columns| { columns[0].selectable_value( @@ -631,7 +636,7 @@ impl luminol_core::Tab for Tab { None }, (0..map.data.zsize()) - .filter(|&i| self.view.map_view.enabled_layers[i]) + .filter(|&i| self.view.map_view.tiles.enabled_layers[i]) .rev(), |x, y, passage| { if self.passages[(x, y)] != passage {