Update egui to 0.18 (#281)

* Update egui to 0.18

- Closes #278

* Bump MSRV to 1.60.0 for egui
This commit is contained in:
Jay Oster 2022-06-13 21:03:06 -07:00 committed by GitHub
parent adaa469ad9
commit af821c9e49
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 20 deletions

View file

@ -13,7 +13,7 @@ jobs:
rust: rust:
- stable - stable
- beta - beta
- 1.57.0 - 1.60.0
steps: steps:
- name: Checkout sources - name: Checkout sources
uses: actions/checkout@v2 uses: actions/checkout@v2
@ -73,7 +73,7 @@ jobs:
rust: rust:
- stable - stable
- beta - beta
- 1.57.0 - 1.60.0
steps: steps:
- name: Checkout sources - name: Checkout sources
uses: actions/checkout@v2 uses: actions/checkout@v2

View file

@ -2,6 +2,7 @@
| `pixels` version | `rustc` version | | `pixels` version | `rustc` version |
|------------------|-----------------| |------------------|-----------------|
| `0.10.0` | `1.60.0` |
| `0.9.0` | `1.57.0` | | `0.9.0` | `1.57.0` |
| `0.8.0` | `1.52.0` | | `0.8.0` | `1.52.0` |
| `0.7.0` | `1.52.0` | | `0.7.0` | `1.52.0` |

View file

@ -10,9 +10,9 @@ optimize = ["log/release_max_level_warn"]
default = ["optimize"] default = ["optimize"]
[dependencies] [dependencies]
egui = "0.17" egui = "0.18"
egui_wgpu_backend = "0.17" egui-wgpu = "0.18"
egui-winit = { version = "0.17", default-features = false, features = ["links"] } egui-winit = { version = "0.18", default-features = false, features = ["links"] }
env_logger = "0.9" env_logger = "0.9"
log = "0.4" log = "0.4"
pixels = { path = "../.." } pixels = { path = "../.." }

View file

@ -1,5 +1,5 @@
use egui::{ClippedMesh, Context, TexturesDelta}; use egui::{ClippedPrimitive, Context, TexturesDelta};
use egui_wgpu_backend::{BackendError, RenderPass, ScreenDescriptor}; use egui_wgpu::renderer::{RenderPass, ScreenDescriptor};
use pixels::{wgpu, PixelsContext}; use pixels::{wgpu, PixelsContext};
use winit::window::Window; use winit::window::Window;
@ -10,7 +10,7 @@ pub(crate) struct Framework {
egui_state: egui_winit::State, egui_state: egui_winit::State,
screen_descriptor: ScreenDescriptor, screen_descriptor: ScreenDescriptor,
rpass: RenderPass, rpass: RenderPass,
paint_jobs: Vec<ClippedMesh>, paint_jobs: Vec<ClippedPrimitive>,
textures: TexturesDelta, textures: TexturesDelta,
// State for the GUI // State for the GUI
@ -31,9 +31,8 @@ impl Framework {
let egui_ctx = Context::default(); let egui_ctx = Context::default();
let egui_state = egui_winit::State::from_pixels_per_point(max_texture_size, scale_factor); let egui_state = egui_winit::State::from_pixels_per_point(max_texture_size, scale_factor);
let screen_descriptor = ScreenDescriptor { let screen_descriptor = ScreenDescriptor {
physical_width: width, size_in_pixels: [width, height],
physical_height: height, pixels_per_point: scale_factor,
scale_factor,
}; };
let rpass = RenderPass::new(pixels.device(), pixels.render_texture_format(), 1); let rpass = RenderPass::new(pixels.device(), pixels.render_texture_format(), 1);
let textures = TexturesDelta::default(); let textures = TexturesDelta::default();
@ -58,14 +57,13 @@ impl Framework {
/// Resize egui. /// Resize egui.
pub(crate) fn resize(&mut self, width: u32, height: u32) { pub(crate) fn resize(&mut self, width: u32, height: u32) {
if width > 0 && height > 0 { if width > 0 && height > 0 {
self.screen_descriptor.physical_width = width; self.screen_descriptor.size_in_pixels = [width, height];
self.screen_descriptor.physical_height = height;
} }
} }
/// Update scaling factor. /// Update scaling factor.
pub(crate) fn scale_factor(&mut self, scale_factor: f64) { 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. /// Prepare egui.
@ -89,10 +87,12 @@ impl Framework {
encoder: &mut wgpu::CommandEncoder, encoder: &mut wgpu::CommandEncoder,
render_target: &wgpu::TextureView, render_target: &wgpu::TextureView,
context: &PixelsContext, context: &PixelsContext,
) -> Result<(), BackendError> { ) {
// Upload all resources to the GPU. // Upload all resources to the GPU.
for (id, image_delta) in &self.textures.set {
self.rpass self.rpass
.add_textures(&context.device, &context.queue, &self.textures)?; .update_texture(&context.device, &context.queue, *id, image_delta);
}
self.rpass.update_buffers( self.rpass.update_buffers(
&context.device, &context.device,
&context.queue, &context.queue,
@ -107,11 +107,13 @@ impl Framework {
&self.paint_jobs, &self.paint_jobs,
&self.screen_descriptor, &self.screen_descriptor,
None, None,
)?; );
// Cleanup // Cleanup
let textures = std::mem::take(&mut self.textures); let textures = std::mem::take(&mut self.textures);
self.rpass.remove_textures(textures) for id in &textures.free {
self.rpass.free_texture(id);
}
} }
} }

View file

@ -94,7 +94,7 @@ fn main() -> Result<(), Error> {
context.scaling_renderer.render(encoder, render_target); context.scaling_renderer.render(encoder, render_target);
// Render egui // Render egui
framework.render(encoder, render_target, context)?; framework.render(encoder, render_target, context);
Ok(()) Ok(())
}); });