Skip to content

Commit

Permalink
Allow software rendering OpenGL by default (#1693)
Browse files Browse the repository at this point in the history
Follow-up to #1681
  • Loading branch information
emilk authored May 29, 2022
1 parent 4a7a2d6 commit 20c8ee3
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ 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
2 changes: 1 addition & 1 deletion eframe/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ NOTE: [`egui-winit`](../egui-winit/CHANGELOG.md), [`egui_glium`](../egui_glium/C
* Add features "wgpu" and "glow"
* Add `NativeOptions::renderer` to switch between the rendering backends
* Fix clipboard on Wayland ([#1613](https://github.com/emilk/egui/pull/1613)).

* Allow running on native without hardware accelerated rendering. Change with `NativeOptions::hardware_acceleration` ([#1681]([#1693](https://github.com/emilk/egui/pull/1693)).

## 0.18.0 - 2022-04-30
* MSRV (Minimum Supported Rust Version) is now `1.60.0` ([#1467](https://github.com/emilk/egui/pull/1467)).
Expand Down
25 changes: 20 additions & 5 deletions eframe/src/epi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,21 @@ pub trait App {
fn post_rendering(&mut self, _window_size_px: [u32; 2], _frame: &Frame) {}
}

/// Selects the level of hardware graphics acceleration.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum HardwareAcceleration {
/// Require graphics acceleration.
Required,

/// Prefer graphics acceleration, but fall back to software.
Preferred,

/// Do NOT use graphics acceleration.
///
/// On some platforms (MacOS) this is ignored and treated the same as [`Self::Preferred`].
Off,
}

/// Options controlling the behavior of a native window.
///
/// Only a single native window is currently supported.
Expand Down Expand Up @@ -221,10 +236,10 @@ 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>,
/// Specify wether or not hardware acceleration is preferred, required, or not.
///
/// Default: [`HardwareAcceleration::Preferred`].
pub hardware_acceleration: HardwareAcceleration,

/// What rendering backend to use.
pub renderer: Renderer,
Expand All @@ -248,7 +263,7 @@ impl Default for NativeOptions {
multisampling: 0,
depth_buffer: 0,
stencil_buffer: 0,
hardware_acceleration: Some(true),
hardware_acceleration: HardwareAcceleration::Preferred,
renderer: Renderer::default(),
}
}
Expand Down
11 changes: 10 additions & 1 deletion eframe/src/native/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,18 @@ fn create_display(
glow::Context,
) {
crate::profile_function!();

use crate::HardwareAcceleration;

let hardware_acceleration = match native_options.hardware_acceleration {
HardwareAcceleration::Required => Some(true),
HardwareAcceleration::Preferred => None,
HardwareAcceleration::Off => Some(false),
};

let gl_window = unsafe {
glutin::ContextBuilder::new()
.with_hardware_acceleration(native_options.hardware_acceleration)
.with_hardware_acceleration(hardware_acceleration)
.with_depth_buffer(native_options.depth_buffer)
.with_multisampling(native_options.multisampling)
.with_srgb(true)
Expand Down

0 comments on commit 20c8ee3

Please sign in to comment.