Make glow Send + Sync again. (#3646)

* Reverts #3598
* Closes #3645
This commit is contained in:
Sebastian Urban 2023-12-04 15:58:05 +01:00 committed by GitHub
parent 84a6d6f2ab
commit 36c6b6304d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 14 additions and 13 deletions

View File

@ -64,7 +64,7 @@ pub struct CreationContext<'s> {
///
/// Only available when compiling with the `glow` feature and using [`Renderer::Glow`].
#[cfg(feature = "glow")]
pub gl: Option<std::rc::Rc<glow::Context>>,
pub gl: Option<std::sync::Arc<glow::Context>>,
/// The underlying WGPU render state.
///
@ -584,7 +584,7 @@ pub struct Frame {
/// A reference to the underlying [`glow`] (OpenGL) context.
#[cfg(feature = "glow")]
pub(crate) gl: Option<std::rc::Rc<glow::Context>>,
pub(crate) gl: Option<std::sync::Arc<glow::Context>>,
/// Can be used to manage GPU resources for custom rendering with WGPU using [`egui::PaintCallback`]s.
#[cfg(feature = "wgpu")]
@ -656,7 +656,7 @@ impl Frame {
/// To get a [`glow`] context you need to compile with the `glow` feature flag,
/// and run eframe using [`Renderer::Glow`].
#[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

@ -152,7 +152,7 @@ impl EpiIntegration {
app_name: &str,
native_options: &crate::NativeOptions,
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>>,
#[cfg(feature = "wgpu")] wgpu_render_state: Option<egui_wgpu::RenderState>,
) -> Self {
let frame = epi::Frame {

View File

@ -170,7 +170,7 @@ impl GlowWinitApp {
let gl = unsafe {
crate::profile_scope!("glow::Context::from_loader_function");
Rc::new(glow::Context::from_loader_function(|s| {
Arc::new(glow::Context::from_loader_function(|s| {
let s = std::ffi::CString::new(s)
.expect("failed to construct C string from string for gl proc address");

View File

@ -15,7 +15,7 @@ pub(crate) struct WebPainterGlow {
}
impl WebPainterGlow {
pub fn gl(&self) -> &std::rc::Rc<glow::Context> {
pub fn gl(&self) -> &std::sync::Arc<glow::Context> {
self.painter.gl()
}
@ -24,7 +24,8 @@ impl WebPainterGlow {
let (gl, shader_prefix) =
init_glow_context_from_canvas(&canvas, options.webgl_context_option)?;
let gl = std::rc::Rc::new(gl);
#[allow(clippy::arc_with_non_send_sync)]
let gl = std::sync::Arc::new(gl);
let painter = egui_glow::Painter::new(gl, shader_prefix, None)
.map_err(|err| format!("Error starting glow painter: {err}"))?;

View File

@ -152,7 +152,7 @@ fn main() {
let event_loop = winit::event_loop::EventLoopBuilder::<UserEvent>::with_user_event().build();
let (gl_window, gl) = create_display(&event_loop);
let gl = std::rc::Rc::new(gl);
let gl = std::sync::Arc::new(gl);
let mut egui_glow = egui_glow::EguiGlow::new(&event_loop, gl.clone(), None, None);

View File

@ -1,7 +1,7 @@
#![allow(clippy::collapsible_else_if)]
#![allow(unsafe_code)]
use std::{collections::HashMap, rc::Rc};
use std::{collections::HashMap, sync::Arc};
use egui::{
emath::Rect,
@ -62,7 +62,7 @@ impl From<String> for PainterError {
///
/// NOTE: all egui viewports share the same painter.
pub struct Painter {
gl: Rc<glow::Context>,
gl: Arc<glow::Context>,
max_texture_side: usize,
@ -120,7 +120,7 @@ impl Painter {
/// * failed to create postprocess on webgl with `sRGB` support
/// * failed to create buffer
pub fn new(
gl: Rc<glow::Context>,
gl: Arc<glow::Context>,
shader_prefix: &str,
shader_version: Option<ShaderVersion>,
) -> Result<Painter, PainterError> {
@ -250,7 +250,7 @@ impl Painter {
}
/// Access the shared glow context.
pub fn gl(&self) -> &Rc<glow::Context> {
pub fn gl(&self) -> &Arc<glow::Context> {
&self.gl
}

View File

@ -24,7 +24,7 @@ impl EguiGlow {
/// For automatic shader version detection set `shader_version` to `None`.
pub fn new<E>(
event_loop: &winit::event_loop::EventLoopWindowTarget<E>,
gl: std::rc::Rc<glow::Context>,
gl: std::sync::Arc<glow::Context>,
shader_version: Option<ShaderVersion>,
native_pixels_per_point: Option<f32>,
) -> Self {