Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flag to disable hardware acceleration #1681

Merged
merged 2 commits into from
May 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ NOTE: [`epaint`](epaint/CHANGELOG.md), [`eframe`](eframe/CHANGELOG.md), [`egui-w

## Unreleased
### 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 `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)).
Expand Down
6 changes: 6 additions & 0 deletions eframe/src/epi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@ pub struct NativeOptions {
/// `egui` doesn't need the stencil buffer, so the default value is 0.
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>,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on mac, glutin only sets the relevant attribute (mentioned below) if it is some, otherwise it just skips setting that attribute.

from https://developer.apple.com/documentation/appkit/1436213-opengl_pixel_format_attributes/nsopenglpfaaccelerated

A Boolean attribute. If present, this attribute indicates that only hardware-accelerated renderers are considered. If not present, accelerated renderers are still preferred.

so, hw acceleration preferred by default (None). if Some(true), only hw acceleration contexts are considered. but ofcourse, someone with mac needs to test it out just to be sure.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting - so the current default (before and after this PR) means that we ONLY consider hardware-accelerated renderers, which could explain #1358 (comment)

Perhaps the default should be None to allow software rendered backends too.


/// What rendering backend to use.
pub renderer: Renderer,
}
Expand All @@ -233,6 +238,7 @@ impl Default for NativeOptions {
multisampling: 0,
depth_buffer: 0,
stencil_buffer: 0,
hardware_acceleration: Some(true),
renderer: Renderer::default(),
}
}
Expand Down
11 changes: 6 additions & 5 deletions eframe/src/native/epi_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ pub fn window_builder(
max_window_size,
resizable,
transparent,
vsync: _, // used in `fn create_display`
multisampling: _, // used in `fn create_display`
depth_buffer: _, // used in `fn create_display`
stencil_buffer: _, // used in `fn create_display`
renderer: _, // used in `fn run_native`
vsync: _, // used in `fn create_display`
multisampling: _, // used in `fn create_display`
depth_buffer: _, // used in `fn create_display`
stencil_buffer: _, // used in `fn create_display`
hardware_acceleration: _, // used in `fn create_display`
renderer: _, // used in `fn run_native`
} = native_options;

let window_icon = icon_data.clone().and_then(load_icon);
Expand Down
1 change: 1 addition & 0 deletions eframe/src/native/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ fn create_display(
crate::profile_function!();
let gl_window = unsafe {
glutin::ContextBuilder::new()
.with_hardware_acceleration(native_options.hardware_acceleration)
.with_depth_buffer(native_options.depth_buffer)
.with_multisampling(native_options.multisampling)
.with_srgb(true)
Expand Down