Skip to content

Commit 72e3837

Browse files
authored
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.
1 parent 1d9524c commit 72e3837

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ NOTE: [`epaint`](epaint/CHANGELOG.md), [`eframe`](eframe/CHANGELOG.md), [`egui-w
66

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

eframe/src/epi.rs

+6
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ pub struct NativeOptions {
216216
/// `egui` doesn't need the stencil buffer, so the default value is 0.
217217
pub stencil_buffer: u8,
218218

219+
/// Use hardware acceleration if available. On macOS, this will possibly
220+
/// use a dedicated GPU which will lead to higher power consumption.
221+
/// The default value is `Some(true)`
222+
pub hardware_acceleration: Option<bool>,
223+
219224
/// What rendering backend to use.
220225
pub renderer: Renderer,
221226
}
@@ -238,6 +243,7 @@ impl Default for NativeOptions {
238243
multisampling: 0,
239244
depth_buffer: 0,
240245
stencil_buffer: 0,
246+
hardware_acceleration: Some(true),
241247
renderer: Renderer::default(),
242248
}
243249
}

eframe/src/native/epi_integration.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@ pub fn window_builder(
4747
max_window_size,
4848
resizable,
4949
transparent,
50-
vsync: _, // used in `fn create_display`
51-
multisampling: _, // used in `fn create_display`
52-
depth_buffer: _, // used in `fn create_display`
53-
stencil_buffer: _, // used in `fn create_display`
54-
renderer: _, // used in `fn run_native`
50+
vsync: _, // used in `fn create_display`
51+
multisampling: _, // used in `fn create_display`
52+
depth_buffer: _, // used in `fn create_display`
53+
stencil_buffer: _, // used in `fn create_display`
54+
hardware_acceleration: _, // used in `fn create_display`
55+
renderer: _, // used in `fn run_native`
5556
} = native_options;
5657

5758
let window_icon = icon_data.clone().and_then(load_icon);

eframe/src/native/run.rs

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ fn create_display(
1717
crate::profile_function!();
1818
let gl_window = unsafe {
1919
glutin::ContextBuilder::new()
20+
.with_hardware_acceleration(native_options.hardware_acceleration)
2021
.with_depth_buffer(native_options.depth_buffer)
2122
.with_multisampling(native_options.multisampling)
2223
.with_srgb(true)

0 commit comments

Comments
 (0)