Allow software rendering OpenGL by default (#1693)

Follow-up to https://github.com/emilk/egui/pull/1681
This commit is contained in:
Emil Ernerfeldt 2022-05-29 20:37:19 +02:00 committed by GitHub
parent 4a7a2d6430
commit 20c8ee302c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 8 deletions

View file

@ -6,7 +6,6 @@ NOTE: [`epaint`](epaint/CHANGELOG.md), [`eframe`](eframe/CHANGELOG.md), [`egui-w
## Unreleased ## Unreleased
### Added ⭐ ### 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 `*_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)). * 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)). * Optimized painting of filled circles (e.g. for scatter plots) by 10x or more ([#1616](https://github.com/emilk/egui/pull/1616)).

View file

@ -10,7 +10,7 @@ NOTE: [`egui-winit`](../egui-winit/CHANGELOG.md), [`egui_glium`](../egui_glium/C
* Add features "wgpu" and "glow" * Add features "wgpu" and "glow"
* Add `NativeOptions::renderer` to switch between the rendering backends * Add `NativeOptions::renderer` to switch between the rendering backends
* Fix clipboard on Wayland ([#1613](https://github.com/emilk/egui/pull/1613)). * 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 ## 0.18.0 - 2022-04-30
* MSRV (Minimum Supported Rust Version) is now `1.60.0` ([#1467](https://github.com/emilk/egui/pull/1467)). * MSRV (Minimum Supported Rust Version) is now `1.60.0` ([#1467](https://github.com/emilk/egui/pull/1467)).

View file

@ -148,6 +148,21 @@ pub trait App {
fn post_rendering(&mut self, _window_size_px: [u32; 2], _frame: &Frame) {} 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. /// Options controlling the behavior of a native window.
/// ///
/// Only a single native window is currently supported. /// 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. /// `egui` doesn't need the stencil buffer, so the default value is 0.
pub stencil_buffer: u8, pub stencil_buffer: u8,
/// Use hardware acceleration if available. On macOS, this will possibly /// Specify wether or not hardware acceleration is preferred, required, or not.
/// use a dedicated GPU which will lead to higher power consumption. ///
/// The default value is `Some(true)` /// Default: [`HardwareAcceleration::Preferred`].
pub hardware_acceleration: Option<bool>, pub hardware_acceleration: HardwareAcceleration,
/// What rendering backend to use. /// What rendering backend to use.
pub renderer: Renderer, pub renderer: Renderer,
@ -248,7 +263,7 @@ impl Default for NativeOptions {
multisampling: 0, multisampling: 0,
depth_buffer: 0, depth_buffer: 0,
stencil_buffer: 0, stencil_buffer: 0,
hardware_acceleration: Some(true), hardware_acceleration: HardwareAcceleration::Preferred,
renderer: Renderer::default(), renderer: Renderer::default(),
} }
} }

View file

@ -15,9 +15,18 @@ fn create_display(
glow::Context, glow::Context,
) { ) {
crate::profile_function!(); 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 { let gl_window = unsafe {
glutin::ContextBuilder::new() glutin::ContextBuilder::new()
.with_hardware_acceleration(native_options.hardware_acceleration) .with_hardware_acceleration(hardware_acceleration)
.with_depth_buffer(native_options.depth_buffer) .with_depth_buffer(native_options.depth_buffer)
.with_multisampling(native_options.multisampling) .with_multisampling(native_options.multisampling)
.with_srgb(true) .with_srgb(true)