From af821c9e49f107b9d3fcaf0f2393364f3abf7ba1 Mon Sep 17 00:00:00 2001 From: Jay Oster Date: Mon, 13 Jun 2022 21:03:06 -0700 Subject: [PATCH] Update egui to 0.18 (#281) * Update egui to 0.18 - Closes #278 * Bump MSRV to 1.60.0 for egui --- .github/workflows/ci.yml | 4 ++-- MSRV.md | 1 + examples/minimal-egui/Cargo.toml | 6 +++--- examples/minimal-egui/src/gui.rs | 30 ++++++++++++++++-------------- examples/minimal-egui/src/main.rs | 2 +- 5 files changed, 23 insertions(+), 20 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d669a2b8..85a8649e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ jobs: rust: - stable - beta - - 1.57.0 + - 1.60.0 steps: - name: Checkout sources uses: actions/checkout@v2 @@ -73,7 +73,7 @@ jobs: rust: - stable - beta - - 1.57.0 + - 1.60.0 steps: - name: Checkout sources uses: actions/checkout@v2 diff --git a/MSRV.md b/MSRV.md index c21e3a67..e1e73791 100644 --- a/MSRV.md +++ b/MSRV.md @@ -2,6 +2,7 @@ | `pixels` version | `rustc` version | |------------------|-----------------| +| `0.10.0` | `1.60.0` | | `0.9.0` | `1.57.0` | | `0.8.0` | `1.52.0` | | `0.7.0` | `1.52.0` | diff --git a/examples/minimal-egui/Cargo.toml b/examples/minimal-egui/Cargo.toml index b4b7e45d..39c8fe68 100644 --- a/examples/minimal-egui/Cargo.toml +++ b/examples/minimal-egui/Cargo.toml @@ -10,9 +10,9 @@ optimize = ["log/release_max_level_warn"] default = ["optimize"] [dependencies] -egui = "0.17" -egui_wgpu_backend = "0.17" -egui-winit = { version = "0.17", default-features = false, features = ["links"] } +egui = "0.18" +egui-wgpu = "0.18" +egui-winit = { version = "0.18", default-features = false, features = ["links"] } env_logger = "0.9" log = "0.4" pixels = { path = "../.." } diff --git a/examples/minimal-egui/src/gui.rs b/examples/minimal-egui/src/gui.rs index 815920cd..b10e59c6 100644 --- a/examples/minimal-egui/src/gui.rs +++ b/examples/minimal-egui/src/gui.rs @@ -1,5 +1,5 @@ -use egui::{ClippedMesh, Context, TexturesDelta}; -use egui_wgpu_backend::{BackendError, RenderPass, ScreenDescriptor}; +use egui::{ClippedPrimitive, Context, TexturesDelta}; +use egui_wgpu::renderer::{RenderPass, ScreenDescriptor}; use pixels::{wgpu, PixelsContext}; use winit::window::Window; @@ -10,7 +10,7 @@ pub(crate) struct Framework { egui_state: egui_winit::State, screen_descriptor: ScreenDescriptor, rpass: RenderPass, - paint_jobs: Vec, + paint_jobs: Vec, textures: TexturesDelta, // State for the GUI @@ -31,9 +31,8 @@ impl Framework { let egui_ctx = Context::default(); let egui_state = egui_winit::State::from_pixels_per_point(max_texture_size, scale_factor); let screen_descriptor = ScreenDescriptor { - physical_width: width, - physical_height: height, - scale_factor, + size_in_pixels: [width, height], + pixels_per_point: scale_factor, }; let rpass = RenderPass::new(pixels.device(), pixels.render_texture_format(), 1); let textures = TexturesDelta::default(); @@ -58,14 +57,13 @@ impl Framework { /// Resize egui. pub(crate) fn resize(&mut self, width: u32, height: u32) { if width > 0 && height > 0 { - self.screen_descriptor.physical_width = width; - self.screen_descriptor.physical_height = height; + self.screen_descriptor.size_in_pixels = [width, height]; } } /// Update scaling factor. pub(crate) fn scale_factor(&mut self, scale_factor: f64) { - self.screen_descriptor.scale_factor = scale_factor as f32; + self.screen_descriptor.pixels_per_point = scale_factor as f32; } /// Prepare egui. @@ -89,10 +87,12 @@ impl Framework { encoder: &mut wgpu::CommandEncoder, render_target: &wgpu::TextureView, context: &PixelsContext, - ) -> Result<(), BackendError> { + ) { // Upload all resources to the GPU. - self.rpass - .add_textures(&context.device, &context.queue, &self.textures)?; + for (id, image_delta) in &self.textures.set { + self.rpass + .update_texture(&context.device, &context.queue, *id, image_delta); + } self.rpass.update_buffers( &context.device, &context.queue, @@ -107,11 +107,13 @@ impl Framework { &self.paint_jobs, &self.screen_descriptor, None, - )?; + ); // Cleanup let textures = std::mem::take(&mut self.textures); - self.rpass.remove_textures(textures) + for id in &textures.free { + self.rpass.free_texture(id); + } } } diff --git a/examples/minimal-egui/src/main.rs b/examples/minimal-egui/src/main.rs index 9086b09d..3bba776e 100644 --- a/examples/minimal-egui/src/main.rs +++ b/examples/minimal-egui/src/main.rs @@ -94,7 +94,7 @@ fn main() -> Result<(), Error> { context.scaling_renderer.render(encoder, render_target); // Render egui - framework.render(encoder, render_target, context)?; + framework.render(encoder, render_target, context); Ok(()) });