1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 05:10:03 -04:00

Take Glow context using Arc. (#1640)

This allows usage with a Glow context that is passed between threads.
This commit is contained in:
Sebastian Urban
2022-05-22 17:43:30 +02:00
committed by GitHub
parent a29154233b
commit b2510676b9
11 changed files with 27 additions and 31 deletions

View File

@@ -28,7 +28,7 @@ pub struct CreationContext<'s> {
/// The [`glow::Context`] allows you to initialize OpenGL resources (e.g. shaders) that
/// you might want to use later from a [`egui::PaintCallback`].
#[cfg(feature = "glow")]
pub gl: Option<std::rc::Rc<glow::Context>>,
pub gl: Option<std::sync::Arc<glow::Context>>,
}
// ----------------------------------------------------------------------------
@@ -334,7 +334,7 @@ pub struct Frame {
/// A reference to the underlying [`glow`] (OpenGL) context.
#[cfg(feature = "glow")]
#[doc(hidden)]
pub gl: Option<std::rc::Rc<glow::Context>>,
pub gl: Option<std::sync::Arc<glow::Context>>,
}
impl Frame {
@@ -371,7 +371,7 @@ impl Frame {
/// To get a [`glow`] context you need to compile with the `glow` feature flag,
/// and run eframe with the glow backend.
#[cfg(feature = "glow")]
pub fn gl(&self) -> Option<&std::rc::Rc<glow::Context>> {
pub fn gl(&self) -> Option<&std::sync::Arc<glow::Context>> {
self.gl.as_ref()
}

View File

@@ -185,7 +185,7 @@ impl EpiIntegration {
max_texture_side: usize,
window: &winit::window::Window,
storage: Option<Box<dyn epi::Storage>>,
#[cfg(feature = "glow")] gl: Option<std::rc::Rc<glow::Context>>,
#[cfg(feature = "glow")] gl: Option<std::sync::Arc<glow::Context>>,
) -> Self {
let egui_ctx = egui::Context::default();

View File

@@ -51,7 +51,7 @@ pub fn run_glow(
let window_builder =
epi_integration::window_builder(native_options, &window_settings).with_title(app_name);
let (gl_window, gl) = create_display(native_options, window_builder, &event_loop);
let gl = std::rc::Rc::new(gl);
let gl = std::sync::Arc::new(gl);
let mut painter = egui_glow::Painter::new(gl.clone(), None, "")
.unwrap_or_else(|error| panic!("some OpenGL error occurred {}\n", error));

View File

@@ -17,7 +17,7 @@ impl WrappedGlowPainter {
let canvas = super::canvas_element_or_die(canvas_id);
let (gl, shader_prefix) = init_glow_context_from_canvas(&canvas)?;
let gl = std::rc::Rc::new(gl);
let gl = std::sync::Arc::new(gl);
let dimension = [canvas.width() as i32, canvas.height() as i32];
let painter = egui_glow::Painter::new(gl, Some(dimension), shader_prefix)
@@ -32,7 +32,7 @@ impl WrappedGlowPainter {
}
impl WrappedGlowPainter {
pub fn gl(&self) -> &std::rc::Rc<glow::Context> {
pub fn gl(&self) -> &std::sync::Arc<glow::Context> {
self.painter.gl()
}