-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[wgpu] Add depth stencil initialization to Painter
#2316
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
putting this into paint_and_update_textures
doesn't really make sense as we don't check for a configured surface every frame either. Also don't quite understand why you're doing map().iter().for_each
on a single element - you can just map to the correct thing right away :).
Anyways, it would be best if set_window
would do the same on Some(window)
as on_window_resized
does on self.surface_state.is_some()
.
I.e. best to put
self.configure_surface(width_in_pixels, height_in_pixels);
let device = &self.render_state.as_ref().unwrap().device;
self.depth_texture_view = self.depth_format.map(|depth_format| {
device
.create_texture(&wgpu::TextureDescriptor {
label: Some("egui_depth_texture"),
size: wgpu::Extent3d {
width: width_in_pixels,
height: height_in_pixels,
depth_or_array_layers: 1,
},
mip_level_count: 1,
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format: depth_format,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT
| wgpu::TextureUsages::TEXTURE_BINDING,
})
.create_view(&wgpu::TextureViewDescriptor::default())
});
into a function and call it at both locations. If that's unclear I can help out!
…ture_view`, and call it in `set_window` and `on_window_resized`
@Wumpf thanks for explaining! Also feel free to suggest a better name for the texture view generator than |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great and thanks for contributing!
I added a change-log entry myself since I forgot to mention that earlier (:
I was getting panics in the
egui_demo_app
when using a depth buffer. To add the depth buffer I had modified:and
I realized that because the first frame can render before the window is set, it is possible for
depth_buffer
to exist, whiledepth_texture_view
to beNone
. This check stopped the crash for me, but if there is an issue with this solution I would be happy to refactor.