This commit is contained in:
Alex Janka 2023-09-28 17:31:54 +10:00
parent a39b31dc33
commit 92dc4e3885
2 changed files with 13 additions and 5 deletions

View file

@ -18,6 +18,16 @@ impl WindowData {
pub fn resize(&mut self, width: u32, height: u32, factor: u32, window: &Window) {
self.pixels = new_pixels(width, height, factor, window);
}
pub fn new_frame(&mut self, buffer: &[[u8; 4]]) {
self.pixels
.frame_mut()
.copy_from_slice(bytemuck::cast_slice(buffer));
}
pub fn render(&mut self) {
self.pixels.render().unwrap();
}
}
fn new_pixels(width: u32, height: u32, scaling: u32, window: &Window) -> Pixels {

View file

@ -75,8 +75,8 @@ impl WindowManager {
}
Event::RedrawRequested(window_id) => {
if let Some(w) = self.windows.get(&window_id) {
if let Ok(data) = w.lock() {
data.pixels.render().unwrap();
if let Ok(mut data) = w.lock() {
data.render();
}
}
}
@ -162,9 +162,7 @@ impl Renderer<[u8; 4]> for WindowRenderer {
fn display(&mut self, buffer: &[[u8; 4]]) {
if let Ok(mut data) = self.data.lock() {
data.pixels
.frame_mut()
.copy_from_slice(bytemuck::cast_slice(buffer));
data.new_frame(buffer);
}
self.window.request_redraw();
}