Skip to content

Commit

Permalink
refactor(tilemap): ♻️ Take a &mut impl RenderEncoder instead of Rende…
Browse files Browse the repository at this point in the history
…rPass
  • Loading branch information
melody-rs committed Feb 12, 2024
1 parent cbb14b8 commit 2ca3f35
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion crates/graphics/src/collision/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 1 addition & 3 deletions crates/graphics/src/collision/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -199,7 +198,6 @@ impl Collision {
}

self.instances.draw(render_pass);
render_pass.pop_debug_group();
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/graphics/src/grid/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 1 addition & 3 deletions crates/graphics/src/grid/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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 {
Expand All @@ -104,7 +103,6 @@ impl Grid {
.update_viewport_size(&graphics_state.render_state, info);

self.instances.draw(render_pass);
render_pass.pop_debug_group();
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/graphics/src/plane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 1 addition & 3 deletions crates/graphics/src/sprite/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, &[]);

Expand All @@ -108,7 +107,6 @@ impl Sprite {
}

self.vertices.draw(render_pass);
render_pass.pop_debug_group();
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/graphics/src/sprite/vertices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
6 changes: 5 additions & 1 deletion crates/graphics/src/tiles/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 1 addition & 3 deletions crates/graphics/src/tiles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl Tiles {
graphics_state: &'rpass GraphicsState,
enabled_layers: &[bool],
selected_layer: Option<usize>,
render_pass: &mut wgpu::RenderPass<'rpass>,
render_pass: &mut impl wgpu::util::RenderEncoder<'rpass>,
) {
#[repr(C)]
#[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)]
Expand All @@ -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() {
Expand Down Expand Up @@ -160,7 +159,6 @@ impl Tiles {

self.instances.draw(render_pass, layer);
}
render_pass.pop_debug_group();
}
}

Expand Down

0 comments on commit 2ca3f35

Please sign in to comment.