mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 06:10:06 -04:00
Simplify backends by adding fn paint_and_update_textures helper
This commit is contained in:
@@ -67,14 +67,10 @@ pub fn run(app: Box<dyn epi::App>, native_options: &epi::NativeOptions) -> ! {
|
||||
std::thread::sleep(std::time::Duration::from_millis(10));
|
||||
}
|
||||
|
||||
let (needs_repaint, mut textures_delta, shapes) =
|
||||
let (needs_repaint, textures_delta, shapes) =
|
||||
integration.update(display.gl_window().window());
|
||||
let clipped_meshes = integration.egui_ctx.tessellate(shapes);
|
||||
|
||||
for (id, image_delta) in textures_delta.set {
|
||||
painter.set_texture(&display, id, &image_delta);
|
||||
}
|
||||
|
||||
// paint:
|
||||
{
|
||||
use glium::Surface as _;
|
||||
@@ -82,20 +78,17 @@ pub fn run(app: Box<dyn epi::App>, native_options: &epi::NativeOptions) -> ! {
|
||||
let color = integration.app.clear_color();
|
||||
target.clear_color(color[0], color[1], color[2], color[3]);
|
||||
|
||||
painter.paint_meshes(
|
||||
painter.paint_and_update_textures(
|
||||
&display,
|
||||
&mut target,
|
||||
integration.egui_ctx.pixels_per_point(),
|
||||
clipped_meshes,
|
||||
&textures_delta,
|
||||
);
|
||||
|
||||
target.finish().unwrap();
|
||||
}
|
||||
|
||||
for id in textures_delta.free.drain(..) {
|
||||
painter.free_texture(id);
|
||||
}
|
||||
|
||||
{
|
||||
*control_flow = if integration.should_quit() {
|
||||
glutin::event_loop::ControlFlow::Exit
|
||||
|
||||
@@ -157,22 +157,14 @@ impl EguiGlium {
|
||||
/// Paint the results of the last call to [`Self::run`].
|
||||
pub fn paint<T: glium::Surface>(&mut self, display: &glium::Display, target: &mut T) {
|
||||
let shapes = std::mem::take(&mut self.shapes);
|
||||
let mut textures_delta = std::mem::take(&mut self.textures_delta);
|
||||
|
||||
for (id, image_delta) in textures_delta.set {
|
||||
self.painter.set_texture(display, id, &image_delta);
|
||||
}
|
||||
|
||||
let textures_delta = std::mem::take(&mut self.textures_delta);
|
||||
let clipped_meshes = self.egui_ctx.tessellate(shapes);
|
||||
self.painter.paint_meshes(
|
||||
self.painter.paint_and_update_textures(
|
||||
display,
|
||||
target,
|
||||
self.egui_ctx.pixels_per_point(),
|
||||
clipped_meshes,
|
||||
&textures_delta,
|
||||
);
|
||||
|
||||
for id in textures_delta.free.drain(..) {
|
||||
self.painter.free_texture(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,6 +65,25 @@ impl Painter {
|
||||
self.max_texture_side
|
||||
}
|
||||
|
||||
pub fn paint_and_update_textures<T: glium::Surface>(
|
||||
&mut self,
|
||||
display: &glium::Display,
|
||||
target: &mut T,
|
||||
pixels_per_point: f32,
|
||||
clipped_meshes: Vec<egui::ClippedMesh>,
|
||||
textures_delta: &egui::TexturesDelta,
|
||||
) {
|
||||
for (id, image_delta) in &textures_delta.set {
|
||||
self.set_texture(display, *id, image_delta);
|
||||
}
|
||||
|
||||
self.paint_meshes(display, target, pixels_per_point, clipped_meshes);
|
||||
|
||||
for &id in &textures_delta.free {
|
||||
self.free_texture(id);
|
||||
}
|
||||
}
|
||||
|
||||
/// Main entry-point for painting a frame.
|
||||
/// You should call `target.clear_color(..)` before
|
||||
/// and `target.finish()` after this.
|
||||
@@ -73,9 +92,9 @@ impl Painter {
|
||||
display: &glium::Display,
|
||||
target: &mut T,
|
||||
pixels_per_point: f32,
|
||||
cipped_meshes: Vec<egui::ClippedMesh>,
|
||||
clipped_meshes: Vec<egui::ClippedMesh>,
|
||||
) {
|
||||
for egui::ClippedMesh(clip_rect, mesh) in cipped_meshes {
|
||||
for egui::ClippedMesh(clip_rect, mesh) in clipped_meshes {
|
||||
self.paint_mesh(target, display, pixels_per_point, clip_rect, &mesh);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user