From 2ca3f35a3bd66c3e89a6b2be89885cbfef643e44 Mon Sep 17 00:00:00 2001 From: Speak2Erase Date: Sun, 11 Feb 2024 16:27:51 -0800 Subject: [PATCH] refactor(tilemap): :recycle: Take a &mut impl RenderEncoder instead of RenderPass --- crates/graphics/src/collision/instance.rs | 2 +- crates/graphics/src/collision/mod.rs | 4 +--- crates/graphics/src/grid/instance.rs | 2 +- crates/graphics/src/grid/mod.rs | 4 +--- crates/graphics/src/plane.rs | 2 +- crates/graphics/src/sprite/mod.rs | 4 +--- crates/graphics/src/sprite/vertices.rs | 2 +- crates/graphics/src/tiles/instance.rs | 6 +++++- crates/graphics/src/tiles/mod.rs | 4 +--- 9 files changed, 13 insertions(+), 17 deletions(-) diff --git a/crates/graphics/src/collision/instance.rs b/crates/graphics/src/collision/instance.rs index 48b4babe..e011b23b 100644 --- a/crates/graphics/src/collision/instance.rs +++ b/crates/graphics/src/collision/instance.rs @@ -170,7 +170,7 @@ impl Instances { ] } - pub fn draw<'rpass>(&'rpass self, render_pass: &mut wgpu::RenderPass<'rpass>) { + pub fn draw<'rpass>(&'rpass self, render_pass: &mut impl wgpu::util::RenderEncoder<'rpass>) { render_pass.set_vertex_buffer(0, self.vertex_buffer.slice(..)); // Calculate the start and end index of the buffer, as well as the amount of instances. diff --git a/crates/graphics/src/collision/mod.rs b/crates/graphics/src/collision/mod.rs index 4be6b41c..2e997474 100644 --- a/crates/graphics/src/collision/mod.rs +++ b/crates/graphics/src/collision/mod.rs @@ -183,9 +183,8 @@ impl Collision { pub fn draw<'rpass>( &'rpass self, graphics_state: &'rpass GraphicsState, - render_pass: &mut wgpu::RenderPass<'rpass>, + render_pass: &mut impl wgpu::util::RenderEncoder<'rpass>, ) { - render_pass.push_debug_group("tilemap collision renderer"); render_pass.set_pipeline(&graphics_state.pipelines.collision); if let Some(bind_group) = &self.bind_group { @@ -199,7 +198,6 @@ impl Collision { } self.instances.draw(render_pass); - render_pass.pop_debug_group(); } } diff --git a/crates/graphics/src/grid/instance.rs b/crates/graphics/src/grid/instance.rs index b3f7aaf7..dd829ab8 100644 --- a/crates/graphics/src/grid/instance.rs +++ b/crates/graphics/src/grid/instance.rs @@ -96,7 +96,7 @@ impl Instances { } } - pub fn draw<'rpass>(&'rpass self, render_pass: &mut wgpu::RenderPass<'rpass>) { + pub fn draw<'rpass>(&'rpass self, render_pass: &mut impl wgpu::util::RenderEncoder<'rpass>) { render_pass.set_vertex_buffer(0, self.vertex_buffer.slice(..)); // Calculate the range of instances. diff --git a/crates/graphics/src/grid/mod.rs b/crates/graphics/src/grid/mod.rs index 0dc2467a..d6be3e44 100644 --- a/crates/graphics/src/grid/mod.rs +++ b/crates/graphics/src/grid/mod.rs @@ -73,7 +73,7 @@ impl Grid { &'rpass self, graphics_state: &'rpass GraphicsState, info: &egui::PaintCallbackInfo, - render_pass: &mut wgpu::RenderPass<'rpass>, + render_pass: &mut impl wgpu::util::RenderEncoder<'rpass>, ) { #[repr(C)] #[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)] @@ -82,7 +82,6 @@ impl Grid { display: [u8; 16], } - render_pass.push_debug_group("tilemap grid renderer"); render_pass.set_pipeline(&graphics_state.pipelines.grid); if let Some(bind_group) = &self.bind_group { @@ -104,7 +103,6 @@ impl Grid { .update_viewport_size(&graphics_state.render_state, info); self.instances.draw(render_pass); - render_pass.pop_debug_group(); } } diff --git a/crates/graphics/src/plane.rs b/crates/graphics/src/plane.rs index 62d0305f..d09de445 100644 --- a/crates/graphics/src/plane.rs +++ b/crates/graphics/src/plane.rs @@ -66,7 +66,7 @@ impl Plane { pub fn draw<'rpass>( &'rpass self, graphics_state: &'rpass GraphicsState, - render_pass: &mut wgpu::RenderPass<'rpass>, + render_pass: &mut impl wgpu::util::RenderEncoder<'rpass>, ) { self.sprite.draw(graphics_state, render_pass); } diff --git a/crates/graphics/src/sprite/mod.rs b/crates/graphics/src/sprite/mod.rs index ec9097bf..88a38810 100644 --- a/crates/graphics/src/sprite/mod.rs +++ b/crates/graphics/src/sprite/mod.rs @@ -88,9 +88,8 @@ impl Sprite { pub fn draw<'rpass>( &'rpass self, graphics_state: &'rpass GraphicsState, - render_pass: &mut wgpu::RenderPass<'rpass>, + render_pass: &mut impl wgpu::util::RenderEncoder<'rpass>, ) { - render_pass.push_debug_group("sprite render"); render_pass.set_pipeline(&graphics_state.pipelines.sprites[&self.blend_mode]); render_pass.set_bind_group(0, &self.bind_group, &[]); @@ -108,7 +107,6 @@ impl Sprite { } self.vertices.draw(render_pass); - render_pass.pop_debug_group(); } } diff --git a/crates/graphics/src/sprite/vertices.rs b/crates/graphics/src/sprite/vertices.rs index 85f39592..dc430971 100644 --- a/crates/graphics/src/sprite/vertices.rs +++ b/crates/graphics/src/sprite/vertices.rs @@ -32,7 +32,7 @@ impl Vertices { Self { vertex_buffer } } - pub fn draw<'rpass>(&'rpass self, render_pass: &mut wgpu::RenderPass<'rpass>) { + pub fn draw<'rpass>(&'rpass self, render_pass: &mut impl wgpu::util::RenderEncoder<'rpass>) { render_pass.set_vertex_buffer(0, self.vertex_buffer.slice(..)); render_pass.draw(0..6, 0..1) } diff --git a/crates/graphics/src/tiles/instance.rs b/crates/graphics/src/tiles/instance.rs index 2098c9ba..cd3a9e9f 100644 --- a/crates/graphics/src/tiles/instance.rs +++ b/crates/graphics/src/tiles/instance.rs @@ -101,7 +101,11 @@ impl Instances { .collect_vec() } - pub fn draw<'rpass>(&'rpass self, render_pass: &mut wgpu::RenderPass<'rpass>, layer: usize) { + pub fn draw<'rpass>( + &'rpass self, + render_pass: &mut impl wgpu::util::RenderEncoder<'rpass>, + layer: usize, + ) { render_pass.set_vertex_buffer(0, self.vertex_buffer.slice(..)); // Calculate the start and end index of the buffer, as well as the amount of instances. diff --git a/crates/graphics/src/tiles/mod.rs b/crates/graphics/src/tiles/mod.rs index c7372c38..ed763a86 100644 --- a/crates/graphics/src/tiles/mod.rs +++ b/crates/graphics/src/tiles/mod.rs @@ -109,7 +109,7 @@ impl Tiles { graphics_state: &'rpass GraphicsState, enabled_layers: &[bool], selected_layer: Option, - render_pass: &mut wgpu::RenderPass<'rpass>, + render_pass: &mut impl wgpu::util::RenderEncoder<'rpass>, ) { #[repr(C)] #[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)] @@ -118,7 +118,6 @@ impl Tiles { autotiles: [u8; 48], } - render_pass.push_debug_group("tilemap tiles renderer"); render_pass.set_pipeline(&graphics_state.pipelines.tiles); if graphics_state.push_constants_supported() { @@ -160,7 +159,6 @@ impl Tiles { self.instances.draw(render_pass, layer); } - render_pass.pop_debug_group(); } }