Skip to content

armgit / gecko

Public Imported from GitHub
0

A GameCube/Wii emulator and debugger written in Rust.

fix sizing issue

Layle554dfd1e541e
diff --git a/crates/backend-wgpu/src/lib.rs b/crates/backend-wgpu/src/lib.rs
index f0ceaf0..4d00834 100644
--- a/crates/backend-wgpu/src/lib.rs
+++ b/crates/backend-wgpu/src/lib.rs
@@ -23,6 +23,8 @@ pub struct GxRenderer {
vertex_capacity: usize,
depth_texture: wgpu::Texture,
depth_view: wgpu::TextureView,
+ depth_width: u32,
+ depth_height: u32,
}
impl GxRenderer {
@@ -130,7 +132,9 @@ impl GxRenderer {
mapped_at_creation: false,
});
- let (depth_texture, depth_view) = create_depth_texture(device, width, height);
+ let depth_width = width.max(1);
+ let depth_height = height.max(1);
+ let (depth_texture, depth_view) = create_depth_texture(device, depth_width, depth_height);
GxRenderer {
pipeline,
@@ -140,13 +144,26 @@ impl GxRenderer {
vertex_capacity: initial_capacity,
depth_texture,
depth_view,
+ depth_width,
+ depth_height,
}
}
pub fn resize(&mut self, device: &wgpu::Device, width: u32, height: u32) {
+ self.ensure_depth_texture(device, width, height);
+ }
+
+ fn ensure_depth_texture(&mut self, device: &wgpu::Device, width: u32, height: u32) {
+ let width = width.max(1);
+ let height = height.max(1);
+ if (width, height) == (self.depth_width, self.depth_height) {
+ return;
+ }
let (tex, view) = create_depth_texture(device, width, height);
self.depth_texture = tex;
self.depth_view = view;
+ self.depth_width = width;
+ self.depth_height = height;
}
pub fn render(
@@ -155,7 +172,11 @@ impl GxRenderer {
queue: &wgpu::Queue,
commands: &DrawCommands,
target: &wgpu::TextureView,
+ target_width: u32,
+ target_height: u32,
) {
+ self.ensure_depth_texture(device, target_width, target_height);
+
let mvp = commands.projection * commands.modelview;
queue.write_buffer(&self.uniform_buffer, 0, bytemuck::bytes_of(&Uniforms { mvp: mvp.0 }));
diff --git a/crates/tinyapp/src/main.rs b/crates/tinyapp/src/main.rs
index ebb5d54..865d52e 100644
--- a/crates/tinyapp/src/main.rs
+++ b/crates/tinyapp/src/main.rs
@@ -128,7 +128,12 @@ impl State {
});
let (texture, bind_group) = create_xfb_texture(&device, &bind_group_layout, w, h);
- let gx_renderer = backend_wgpu::GxRenderer::new(&device, surface_format, w, h);
+ let gx_renderer = backend_wgpu::GxRenderer::new(
+ &device,
+ surface_format,
+ surface_config.width,
+ surface_config.height,
+ );
State {
surface,
@@ -177,8 +182,14 @@ impl State {
}
fn render_gx(&mut self, emulator: &mut Gekko, view: &wgpu::TextureView) {
- self.gx_renderer
- .render(&self.device, &self.queue, &emulator.gx.draw_commands, view);
+ self.gx_renderer.render(
+ &self.device,
+ &self.queue,
+ &emulator.gx.draw_commands,
+ view,
+ self.surface_config.width,
+ self.surface_config.height,
+ );
emulator.gx.draw_commands.commands.clear();
}