1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-01 14:20:04 -04:00

Add egui_wgpu crate (#1564)

Based on https://github.com/hasenbanck/egui_wgpu_backend

`egui-wgpu` is now an official backend for `eframe` (opt-in).

Use the `wgpu` feature flag on `eframe` and the `NativeOptions::renderer` settings to pick it.

Co-authored-by: Nils Hasenbanck <nils@hasenbanck.de>
Co-authored-by: Sven Niederberger <niederberger@embotech.com>
Co-authored-by: Sven Niederberger <73159570+s-nie@users.noreply.github.com>
This commit is contained in:
Emil Ernerfeldt
2022-05-12 09:02:28 +02:00
committed by GitHub
parent 3d52cc8867
commit 931e716b97
32 changed files with 1540 additions and 101 deletions

View File

@@ -1,5 +1,6 @@
use std::sync::Arc;
use eframe::egui_glow;
use egui::mutex::Mutex;
use egui_glow::glow;
@@ -39,8 +40,10 @@ impl eframe::App for Custom3d {
});
}
fn on_exit(&mut self, gl: &glow::Context) {
self.rotating_triangle.lock().destroy(gl);
fn on_exit(&mut self, gl: Option<&glow::Context>) {
if let Some(gl) = gl {
self.rotating_triangle.lock().destroy(gl);
}
}
}

View File

@@ -1,9 +1,15 @@
#[cfg(feature = "glow")]
mod custom3d;
mod fractal_clock;
#[cfg(feature = "http")]
mod http_app;
#[cfg(feature = "glow")]
pub use custom3d::Custom3d;
pub use fractal_clock::FractalClock;
#[cfg(feature = "http")]
pub use http_app::HttpApp;

View File

@@ -9,6 +9,10 @@ fn main() {
let options = eframe::NativeOptions {
drag_and_drop_support: true,
#[cfg(feature = "wgpu")]
renderer: eframe::Renderer::Wgpu,
..Default::default()
};
eframe::run_native(

View File

@@ -1,5 +1,7 @@
use egui_demo_lib::is_mobile;
use egui_glow::glow;
#[cfg(feature = "glow")]
use eframe::glow;
#[derive(Default)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
@@ -91,7 +93,8 @@ pub struct State {
pub struct WrapApp {
state: State,
// not serialized (because it contains OpenGL buffers etc)
custom3d: crate::apps::Custom3d,
#[cfg(feature = "glow")]
custom3d: Option<crate::apps::Custom3d>,
dropped_files: Vec<egui::DroppedFile>,
}
@@ -100,7 +103,8 @@ impl WrapApp {
#[allow(unused_mut)]
let mut slf = Self {
state: State::default(),
custom3d: crate::apps::Custom3d::new(&cc.gl),
#[cfg(feature = "glow")]
custom3d: cc.gl.as_ref().map(|gl| crate::apps::Custom3d::new(gl)),
dropped_files: Default::default(),
};
@@ -121,7 +125,7 @@ impl WrapApp {
}
fn apps_iter_mut(&mut self) -> impl Iterator<Item = (&str, &str, &mut dyn eframe::App)> {
vec![
let mut vec = vec![
(
"✨ Demos",
"demo",
@@ -143,18 +147,24 @@ impl WrapApp {
"clock",
&mut self.state.clock as &mut dyn eframe::App,
),
(
];
#[cfg(feature = "glow")]
if let Some(custom3d) = &mut self.custom3d {
vec.push((
"🔺 3D painting",
"custom3e",
&mut self.custom3d as &mut dyn eframe::App,
),
(
"🎨 Color test",
"colors",
&mut self.state.color_test as &mut dyn eframe::App,
),
]
.into_iter()
custom3d as &mut dyn eframe::App,
));
}
vec.push((
"🎨 Color test",
"colors",
&mut self.state.color_test as &mut dyn eframe::App,
));
vec.into_iter()
}
}
@@ -212,8 +222,11 @@ impl eframe::App for WrapApp {
self.ui_file_drag_and_drop(ctx);
}
fn on_exit(&mut self, gl: &glow::Context) {
self.custom3d.on_exit(gl);
#[cfg(feature = "glow")]
fn on_exit(&mut self, gl: Option<&glow::Context>) {
if let Some(custom3d) = &mut self.custom3d {
custom3d.on_exit(gl);
}
}
}