1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-29 04:40:03 -04:00

Partial font texture update (#1149)

This commit is contained in:
Emil Ernerfeldt
2022-01-22 11:23:12 +01:00
committed by GitHub
parent 343f7da564
commit 462f181db3
24 changed files with 393 additions and 255 deletions

View File

@@ -70,8 +70,8 @@ pub fn run(app: Box<dyn epi::App>, native_options: &epi::NativeOptions) -> ! {
integration.update(display.gl_window().window());
let clipped_meshes = integration.egui_ctx.tessellate(shapes);
for (id, image) in textures_delta.set {
painter.set_texture(&display, id, &image);
for (id, image_delta) in textures_delta.set {
painter.set_texture(&display, id, &image_delta);
}
// paint:

View File

@@ -155,8 +155,8 @@ impl EguiGlium {
let shapes = std::mem::take(&mut self.shapes);
let mut textures_delta = std::mem::take(&mut self.textures_delta);
for (id, image) in textures_delta.set {
self.painter.set_texture(display, id, &image);
for (id, image_delta) in textures_delta.set {
self.painter.set_texture(display, id, &image_delta);
}
let clipped_meshes = self.egui_ctx.tessellate(shapes);

View File

@@ -185,9 +185,9 @@ impl Painter {
&mut self,
facade: &dyn glium::backend::Facade,
tex_id: egui::TextureId,
image: &egui::ImageData,
delta: &egui::epaint::ImageDelta,
) {
let pixels: Vec<(u8, u8, u8, u8)> = match image {
let pixels: Vec<(u8, u8, u8, u8)> = match &delta.image {
egui::ImageData::Color(image) => {
assert_eq!(
image.width() * image.height(),
@@ -206,15 +206,29 @@ impl Painter {
};
let glium_image = glium::texture::RawImage2d {
data: std::borrow::Cow::Owned(pixels),
width: image.width() as _,
height: image.height() as _,
width: delta.image.width() as _,
height: delta.image.height() as _,
format: glium::texture::ClientFormat::U8U8U8U8,
};
let format = texture::SrgbFormat::U8U8U8U8;
let mipmaps = texture::MipmapsOption::NoMipmap;
let gl_texture = SrgbTexture2d::with_format(facade, glium_image, format, mipmaps).unwrap();
self.textures.insert(tex_id, gl_texture.into());
if let Some(pos) = delta.pos {
// update a sub-region
if let Some(gl_texture) = self.textures.get(&tex_id) {
let rect = glium::Rect {
left: pos[0] as _,
bottom: pos[1] as _,
width: glium_image.width,
height: glium_image.height,
};
gl_texture.main_level().write(rect, glium_image);
}
} else {
let gl_texture =
SrgbTexture2d::with_format(facade, glium_image, format, mipmaps).unwrap();
self.textures.insert(tex_id, gl_texture.into());
}
}
pub fn free_texture(&mut self, tex_id: egui::TextureId) {