Repaint screen less often
This commit is contained in:
+16
-1
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user