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:
@@ -83,14 +83,9 @@ 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) =
|
||||
integration.update(gl_window.window());
|
||||
let (needs_repaint, textures_delta, shapes) = integration.update(gl_window.window());
|
||||
let clipped_meshes = integration.egui_ctx.tessellate(shapes);
|
||||
|
||||
for (id, image_delta) in textures_delta.set {
|
||||
painter.set_texture(&gl, id, &image_delta);
|
||||
}
|
||||
|
||||
// paint:
|
||||
{
|
||||
let color = integration.app.clear_color();
|
||||
@@ -100,20 +95,17 @@ pub fn run(app: Box<dyn epi::App>, native_options: &epi::NativeOptions) -> ! {
|
||||
gl.clear_color(color[0], color[1], color[2], color[3]);
|
||||
gl.clear(glow::COLOR_BUFFER_BIT);
|
||||
}
|
||||
painter.paint_meshes(
|
||||
painter.paint_and_update_textures(
|
||||
&gl,
|
||||
gl_window.window().inner_size().into(),
|
||||
integration.egui_ctx.pixels_per_point(),
|
||||
clipped_meshes,
|
||||
&textures_delta,
|
||||
);
|
||||
|
||||
gl_window.swap_buffers().unwrap();
|
||||
}
|
||||
|
||||
for id in textures_delta.free.drain(..) {
|
||||
painter.free_texture(&gl, id);
|
||||
}
|
||||
|
||||
{
|
||||
*control_flow = if integration.should_quit() {
|
||||
winit::event_loop::ControlFlow::Exit
|
||||
|
||||
@@ -270,6 +270,25 @@ impl Painter {
|
||||
(width_in_pixels, height_in_pixels)
|
||||
}
|
||||
|
||||
pub fn paint_and_update_textures(
|
||||
&mut self,
|
||||
gl: &glow::Context,
|
||||
inner_size: [u32; 2],
|
||||
pixels_per_point: f32,
|
||||
clipped_meshes: Vec<egui::ClippedMesh>,
|
||||
textures_delta: &egui::TexturesDelta,
|
||||
) {
|
||||
for (id, image_delta) in &textures_delta.set {
|
||||
self.set_texture(gl, *id, image_delta);
|
||||
}
|
||||
|
||||
self.paint_meshes(gl, inner_size, pixels_per_point, clipped_meshes);
|
||||
|
||||
for &id in &textures_delta.free {
|
||||
self.free_texture(gl, id);
|
||||
}
|
||||
}
|
||||
|
||||
/// Main entry-point for painting a frame.
|
||||
/// You should call `target.clear_color(..)` before
|
||||
/// and `target.finish()` after this.
|
||||
|
||||
Reference in New Issue
Block a user