mirror of
https://github.com/emilk/egui.git
synced 2026-06-28 07:23:13 -04:00
Allow software rendering OpenGL by default (#1693)
Follow-up to https://github.com/emilk/egui/pull/1681
This commit is contained in:
@@ -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(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user