From 4504ad272e0adc398290a231b936c1437aad1493 Mon Sep 17 00:00:00 2001 From: Vivek Bagaria Date: Tue, 28 Nov 2023 20:07:24 -0800 Subject: [PATCH] Updating egui and egui_glow to 0.24 1. Used Rc instead of Arc in Context to make it compatible with egui https://github.com/emilk/egui/pull/3598 --- Cargo.toml | 6 +++--- src/core/context.rs | 7 ++++--- src/gui/egui_gui.rs | 11 ++++++----- src/window/winit_window/windowed_context.rs | 4 ++-- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5008704cc..fc500cba5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,8 +28,8 @@ cgmath = "0.18" three-d-asset = {version = "0.6"} thiserror = "1" winit = {version = "0.28", optional = true} -egui = { version = "0.22", optional = true } -egui_glow = { version = "0.22", optional = true } +egui = { version = "0.24", optional = true } +egui_glow = { version = "0.24", optional = true } getrandom = { version = "0.2", features = ["js"], optional = true } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] @@ -188,4 +188,4 @@ required-features = ["headless"] [[example]] name = "logo" -path = "examples/logo/src/main.rs" \ No newline at end of file +path = "examples/logo/src/main.rs" diff --git a/src/core/context.rs b/src/core/context.rs index 6e397bb7d..953b96b36 100644 --- a/src/core/context.rs +++ b/src/core/context.rs @@ -1,5 +1,6 @@ use super::*; use std::collections::HashMap; +use std::rc::Rc; use std::sync::Arc; use std::sync::RwLock; @@ -13,7 +14,7 @@ pub use crate::context::HasContext; /// #[derive(Clone)] pub struct Context { - context: Arc, + context: Rc, pub(super) vao: crate::context::VertexArray, /// A cache of programs to avoid recompiling a [Program] every frame. pub programs: Arc, Program>>>, @@ -26,7 +27,7 @@ impl Context { /// Since the content in the [context](crate::context) module is just a re-export of [glow](https://crates.io/crates/glow), /// you can also call this method with a reference counter to a glow context created using glow and not the re-export in [context](crate::context). /// - pub fn from_gl_context(context: Arc) -> Result { + pub fn from_gl_context(context: Rc) -> Result { unsafe { if !context.version().is_embedded { // Enable seamless cube map textures - not available on OpenGL ES and WebGL @@ -304,7 +305,7 @@ impl std::fmt::Debug for Context { } impl std::ops::Deref for Context { - type Target = Arc; + type Target = Rc; fn deref(&self) -> &Self::Target { &self.context } diff --git a/src/gui/egui_gui.rs b/src/gui/egui_gui.rs index 86e050497..c24fde05d 100644 --- a/src/gui/egui_gui.rs +++ b/src/gui/egui_gui.rs @@ -29,7 +29,7 @@ impl GUI { /// /// Creates a new GUI from a low-level graphics [Context](crate::context::Context). /// - pub fn from_gl_context(context: std::sync::Arc) -> Self { + pub fn from_gl_context(context: std::rc::Rc) -> Self { GUI { egui_context: egui::Context::default(), painter: RefCell::new(Painter::new(context, "", None).unwrap()), @@ -66,7 +66,6 @@ impl GUI { + viewport.height as f32 / device_pixel_ratio as f32, }, }), - pixels_per_point: Some(device_pixel_ratio as f32), time: Some(accumulated_time_in_ms * 0.001), modifiers: (&self.modifiers).into(), events: events @@ -245,11 +244,13 @@ impl GUI { .borrow_mut() .take() .expect("need to call GUI::update before GUI::render"); - let clipped_meshes = self.egui_context.tessellate(output.shapes); - let scale = self.egui_context.pixels_per_point(); + let pixels_per_point = self.egui_context.pixels_per_point(); + let clipped_meshes = self + .egui_context + .tessellate(output.shapes, pixels_per_point); self.painter.borrow_mut().paint_and_update_textures( [self.viewport.width, self.viewport.height], - scale, + pixels_per_point, &clipped_meshes, &output.textures_delta, ); diff --git a/src/window/winit_window/windowed_context.rs b/src/window/winit_window/windowed_context.rs index 9e0987ce1..2eda5290f 100644 --- a/src/window/winit_window/windowed_context.rs +++ b/src/window/winit_window/windowed_context.rs @@ -1,7 +1,7 @@ use crate::Context; use crate::SurfaceSettings; use crate::WindowError; -use std::sync::Arc; +use std::rc::Rc; use winit::window::Window; #[cfg(target_arch = "wasm32")] @@ -193,7 +193,7 @@ mod inner { gl_surface.set_swap_interval(&gl_context, swap_interval)?; Ok(Self { - context: Context::from_gl_context(Arc::new(unsafe { + context: Context::from_gl_context(Rc::new(unsafe { crate::context::Context::from_loader_function(|s| { let s = std::ffi::CString::new(s) .expect("failed to construct C string from string for gl proc address");