1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-26 22:53:14 -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

@@ -12,4 +12,4 @@ publish = false
eframe = { path = "../../eframe", features = ["glow"] }
egui_glow = { path = "../../egui_glow" }
glow = "0.11"
three-d = { version = "0.11", default-features = false }
three-d = { version = "0.12", default-features = false }

View File

@@ -80,7 +80,7 @@ impl MyApp {
/// to the [`egui::PaintCallback`] because [`three_d::Context`] isn't `Send+Sync`, which
/// [`egui::PaintCallback`] is.
fn with_three_d_context<R>(
gl: &std::rc::Rc<glow::Context>,
gl: &std::sync::Arc<glow::Context>,
f: impl FnOnce(&three_d::Context) -> R,
) -> R {
use std::cell::RefCell;
@@ -111,15 +111,12 @@ fn paint_with_three_d(three_d: &three_d::Context, info: &egui::PaintCallbackInfo
// Respect the egui clip region (e.g. if we are inside an `egui::ScrollArea`).
let clip_rect = info.clip_rect_in_pixels();
let render_states = RenderStates {
clip: Clip::Enabled {
x: clip_rect.left_px.round() as _,
y: clip_rect.from_bottom_px.round() as _,
width: clip_rect.width_px.round() as _,
height: clip_rect.height_px.round() as _,
},
..Default::default()
};
three_d.set_scissor(ScissorBox {
x: clip_rect.left_px.round() as _,
y: clip_rect.from_bottom_px.round() as _,
width: clip_rect.width_px.round() as _,
height: clip_rect.height_px.round() as _,
});
let camera = Camera::new_perspective(
three_d,
@@ -150,11 +147,7 @@ fn paint_with_three_d(three_d: &three_d::Context, info: &egui::PaintCallbackInfo
..Default::default()
};
let material = ColorMaterial {
render_states,
..Default::default()
};
let mut model = Model::new_with_material(three_d, &cpu_mesh, material).unwrap();
let mut model = Model::new(three_d, &cpu_mesh).unwrap();
// Set the current transformation of the triangle
model.set_transformation(Mat4::from_angle_y(radians(angle)));