1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-03 15:20:05 -04:00

Add depth buffer support for egui-wgpu's render pass (#2002)

* add a depth texture for wgpu callbacks

* egui-wgpu: use depth from native_options

* add wgpu caveat to depth_buffer docstring
This commit is contained in:
Romet Tagobert
2022-09-06 15:37:07 +03:00
committed by GitHub
parent 162210f90e
commit 64aac30f36
4 changed files with 70 additions and 5 deletions

View File

@@ -30,6 +30,7 @@ pub struct Painter<'a> {
device_descriptor: wgpu::DeviceDescriptor<'a>,
present_mode: wgpu::PresentMode,
msaa_samples: u32,
depth_bits: u8,
instance: Instance,
adapter: Option<Adapter>,
@@ -56,6 +57,7 @@ impl<'a> Painter<'a> {
device_descriptor: wgpu::DeviceDescriptor<'a>,
present_mode: wgpu::PresentMode,
msaa_samples: u32,
depth_bits: u8,
) -> Self {
let instance = wgpu::Instance::new(backends);
@@ -64,6 +66,7 @@ impl<'a> Painter<'a> {
device_descriptor,
present_mode,
msaa_samples,
depth_bits,
instance,
adapter: None,
@@ -87,7 +90,8 @@ impl<'a> Painter<'a> {
let (device, queue) =
pollster::block_on(adapter.request_device(&self.device_descriptor, None)).unwrap();
let rpass = renderer::RenderPass::new(&device, target_format, self.msaa_samples);
let rpass =
renderer::RenderPass::new(&device, target_format, self.msaa_samples, self.depth_bits);
RenderState {
device: Arc::new(device),
@@ -145,6 +149,14 @@ impl<'a> Painter<'a> {
.configure(&render_state.device, &config);
surface_state.width = width_in_pixels;
surface_state.height = height_in_pixels;
if self.depth_bits > 0 {
render_state.egui_rpass.write().update_depth_texture(
&render_state.device,
width_in_pixels,
height_in_pixels,
);
}
}
/// Updates (or clears) the [`winit::window::Window`] associated with the [`Painter`]