mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 22:30:03 -04:00
Add Shape::Callback to do custom rendering inside of an egui UI (#1351)
* Add Shape::Callback to do custom rendering inside of an egui UI * Use Rc<glow::Context> everywhere * Remove trait WebPainter * Add glow::Context to epi::App::setup
This commit is contained in:
@@ -54,17 +54,19 @@ pub fn run(app: Box<dyn epi::App>, native_options: &epi::NativeOptions) -> ! {
|
||||
egui_winit::epi::window_builder(native_options, &window_settings).with_title(app.name());
|
||||
let event_loop = winit::event_loop::EventLoop::with_user_event();
|
||||
let (gl_window, gl) = create_display(window_builder, &event_loop);
|
||||
let gl = std::rc::Rc::new(gl);
|
||||
|
||||
let repaint_signal = std::sync::Arc::new(GlowRepaintSignal(std::sync::Mutex::new(
|
||||
event_loop.create_proxy(),
|
||||
)));
|
||||
|
||||
let mut painter = crate::Painter::new(&gl, None, "")
|
||||
let mut painter = crate::Painter::new(gl.clone(), None, "")
|
||||
.unwrap_or_else(|error| panic!("some OpenGL error occurred {}\n", error));
|
||||
let mut integration = egui_winit::epi::EpiIntegration::new(
|
||||
"egui_glow",
|
||||
painter.max_texture_side(),
|
||||
gl_window.window(),
|
||||
&gl,
|
||||
repaint_signal,
|
||||
persistence,
|
||||
app,
|
||||
@@ -92,7 +94,7 @@ pub fn run(app: Box<dyn epi::App>, native_options: &epi::NativeOptions) -> ! {
|
||||
|
||||
integration.handle_platform_output(gl_window.window(), platform_output);
|
||||
|
||||
let clipped_meshes = integration.egui_ctx.tessellate(shapes);
|
||||
let clipped_primitives = integration.egui_ctx.tessellate(shapes);
|
||||
|
||||
// paint:
|
||||
{
|
||||
@@ -104,10 +106,9 @@ pub fn run(app: Box<dyn epi::App>, native_options: &epi::NativeOptions) -> ! {
|
||||
gl.clear(glow::COLOR_BUFFER_BIT);
|
||||
}
|
||||
painter.paint_and_update_textures(
|
||||
&gl,
|
||||
gl_window.window().inner_size().into(),
|
||||
integration.egui_ctx.pixels_per_point(),
|
||||
clipped_meshes,
|
||||
&clipped_primitives,
|
||||
&textures_delta,
|
||||
);
|
||||
|
||||
@@ -153,7 +154,7 @@ pub fn run(app: Box<dyn epi::App>, native_options: &epi::NativeOptions) -> ! {
|
||||
}
|
||||
winit::event::Event::LoopDestroyed => {
|
||||
integration.on_exit(gl_window.window());
|
||||
painter.destroy(&gl);
|
||||
painter.destroy();
|
||||
}
|
||||
winit::event::Event::UserEvent(RequestRepaintEvent) => {
|
||||
gl_window.window().request_redraw();
|
||||
|
||||
Reference in New Issue
Block a user