diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index 849b91f2b..7c8af2e2b 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -186,14 +186,14 @@ impl<'app> WgpuWinitApp<'app> { let mut painter = pollster::block_on(egui_wgpu::winit::Painter::new( egui_ctx.clone(), self.native_options.wgpu_options.clone(), - egui_wgpu::depth_format_from_bits( - self.native_options.depth_buffer, - self.native_options.stencil_buffer, - ), self.native_options.viewport.transparent.unwrap_or(false), egui_wgpu::RendererOptions { msaa_samples: self.native_options.multisampling.max(1) as _, dithering: self.native_options.dithering, + depth_stencil_format: egui_wgpu::depth_format_from_bits( + self.native_options.depth_buffer, + self.native_options.stencil_buffer, + ), }, )); diff --git a/crates/egui-wgpu/src/lib.rs b/crates/egui-wgpu/src/lib.rs index b4e003a33..59e27e7ac 100644 --- a/crates/egui-wgpu/src/lib.rs +++ b/crates/egui-wgpu/src/lib.rs @@ -173,7 +173,6 @@ impl RenderState { config: &WgpuConfiguration, instance: &wgpu::Instance, compatible_surface: Option<&wgpu::Surface<'static>>, - depth_format: Option, options: RendererOptions, ) -> Result { profiling::scope!("RenderState::create"); // async yield give bad names using `profile_function` @@ -243,7 +242,7 @@ impl RenderState { }; let target_format = crate::preferred_framebuffer_format(&surface_formats)?; - let renderer = Renderer::new(&device, target_format, depth_format, options); + let renderer = Renderer::new(&device, target_format, options); // On wasm, depending on feature flags, wgpu objects may or may not implement sync. // It doesn't make sense to switch to Rc for that special usecase, so simply disable the lint. diff --git a/crates/egui-wgpu/src/renderer.rs b/crates/egui-wgpu/src/renderer.rs index b3a539155..10cb4b08f 100644 --- a/crates/egui-wgpu/src/renderer.rs +++ b/crates/egui-wgpu/src/renderer.rs @@ -198,6 +198,12 @@ pub struct RendererOptions { /// /// Defaults to true. pub dithering: bool, + + /// What format to use for the depth and stencil buffers, + /// e.g. [`wgpu::TextureFormat::Depth32FloatStencil8`]. + /// + /// egui doesn't need depth/stencil, so the default value is `None` (no depth or stancil buffers). + pub depth_stencil_format: Option, } impl Default for RendererOptions { @@ -205,6 +211,7 @@ impl Default for RendererOptions { Self { msaa_samples: 0, dithering: true, + depth_stencil_format: None, } } } @@ -244,7 +251,6 @@ impl Renderer { pub fn new( device: &wgpu::Device, output_color_format: wgpu::TextureFormat, - output_depth_format: Option, options: RendererOptions, ) -> Self { profiling::function_scope!(); @@ -332,13 +338,15 @@ impl Renderer { push_constant_ranges: &[], }); - let depth_stencil = output_depth_format.map(|format| wgpu::DepthStencilState { - format, - depth_write_enabled: false, - depth_compare: wgpu::CompareFunction::Always, - stencil: wgpu::StencilState::default(), - bias: wgpu::DepthBiasState::default(), - }); + let depth_stencil = options + .depth_stencil_format + .map(|format| wgpu::DepthStencilState { + format, + depth_write_enabled: false, + depth_compare: wgpu::CompareFunction::Always, + stencil: wgpu::StencilState::default(), + bias: wgpu::DepthBiasState::default(), + }); let pipeline = { profiling::scope!("create_render_pipeline"); diff --git a/crates/egui-wgpu/src/winit.rs b/crates/egui-wgpu/src/winit.rs index 1c0a2ca3d..c96723769 100644 --- a/crates/egui-wgpu/src/winit.rs +++ b/crates/egui-wgpu/src/winit.rs @@ -26,7 +26,6 @@ pub struct Painter { configuration: WgpuConfiguration, options: RendererOptions, support_transparent_backbuffer: bool, - depth_format: Option, screen_capture_state: Option, instance: wgpu::Instance, @@ -56,7 +55,6 @@ impl Painter { pub async fn new( context: Context, configuration: WgpuConfiguration, - depth_format: Option, support_transparent_backbuffer: bool, options: RendererOptions, ) -> Self { @@ -68,7 +66,6 @@ impl Painter { configuration, options, support_transparent_backbuffer, - depth_format, screen_capture_state: None, instance, @@ -204,7 +201,6 @@ impl Painter { &self.configuration, &self.instance, Some(&surface), - self.depth_format, self.options, ) .await?; @@ -278,7 +274,7 @@ impl Painter { Self::configure_surface(surface_state, render_state, &self.configuration); - if let Some(depth_format) = self.depth_format { + if let Some(depth_format) = self.options.depth_stencil_format { self.depth_texture_view.insert( viewport_id, render_state