Unable to resize the depth buffer on WebGL2? #2120
-
I would like to resize the "renderer" when the HTML This works fine when using the examples, so its very possible I am doing something wrong. In my case it works only on Metal / Vulkan / DX12 (I was unable to test GL due to lack of fitting device). As far as I can tell I am doing the same as for example in the shadow example, so I really have no idea as to why this happens and would be grateful for any hint on this. My resize function looks like so: pub fn resize(&mut self, new_width: u32, new_height: u32) {
if new_width > 0 && new_height > 0 {
self.config.width = new_width;
self.config.height = new_height;
self.depth_texture =
texture::Texture::create_depth_texture(&self.device, &self.config, "depth_texture");
self.surface.configure(&self.device, &self.config);
}
} and pub fn create_depth_texture(
device: &wgpu::Device,
config: &wgpu::SurfaceConfiguration,
label: &str,
) -> wgpu::TextureView {
let size = wgpu::Extent3d {
width: config.width,
height: config.height,
depth_or_array_layers: 1,
};
let desc = wgpu::TextureDescriptor {
label: Some(label),
size,
mip_level_count: 1,
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Depth32Float,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT/* | wgpu::TextureUsages::TEXTURE_BINDING */,
};
let texture = device.create_texture(&desc);
texture.create_view(&wgpu::TextureViewDescriptor::default())
} now the problem is that once I call
and now whenever I call
The basic pub fn render(&mut self) -> Result<(), wgpu::SurfaceError> {
let output = self.surface.get_current_texture()?;
let view = output
.texture
.create_view(&wgpu::TextureViewDescriptor::default());
let mut encoder = self
.device
.create_command_encoder(&wgpu::CommandEncoderDescriptor {
label: Some("Render Encoder"),
});
{
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("Render Pass"),
color_attachments: &[wgpu::RenderPassColorAttachment {
view: &view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color {
r: 0.1,
g: 0.2,
b: 0.3,
a: 1.0,
}),
store: true,
},
}],
depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment {
view: &self.depth_texture_view,
depth_ops: Some(wgpu::Operations {
load: wgpu::LoadOp::Clear(1.0),
store: true,
}),
stencil_ops: None,
}),
});
render_pass.set_pipeline(&self.render_pipeline);
render_pass.set_bind_group(0, &self.diffuse_bind_group, &[]);
render_pass.set_bind_group(1, &self.camera_bind_group, &[]);
render_pass.set_bind_group(2, &self.light_bind_group, &[]);
render_pass.set_vertex_buffer(0, self.vertex_buffer.slice(..));
render_pass.draw(0..self.num_indices, 0..1);
}
self.queue.submit(std::iter::once(encoder.finish()));
output.present();
Ok(())
} This is the whole testbed / playground from where I have taken these snippets. Btw. due to the resize failing it is currently only triggered after the To test this with the event::Event::DeviceEvent { device_id: _, event: winit::event::DeviceEvent::MouseMotion { delta: _ } } => {
window.set_inner_size(winit::dpi::PhysicalSize::new(300, 100));
}, to the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
This was fixed in #2067 and already published. Please don't forget to do check if you are using the latest patch versions of wgpu! |
Beta Was this translation helpful? Give feedback.
This was fixed in #2067 and already published. Please don't forget to do check if you are using the latest patch versions of wgpu!