mirror of
https://github.com/emilk/egui.git
synced 2026-08-29 21:00:03 -04:00
Update to wgpu 29
This commit is contained in:
@@ -184,9 +184,17 @@ impl<'app> WgpuWinitApp<'app> {
|
||||
builder: ViewportBuilder,
|
||||
) -> crate::Result<&mut WgpuWinitRunning<'app>> {
|
||||
profiling::function_scope!();
|
||||
// Inject the display handle into the wgpu setup so that wgpu can create
|
||||
// surfaces on platforms that require it (e.g. GLES on Wayland).
|
||||
let mut wgpu_options = self.native_options.wgpu_options.clone();
|
||||
if let egui_wgpu::WgpuSetup::CreateNew(ref mut create_new) = wgpu_options.wgpu_setup
|
||||
&& create_new.display_handle.is_none()
|
||||
{
|
||||
create_new.display_handle = Some(Box::new(event_loop.owned_display_handle()));
|
||||
}
|
||||
let mut painter = pollster::block_on(egui_wgpu::winit::Painter::new(
|
||||
egui_ctx.clone(),
|
||||
self.native_options.wgpu_options.clone(),
|
||||
wgpu_options,
|
||||
self.native_options.viewport.transparent.unwrap_or(false),
|
||||
egui_wgpu::RendererOptions {
|
||||
msaa_samples: self.native_options.multisampling as _,
|
||||
|
||||
@@ -38,6 +38,7 @@ mod web_painter_wgpu;
|
||||
pub use backend::*;
|
||||
|
||||
use egui::Theme;
|
||||
use js_sys::Object;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use web_sys::{Document, MediaQueryList, Node};
|
||||
|
||||
@@ -370,5 +371,5 @@ pub fn percent_decode(s: &str) -> String {
|
||||
|
||||
/// Are we running inside the Safari browser?
|
||||
pub fn is_safari_browser() -> bool {
|
||||
web_sys::window().is_some_and(|window| window.has_own_property(&JsValue::from("safari")))
|
||||
web_sys::window().is_some_and(|window| Object::has_own(&window, &JsValue::from("safari")))
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ use std::sync::Arc;
|
||||
|
||||
use egui::{Event, UserData, ViewportId};
|
||||
use egui_wgpu::{
|
||||
RenderState, SurfaceErrorAction,
|
||||
RenderState, SurfaceErrorAction, SurfaceStatus,
|
||||
capture::{CaptureReceiver, CaptureSender, CaptureState, capture_channel},
|
||||
};
|
||||
use wasm_bindgen::JsValue;
|
||||
@@ -15,7 +15,7 @@ pub(crate) struct WebPainterWgpu {
|
||||
surface: wgpu::Surface<'static>,
|
||||
surface_configuration: wgpu::SurfaceConfiguration,
|
||||
render_state: Option<RenderState>,
|
||||
on_surface_error: Arc<dyn Fn(wgpu::SurfaceError) -> SurfaceErrorAction>,
|
||||
on_surface_error: Arc<dyn Fn(SurfaceStatus) -> SurfaceErrorAction>,
|
||||
depth_stencil_format: Option<wgpu::TextureFormat>,
|
||||
depth_texture_view: Option<wgpu::TextureView>,
|
||||
screen_capture_state: Option<CaptureState>,
|
||||
@@ -196,17 +196,58 @@ impl WebPainter for WebPainterWgpu {
|
||||
}
|
||||
|
||||
let output_frame = match self.surface.get_current_texture() {
|
||||
Ok(frame) => frame,
|
||||
Err(err) => match (*self.on_surface_error)(err) {
|
||||
SurfaceErrorAction::RecreateSurface => {
|
||||
self.surface
|
||||
.configure(&render_state.device, &self.surface_configuration);
|
||||
return Ok(());
|
||||
wgpu::CurrentSurfaceTexture::Success(frame)
|
||||
| wgpu::CurrentSurfaceTexture::Suboptimal(frame) => frame,
|
||||
wgpu::CurrentSurfaceTexture::Timeout => {
|
||||
match (*self.on_surface_error)(SurfaceStatus::Timeout) {
|
||||
SurfaceErrorAction::RecreateSurface => {
|
||||
self.surface
|
||||
.configure(&render_state.device, &self.surface_configuration);
|
||||
}
|
||||
SurfaceErrorAction::SkipFrame => {}
|
||||
}
|
||||
SurfaceErrorAction::SkipFrame => {
|
||||
return Ok(());
|
||||
return Ok(());
|
||||
}
|
||||
wgpu::CurrentSurfaceTexture::Outdated => {
|
||||
match (*self.on_surface_error)(SurfaceStatus::Outdated) {
|
||||
SurfaceErrorAction::RecreateSurface => {
|
||||
self.surface
|
||||
.configure(&render_state.device, &self.surface_configuration);
|
||||
}
|
||||
SurfaceErrorAction::SkipFrame => {}
|
||||
}
|
||||
},
|
||||
return Ok(());
|
||||
}
|
||||
wgpu::CurrentSurfaceTexture::Lost => {
|
||||
match (*self.on_surface_error)(SurfaceStatus::Lost) {
|
||||
SurfaceErrorAction::RecreateSurface => {
|
||||
self.surface
|
||||
.configure(&render_state.device, &self.surface_configuration);
|
||||
}
|
||||
SurfaceErrorAction::SkipFrame => {}
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
wgpu::CurrentSurfaceTexture::Occluded => {
|
||||
match (*self.on_surface_error)(SurfaceStatus::Occluded) {
|
||||
SurfaceErrorAction::RecreateSurface => {
|
||||
self.surface
|
||||
.configure(&render_state.device, &self.surface_configuration);
|
||||
}
|
||||
SurfaceErrorAction::SkipFrame => {}
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
wgpu::CurrentSurfaceTexture::Validation => {
|
||||
match (*self.on_surface_error)(SurfaceStatus::Validation) {
|
||||
SurfaceErrorAction::RecreateSurface => {
|
||||
self.surface
|
||||
.configure(&render_state.device, &self.surface_configuration);
|
||||
}
|
||||
SurfaceErrorAction::SkipFrame => {}
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user