Skip to content

Commit 20c8ee3

Browse files
authored
Allow software rendering OpenGL by default (#1693)
Follow-up to #1681
1 parent 4a7a2d6 commit 20c8ee3

File tree

4 files changed

+31
-8
lines changed

4 files changed

+31
-8
lines changed

CHANGELOG.md

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ 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)).
109
* Added `*_released` & `*_clicked` methods for `PointerState` ([#1582](https://github.com/emilk/egui/pull/1582)).
1110
* Added `egui::hex_color!` to create `Color32`'s from hex strings under the `color-hex` feature ([#1596](https://github.com/emilk/egui/pull/1596)).
1211
* Optimized painting of filled circles (e.g. for scatter plots) by 10x or more ([#1616](https://github.com/emilk/egui/pull/1616)).

eframe/CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ NOTE: [`egui-winit`](../egui-winit/CHANGELOG.md), [`egui_glium`](../egui_glium/C
1010
* Add features "wgpu" and "glow"
1111
* Add `NativeOptions::renderer` to switch between the rendering backends
1212
* Fix clipboard on Wayland ([#1613](https://github.com/emilk/egui/pull/1613)).
13-
13+
* Allow running on native without hardware accelerated rendering. Change with `NativeOptions::hardware_acceleration` ([#1681]([#1693](https://github.com/emilk/egui/pull/1693)).
1414

1515
## 0.18.0 - 2022-04-30
1616
* MSRV (Minimum Supported Rust Version) is now `1.60.0` ([#1467](https://github.com/emilk/egui/pull/1467)).

eframe/src/epi.rs

+20-5
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,21 @@ pub trait App {
148148
fn post_rendering(&mut self, _window_size_px: [u32; 2], _frame: &Frame) {}
149149
}
150150

151+
/// Selects the level of hardware graphics acceleration.
152+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
153+
pub enum HardwareAcceleration {
154+
/// Require graphics acceleration.
155+
Required,
156+
157+
/// Prefer graphics acceleration, but fall back to software.
158+
Preferred,
159+
160+
/// Do NOT use graphics acceleration.
161+
///
162+
/// On some platforms (MacOS) this is ignored and treated the same as [`Self::Preferred`].
163+
Off,
164+
}
165+
151166
/// Options controlling the behavior of a native window.
152167
///
153168
/// Only a single native window is currently supported.
@@ -221,10 +236,10 @@ pub struct NativeOptions {
221236
/// `egui` doesn't need the stencil buffer, so the default value is 0.
222237
pub stencil_buffer: u8,
223238

224-
/// Use hardware acceleration if available. On macOS, this will possibly
225-
/// use a dedicated GPU which will lead to higher power consumption.
226-
/// The default value is `Some(true)`
227-
pub hardware_acceleration: Option<bool>,
239+
/// Specify wether or not hardware acceleration is preferred, required, or not.
240+
///
241+
/// Default: [`HardwareAcceleration::Preferred`].
242+
pub hardware_acceleration: HardwareAcceleration,
228243

229244
/// What rendering backend to use.
230245
pub renderer: Renderer,
@@ -248,7 +263,7 @@ impl Default for NativeOptions {
248263
multisampling: 0,
249264
depth_buffer: 0,
250265
stencil_buffer: 0,
251-
hardware_acceleration: Some(true),
266+
hardware_acceleration: HardwareAcceleration::Preferred,
252267
renderer: Renderer::default(),
253268
}
254269
}

eframe/src/native/run.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,18 @@ fn create_display(
1515
glow::Context,
1616
) {
1717
crate::profile_function!();
18+
19+
use crate::HardwareAcceleration;
20+
21+
let hardware_acceleration = match native_options.hardware_acceleration {
22+
HardwareAcceleration::Required => Some(true),
23+
HardwareAcceleration::Preferred => None,
24+
HardwareAcceleration::Off => Some(false),
25+
};
26+
1827
let gl_window = unsafe {
1928
glutin::ContextBuilder::new()
20-
.with_hardware_acceleration(native_options.hardware_acceleration)
29+
.with_hardware_acceleration(hardware_acceleration)
2130
.with_depth_buffer(native_options.depth_buffer)
2231
.with_multisampling(native_options.multisampling)
2332
.with_srgb(true)

0 commit comments

Comments
 (0)