Add new NativeOptions: vsync multisampling depth_buffer stencil_buffer
These are useful when embedding 3D into eframe.
This commit is contained in:
parent
c63bdeab67
commit
a9fd03709e
8 changed files with 57 additions and 15 deletions
|
@ -7,7 +7,7 @@ NOTE: [`epaint`](epaint/CHANGELOG.md), [`eframe`](eframe/CHANGELOG.md), [`egui_w
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
### Added ⭐
|
### Added ⭐
|
||||||
* Added `Shape::Callback` for backend-specific painting ([#1351](https://github.com/emilk/egui/pull/1351)).
|
* Added `Shape::Callback` for backend-specific painting, [with an example](https://github.com/emilk/egui/blob/master/eframe/examples/custom_3d_three-d.rs) ([#1351](https://github.com/emilk/egui/pull/1351)).
|
||||||
* Added `Frame::canvas` ([#1362](https://github.com/emilk/egui/pull/1362)).
|
* Added `Frame::canvas` ([#1362](https://github.com/emilk/egui/pull/1362)).
|
||||||
* `Context::request_repaint` will wake up UI thread, if integrations has called `Context::set_request_repaint_callback` ([#1366](https://github.com/emilk/egui/pull/1366)).
|
* `Context::request_repaint` will wake up UI thread, if integrations has called `Context::set_request_repaint_callback` ([#1366](https://github.com/emilk/egui/pull/1366)).
|
||||||
* Added `Ui::push_id` ([#1374](https://github.com/emilk/egui/pull/1374)).
|
* Added `Ui::push_id` ([#1374](https://github.com/emilk/egui/pull/1374)).
|
||||||
|
|
|
@ -9,6 +9,7 @@ NOTE: [`egui_web`](../egui_web/CHANGELOG.md), [`egui-winit`](../egui-winit/CHANG
|
||||||
* Remove the `egui_glium` feature. `eframe` will now always use `egui_glow` as the native backend ([#1357](https://github.com/emilk/egui/pull/1357)).
|
* Remove the `egui_glium` feature. `eframe` will now always use `egui_glow` as the native backend ([#1357](https://github.com/emilk/egui/pull/1357)).
|
||||||
* Removed `Frame::request_repaint` - just call `egui::Context::request_repaint` for the same effect ([#1366](https://github.com/emilk/egui/pull/1366)).
|
* Removed `Frame::request_repaint` - just call `egui::Context::request_repaint` for the same effect ([#1366](https://github.com/emilk/egui/pull/1366)).
|
||||||
* Use full browser width by default ([#1378](https://github.com/emilk/egui/pull/1378)).
|
* Use full browser width by default ([#1378](https://github.com/emilk/egui/pull/1378)).
|
||||||
|
* Add new `NativeOptions`: `vsync`, `multisampling`, `depth_buffer`, `stencil_buffer`.
|
||||||
|
|
||||||
|
|
||||||
## 0.17.0 - 2022-02-22
|
## 0.17.0 - 2022-02-22
|
||||||
|
|
|
@ -18,9 +18,13 @@ use egui::mutex::Mutex;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let options = eframe::NativeOptions::default();
|
let options = eframe::NativeOptions {
|
||||||
|
initial_window_size: Some(egui::vec2(350.0, 380.0)),
|
||||||
|
multisampling: 8,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
eframe::run_native(
|
eframe::run_native(
|
||||||
"Custom 3D painting in eframe",
|
"Custom 3D painting in eframe using glow",
|
||||||
options,
|
options,
|
||||||
Box::new(|cc| Box::new(MyApp::new(cc))),
|
Box::new(|cc| Box::new(MyApp::new(cc))),
|
||||||
);
|
);
|
||||||
|
@ -51,13 +55,11 @@ impl eframe::App for MyApp {
|
||||||
ui.label(" (OpenGL).");
|
ui.label(" (OpenGL).");
|
||||||
});
|
});
|
||||||
|
|
||||||
egui::ScrollArea::both().show(ui, |ui| {
|
|
||||||
egui::Frame::canvas(ui.style()).show(ui, |ui| {
|
egui::Frame::canvas(ui.style()).show(ui, |ui| {
|
||||||
self.custom_painting(ui);
|
self.custom_painting(ui);
|
||||||
});
|
});
|
||||||
ui.label("Drag to rotate!");
|
ui.label("Drag to rotate!");
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_exit(&mut self, gl: &glow::Context) {
|
fn on_exit(&mut self, gl: &glow::Context) {
|
||||||
|
@ -68,7 +70,7 @@ impl eframe::App for MyApp {
|
||||||
impl MyApp {
|
impl MyApp {
|
||||||
fn custom_painting(&mut self, ui: &mut egui::Ui) {
|
fn custom_painting(&mut self, ui: &mut egui::Ui) {
|
||||||
let (rect, response) =
|
let (rect, response) =
|
||||||
ui.allocate_exact_size(egui::Vec2::splat(256.0), egui::Sense::drag());
|
ui.allocate_exact_size(egui::Vec2::splat(300.0), egui::Sense::drag());
|
||||||
|
|
||||||
self.angle += response.drag_delta().x * 0.01;
|
self.angle += response.drag_delta().x * 0.01;
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ use eframe::egui;
|
||||||
fn main() {
|
fn main() {
|
||||||
let options = eframe::NativeOptions {
|
let options = eframe::NativeOptions {
|
||||||
initial_window_size: Some(egui::vec2(550.0, 610.0)),
|
initial_window_size: Some(egui::vec2(550.0, 610.0)),
|
||||||
|
multisampling: 8,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
eframe::run_native(
|
eframe::run_native(
|
||||||
|
@ -31,7 +32,7 @@ struct MyApp {
|
||||||
|
|
||||||
impl MyApp {
|
impl MyApp {
|
||||||
fn new(_cc: &eframe::CreationContext<'_>) -> Self {
|
fn new(_cc: &eframe::CreationContext<'_>) -> Self {
|
||||||
Self { angle: 0.0 }
|
Self { angle: 0.2 }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,10 @@ pub fn window_builder(
|
||||||
max_window_size,
|
max_window_size,
|
||||||
resizable,
|
resizable,
|
||||||
transparent,
|
transparent,
|
||||||
|
vsync: _, // used in `fn create_display`
|
||||||
|
multisampling: _, // used in `fn create_display`
|
||||||
|
depth_buffer: _, // used in `fn create_display`
|
||||||
|
stencil_buffer: _, // used in `fn create_display`
|
||||||
} = native_options;
|
} = native_options;
|
||||||
|
|
||||||
let window_icon = icon_data.clone().and_then(load_icon);
|
let window_icon = icon_data.clone().and_then(load_icon);
|
||||||
|
|
|
@ -3,6 +3,8 @@ All notable changes to the `egui_glow` integration will be noted in this file.
|
||||||
|
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
* Improved logging on rendering failures.
|
||||||
|
* Add new `NativeOptions`: `vsync`, `multisampling`, `depth_buffer`, `stencil_buffer`.
|
||||||
|
|
||||||
|
|
||||||
## 0.17.0 - 2022-02-22
|
## 0.17.0 - 2022-02-22
|
||||||
|
|
|
@ -5,6 +5,7 @@ struct RequestRepaintEvent;
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn create_display(
|
fn create_display(
|
||||||
|
native_options: &NativeOptions,
|
||||||
window_builder: winit::window::WindowBuilder,
|
window_builder: winit::window::WindowBuilder,
|
||||||
event_loop: &winit::event_loop::EventLoop<RequestRepaintEvent>,
|
event_loop: &winit::event_loop::EventLoop<RequestRepaintEvent>,
|
||||||
) -> (
|
) -> (
|
||||||
|
@ -13,10 +14,11 @@ fn create_display(
|
||||||
) {
|
) {
|
||||||
let gl_window = unsafe {
|
let gl_window = unsafe {
|
||||||
glutin::ContextBuilder::new()
|
glutin::ContextBuilder::new()
|
||||||
.with_depth_buffer(0)
|
.with_depth_buffer(native_options.depth_buffer)
|
||||||
.with_srgb(true)
|
.with_multisampling(native_options.multisampling)
|
||||||
.with_stencil_buffer(0)
|
.with_srgb(native_options.vsync)
|
||||||
.with_vsync(true)
|
.with_stencil_buffer(native_options.stencil_buffer)
|
||||||
|
.with_vsync(native_options.vsync)
|
||||||
.build_windowed(window_builder, event_loop)
|
.build_windowed(window_builder, event_loop)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.make_current()
|
.make_current()
|
||||||
|
@ -40,7 +42,7 @@ pub fn run(app_name: &str, native_options: &epi::NativeOptions, app_creator: epi
|
||||||
let window_builder =
|
let window_builder =
|
||||||
egui_winit::epi::window_builder(native_options, &window_settings).with_title(app_name);
|
egui_winit::epi::window_builder(native_options, &window_settings).with_title(app_name);
|
||||||
let event_loop = winit::event_loop::EventLoop::with_user_event();
|
let event_loop = winit::event_loop::EventLoop::with_user_event();
|
||||||
let (gl_window, gl) = create_display(window_builder, &event_loop);
|
let (gl_window, gl) = create_display(native_options, window_builder, &event_loop);
|
||||||
let gl = std::rc::Rc::new(gl);
|
let gl = std::rc::Rc::new(gl);
|
||||||
|
|
||||||
let mut painter = crate::Painter::new(gl.clone(), None, "")
|
let mut painter = crate::Painter::new(gl.clone(), None, "")
|
||||||
|
|
|
@ -183,6 +183,32 @@ pub struct NativeOptions {
|
||||||
/// You control the transparency with [`App::clear_color()`].
|
/// You control the transparency with [`App::clear_color()`].
|
||||||
/// You should avoid having a [`egui::CentralPanel`], or make sure its frame is also transparent.
|
/// You should avoid having a [`egui::CentralPanel`], or make sure its frame is also transparent.
|
||||||
pub transparent: bool,
|
pub transparent: bool,
|
||||||
|
|
||||||
|
/// Turn on vertical syncing, limiting the FPS to the display refresh rate.
|
||||||
|
///
|
||||||
|
/// The default is `true`.
|
||||||
|
pub vsync: bool,
|
||||||
|
|
||||||
|
/// Set the level of the multisampling anti-aliasing (MSAA).
|
||||||
|
///
|
||||||
|
/// Must be a power-of-two. Higher = more smooth 3D.
|
||||||
|
///
|
||||||
|
/// A value of `0` turns it off (default).
|
||||||
|
///
|
||||||
|
/// `egui` already performs anti-aliasing via "feathering"
|
||||||
|
/// (controlled by [`egui::epaint::TessellationOptions`]),
|
||||||
|
/// but if you are embedding 3D in egui you may want to turn on multisampling.
|
||||||
|
pub multisampling: u16,
|
||||||
|
|
||||||
|
/// Sets the number of bits in the depth buffer.
|
||||||
|
///
|
||||||
|
/// `egui` doesn't need the depth buffer, so the default value is 0.
|
||||||
|
pub depth_buffer: u8,
|
||||||
|
|
||||||
|
/// Sets the number of bits in the stencil buffer.
|
||||||
|
///
|
||||||
|
/// `egui` doesn't need the stencil buffer, so the default value is 0.
|
||||||
|
pub stencil_buffer: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for NativeOptions {
|
impl Default for NativeOptions {
|
||||||
|
@ -199,6 +225,10 @@ impl Default for NativeOptions {
|
||||||
max_window_size: None,
|
max_window_size: None,
|
||||||
resizable: true,
|
resizable: true,
|
||||||
transparent: false,
|
transparent: false,
|
||||||
|
vsync: true,
|
||||||
|
multisampling: 0,
|
||||||
|
depth_buffer: 0,
|
||||||
|
stencil_buffer: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue