desktop: glow renderer fallback support

This commit is contained in:
ardocrat 2024-06-03 18:34:13 +03:00
parent 19994445e3
commit 9fbb76968c
4 changed files with 22 additions and 9 deletions

View file

@ -112,4 +112,4 @@ jni = "0.21.1"
android-activity = { version = "0.6.0", features = ["game-activity"] } android-activity = { version = "0.6.0", features = ["game-activity"] }
wgpu = "0.19.1" wgpu = "0.19.1"
winit = { version = "0.29.15", features = ["android-game-activity"] } winit = { version = "0.29.15", features = ["android-game-activity"] }
eframe = { version = "0.27.2", features = ["wgpu", "android-game-activity"] } eframe = { version = "0.27.2", features = ["wgpu", "glow", "android-game-activity"] }

View file

@ -27,6 +27,7 @@ use rfd::FileDialog;
use crate::gui::platform::PlatformCallbacks; use crate::gui::platform::PlatformCallbacks;
/// Desktop platform related actions. /// Desktop platform related actions.
#[derive(Clone)]
pub struct Desktop { pub struct Desktop {
/// Flag to check if camera stop is needed. /// Flag to check if camera stop is needed.
stop_camera: Arc<AtomicBool>, stop_camera: Arc<AtomicBool>,

View file

@ -15,6 +15,7 @@
#[macro_use] #[macro_use]
extern crate rust_i18n; extern crate rust_i18n;
use eframe::NativeOptions;
use egui::{Context, Stroke}; use egui::{Context, Stroke};
#[cfg(target_os = "android")] #[cfg(target_os = "android")]
@ -68,7 +69,7 @@ fn android_main(app: AndroidApp) {
let width = app.config().screen_width_dp().unwrap() as f32; let width = app.config().screen_width_dp().unwrap() as f32;
let height = app.config().screen_height_dp().unwrap() as f32; let height = app.config().screen_height_dp().unwrap() as f32;
let size = egui::emath::vec2(width, height); let size = egui::emath::vec2(width, height);
let mut options = eframe::NativeOptions { let mut options = NativeOptions {
viewport: egui::ViewportBuilder::default().with_inner_size(size), viewport: egui::ViewportBuilder::default().with_inner_size(size),
..Default::default() ..Default::default()
}; };
@ -89,7 +90,7 @@ fn android_main(app: AndroidApp) {
})); }));
let app = PlatformApp::new(platform); let app = PlatformApp::new(platform);
start(options, app_creator(app)); start(options, app_creator(app)).unwrap();
} }
/// Check if system is using dark theme. /// Check if system is using dark theme.
@ -116,9 +117,12 @@ pub fn app_creator<T: 'static>(app: PlatformApp<T>) -> eframe::AppCreator
} }
/// Entry point to start ui with [`eframe`]. /// Entry point to start ui with [`eframe`].
pub fn start(mut options: eframe::NativeOptions, app_creator: eframe::AppCreator) { pub fn start(mut options: NativeOptions, app_creator: eframe::AppCreator) -> eframe::Result<()> {
options.default_theme = eframe::Theme::Light; options.default_theme = if AppConfig::dark_theme().unwrap_or(false) {
options.renderer = eframe::Renderer::Wgpu; eframe::Theme::Dark
} else {
eframe::Theme::Light
};
// Setup translations. // Setup translations.
setup_i18n(); setup_i18n();
// Start integrated node if needed. // Start integrated node if needed.
@ -126,7 +130,7 @@ pub fn start(mut options: eframe::NativeOptions, app_creator: eframe::AppCreator
Node::start(); Node::start();
} }
// Launch graphical interface. // Launch graphical interface.
eframe::run_native("Grim", options, app_creator).unwrap(); eframe::run_native("Grim", options, app_creator)
} }
/// Setup application [`egui::Style`] and [`egui::Visuals`]. /// Setup application [`egui::Style`] and [`egui::Visuals`].

View file

@ -69,9 +69,17 @@ fn real_main() {
viewport = viewport.with_position(pos2(x, y)); viewport = viewport.with_position(pos2(x, y));
} }
let options = eframe::NativeOptions { let mut options = eframe::NativeOptions {
viewport, viewport,
..Default::default() ..Default::default()
}; };
grim::start(options, grim::app_creator(PlatformApp::new(platform))); options.renderer = eframe::Renderer::Wgpu;
match grim::start(options.clone(), grim::app_creator(PlatformApp::new(platform.clone()))) {
Ok(_) => {}
Err(_) => {
// Start with Glow renderer on error.
options.renderer = eframe::Renderer::Glow;
grim::start(options, grim::app_creator(PlatformApp::new(platform))).unwrap();
}
}
} }