Add flag to disable hardware acceleration (#1681)

This is a fix for the behaviour on macOS platforms where any egui app would use the dedicated GPU and consume more power than needed. Not all apps might have dedicated GPU requirements.
This commit is contained in:
Benedikt Terhechte 2022-05-28 17:53:05 +02:00 committed by GitHub
parent 1d9524cc59
commit 72e38370fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 5 deletions

View file

@ -6,6 +6,7 @@ NOTE: [`epaint`](epaint/CHANGELOG.md), [`eframe`](eframe/CHANGELOG.md), [`egui-w
## Unreleased ## Unreleased
### Added ⭐ ### Added ⭐
* Added `NativeOptions::hardware_acceleration` to allow opting out of hardware acceleration for less power consumption ([#1681](https://github.com/emilk/egui/pull/1681)).
* Added `*_released` & `*_clicked` methods for `PointerState` ([#1582](https://github.com/emilk/egui/pull/1582)). * Added `*_released` & `*_clicked` methods for `PointerState` ([#1582](https://github.com/emilk/egui/pull/1582)).
* Added `egui::hex_color!` to create `Color32`'s from hex strings under the `color-hex` feature ([#1596](https://github.com/emilk/egui/pull/1596)). * Added `egui::hex_color!` to create `Color32`'s from hex strings under the `color-hex` feature ([#1596](https://github.com/emilk/egui/pull/1596)).
* Optimized painting of filled circles (e.g. for scatter plots) by 10x or more ([#1616](https://github.com/emilk/egui/pull/1616)). * Optimized painting of filled circles (e.g. for scatter plots) by 10x or more ([#1616](https://github.com/emilk/egui/pull/1616)).

View file

@ -216,6 +216,11 @@ pub struct NativeOptions {
/// `egui` doesn't need the stencil buffer, so the default value is 0. /// `egui` doesn't need the stencil buffer, so the default value is 0.
pub stencil_buffer: u8, pub stencil_buffer: u8,
/// Use hardware acceleration if available. On macOS, this will possibly
/// use a dedicated GPU which will lead to higher power consumption.
/// The default value is `Some(true)`
pub hardware_acceleration: Option<bool>,
/// What rendering backend to use. /// What rendering backend to use.
pub renderer: Renderer, pub renderer: Renderer,
} }
@ -238,6 +243,7 @@ impl Default for NativeOptions {
multisampling: 0, multisampling: 0,
depth_buffer: 0, depth_buffer: 0,
stencil_buffer: 0, stencil_buffer: 0,
hardware_acceleration: Some(true),
renderer: Renderer::default(), renderer: Renderer::default(),
} }
} }

View file

@ -47,11 +47,12 @@ pub fn window_builder(
max_window_size, max_window_size,
resizable, resizable,
transparent, transparent,
vsync: _, // used in `fn create_display` vsync: _, // used in `fn create_display`
multisampling: _, // used in `fn create_display` multisampling: _, // used in `fn create_display`
depth_buffer: _, // used in `fn create_display` depth_buffer: _, // used in `fn create_display`
stencil_buffer: _, // used in `fn create_display` stencil_buffer: _, // used in `fn create_display`
renderer: _, // used in `fn run_native` hardware_acceleration: _, // used in `fn create_display`
renderer: _, // used in `fn run_native`
} = native_options; } = native_options;
let window_icon = icon_data.clone().and_then(load_icon); let window_icon = icon_data.clone().and_then(load_icon);

View file

@ -17,6 +17,7 @@ fn create_display(
crate::profile_function!(); crate::profile_function!();
let gl_window = unsafe { let gl_window = unsafe {
glutin::ContextBuilder::new() glutin::ContextBuilder::new()
.with_hardware_acceleration(native_options.hardware_acceleration)
.with_depth_buffer(native_options.depth_buffer) .with_depth_buffer(native_options.depth_buffer)
.with_multisampling(native_options.multisampling) .with_multisampling(native_options.multisampling)
.with_srgb(true) .with_srgb(true)