Browse Source

Allow software rendering OpenGL by default (#1693)

Follow-up to https://github.com/emilk/egui/pull/1681
pull/1700/head
Emil Ernerfeldt 2 years ago
committed by GitHub
parent
commit
20c8ee302c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 2
      eframe/CHANGELOG.md
  3. 25
      eframe/src/epi.rs
  4. 11
      eframe/src/native/run.rs

1
CHANGELOG.md

@ -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)).

2
eframe/CHANGELOG.md

@ -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)).

25
eframe/src/epi.rs

@ -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.
@ -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,
@ -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(),
}
}

11
eframe/src/native/run.rs

@ -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)

Loading…
Cancel
Save