Repaint screen less often

This commit is contained in:
2026-11-01 21:17:37 -05:00
parent 6e08830b43
commit 833214b759
5 changed files with 26 additions and 14 deletions
+16 -1
View File
@@ -5,14 +5,19 @@ use std::{
mpsc,
},
thread,
time::Instant,
};
use anyhow::{Result, bail};
use egui::ViewportId;
use itertools::Itertools as _;
use wgpu::{
Device, Extent3d, Origin3d, Queue, TexelCopyBufferLayout, TexelCopyTextureInfo, Texture,
TextureDescriptor, TextureFormat, TextureUsages, TextureView, TextureViewDescriptor,
};
use winit::event_loop::EventLoopProxy;
use crate::app::UserEvent;
#[derive(Debug)]
pub struct TextureSink {
@@ -21,7 +26,11 @@ pub struct TextureSink {
}
impl TextureSink {
pub fn new(device: &Device, queue: Queue) -> (Self, TextureView) {
pub fn new(
device: &Device,
queue: Queue,
proxy: EventLoopProxy<UserEvent>,
) -> (Self, TextureView) {
let texture = Self::create_texture(device);
let view = texture.create_view(&TextureViewDescriptor::default());
let buffers = Arc::new(BufferPool::new());
@@ -37,6 +46,12 @@ impl TextureSink {
local_buf.copy_from_slice(bytes.as_slice());
}
Self::write_texture(&queue, &texture, local_buf.as_slice());
if proxy
.send_event(UserEvent::RequestRedraw(ViewportId::ROOT, Instant::now()))
.is_err()
{
break;
}
}
});
let sink = Self { buffers, sink };