fix view count
This commit is contained in:
@@ -3,7 +3,7 @@ use std::{
|
|||||||
sync::mpsc::{Receiver, Sender, channel},
|
sync::mpsc::{Receiver, Sender, channel},
|
||||||
};
|
};
|
||||||
|
|
||||||
use image::DynamicImage;
|
use image::{DynamicImage, GenericImageView};
|
||||||
|
|
||||||
use crate::{render::TexturePrimitive, util::RefCounter};
|
use crate::{render::TexturePrimitive, util::RefCounter};
|
||||||
|
|
||||||
@@ -25,6 +25,7 @@ pub struct Textures {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub enum TextureUpdate<'a> {
|
pub enum TextureUpdate<'a> {
|
||||||
|
PushFree,
|
||||||
Push(&'a DynamicImage),
|
Push(&'a DynamicImage),
|
||||||
Set(u32, &'a DynamicImage),
|
Set(u32, &'a DynamicImage),
|
||||||
Free(u32),
|
Free(u32),
|
||||||
@@ -84,7 +85,10 @@ impl Textures {
|
|||||||
|
|
||||||
pub fn updates(&mut self) -> impl Iterator<Item = TextureUpdate<'_>> {
|
pub fn updates(&mut self) -> impl Iterator<Item = TextureUpdate<'_>> {
|
||||||
self.updates.drain(..).map(|u| match u {
|
self.updates.drain(..).map(|u| match u {
|
||||||
Update::Push(i) => TextureUpdate::Push(self.images[i as usize].as_ref().unwrap()),
|
Update::Push(i) => self.images[i as usize]
|
||||||
|
.as_ref()
|
||||||
|
.map(TextureUpdate::Push)
|
||||||
|
.unwrap_or(TextureUpdate::PushFree),
|
||||||
Update::Set(i) => TextureUpdate::Set(i, self.images[i as usize].as_ref().unwrap()),
|
Update::Set(i) => TextureUpdate::Set(i, self.images[i as usize].as_ref().unwrap()),
|
||||||
Update::Free(i) => TextureUpdate::Free(i),
|
Update::Free(i) => TextureUpdate::Free(i),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -137,7 +137,6 @@ impl<Ctx> Ui<Ctx> {
|
|||||||
where
|
where
|
||||||
Ctx: 'static,
|
Ctx: 'static,
|
||||||
{
|
{
|
||||||
self.free();
|
|
||||||
let mut painter = Painter::new(
|
let mut painter = Painter::new(
|
||||||
&self.widgets,
|
&self.widgets,
|
||||||
&mut self.primitives,
|
&mut self.primitives,
|
||||||
@@ -152,6 +151,7 @@ impl<Ctx> Ui<Ctx> {
|
|||||||
for id in self.updates.drain(..) {
|
for id in self.updates.drain(..) {
|
||||||
painter.redraw(&id.id);
|
painter.redraw(&id.id);
|
||||||
}
|
}
|
||||||
|
self.free();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// free any resources that don't have references anymore
|
/// free any resources that don't have references anymore
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use image::{DynamicImage, EncodableLayout};
|
use image::{DynamicImage, EncodableLayout, GenericImageView};
|
||||||
use wgpu::{util::DeviceExt, *};
|
use wgpu::{util::DeviceExt, *};
|
||||||
|
|
||||||
use crate::layout::{TextureUpdate, Textures};
|
use crate::layout::{TextureUpdate, Textures};
|
||||||
@@ -22,6 +22,7 @@ impl GpuTextures {
|
|||||||
TextureUpdate::Push(image) => self.push(image),
|
TextureUpdate::Push(image) => self.push(image),
|
||||||
TextureUpdate::Set(i, image) => self.set(i, image),
|
TextureUpdate::Set(i, image) => self.set(i, image),
|
||||||
TextureUpdate::Free(i) => self.free(i),
|
TextureUpdate::Free(i) => self.free(i),
|
||||||
|
TextureUpdate::PushFree => self.push_free(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
changed
|
changed
|
||||||
@@ -40,6 +41,10 @@ impl GpuTextures {
|
|||||||
let view = self.create_view(image);
|
let view = self.create_view(image);
|
||||||
self.views.push(view);
|
self.views.push(view);
|
||||||
}
|
}
|
||||||
|
fn push_free(&mut self) {
|
||||||
|
self.view_count += 1;
|
||||||
|
self.views.push(self.null_view.clone());
|
||||||
|
}
|
||||||
|
|
||||||
fn create_view(&self, image: &DynamicImage) -> TextureView {
|
fn create_view(&self, image: &DynamicImage) -> TextureView {
|
||||||
let image = image.to_rgba8();
|
let image = image.to_rgba8();
|
||||||
|
|||||||
Reference in New Issue
Block a user