various fixes

- Renames `Drawer::view` to `Drawer::surface_view`.
- Only set present mode if it's supported in `set_render_mode`.
- Don't create view in `Drawer::drop`.
- Format changes.
This commit is contained in:
Isse 2024-01-28 08:58:57 +01:00 committed by Marcel Märtens
parent 6d45d21d95
commit 2f544868ef
3 changed files with 14 additions and 25 deletions

View File

@ -185,6 +185,7 @@ pub struct Renderer {
/// The texture format used for the intermediate rendering passes /// The texture format used for the intermediate rendering passes
intermediate_format: wgpu::TextureFormat, intermediate_format: wgpu::TextureFormat,
/// Supported present modes.
present_modes: Vec<PresentMode>, present_modes: Vec<PresentMode>,
} }
@ -649,17 +650,10 @@ impl Renderer {
if self.other_modes != other_modes { if self.other_modes != other_modes {
self.other_modes = other_modes; self.other_modes = other_modes;
// Update present mode in swap chain descriptor // Update present mode in swap chain descriptor if it is supported.
self.surface_config.present_mode = if self.present_modes.contains(&self.other_modes.present_mode) {
if self.present_modes.contains(&self.other_modes.present_mode) { self.surface_config.present_mode = self.other_modes.present_mode.into()
self.other_modes.present_mode }
} else {
*self
.present_modes
.first()
.expect("There should never be no supported present modes")
}
.into();
// Only enable profiling if the wgpu features are enabled // Only enable profiling if the wgpu features are enabled
self.other_modes.profiler_enabled &= self.profiler_features_enabled; self.other_modes.profiler_enabled &= self.profiler_features_enabled;

View File

@ -87,7 +87,7 @@ struct RendererBorrow<'frame> {
} }
pub struct Drawer<'frame> { pub struct Drawer<'frame> {
view: wgpu::TextureView, surface_view: wgpu::TextureView,
encoder: Option<ManualOwningScope<'frame, wgpu::CommandEncoder>>, encoder: Option<ManualOwningScope<'frame, wgpu::CommandEncoder>>,
borrow: RendererBorrow<'frame>, borrow: RendererBorrow<'frame>,
surface_texture: Option<wgpu::SurfaceTexture>, surface_texture: Option<wgpu::SurfaceTexture>,
@ -143,7 +143,7 @@ impl<'frame> Drawer<'frame> {
ManualOwningScope::start("frame", &mut renderer.profiler, encoder, borrow.device); ManualOwningScope::start("frame", &mut renderer.profiler, encoder, borrow.device);
// Create a view to the surface texture. // Create a view to the surface texture.
let view = surface_texture let surface_view = surface_texture
.texture .texture
.create_view(&wgpu::TextureViewDescriptor { .create_view(&wgpu::TextureViewDescriptor {
label: Some("Surface texture view"), label: Some("Surface texture view"),
@ -151,7 +151,7 @@ impl<'frame> Drawer<'frame> {
}); });
Self { Self {
view, surface_view,
encoder: Some(encoder), encoder: Some(encoder),
borrow, borrow,
surface_texture: Some(surface_texture), surface_texture: Some(surface_texture),
@ -514,6 +514,7 @@ impl<'frame> Drawer<'frame> {
/// to complete any pending image uploads for the UI. /// to complete any pending image uploads for the UI.
pub fn third_pass(&mut self) -> ThirdPassDrawer { pub fn third_pass(&mut self) -> ThirdPassDrawer {
self.run_ui_premultiply_passes(); self.run_ui_premultiply_passes();
let encoder = self.encoder.as_mut().unwrap(); let encoder = self.encoder.as_mut().unwrap();
let device = self.borrow.device; let device = self.borrow.device;
let mut render_pass = let mut render_pass =
@ -525,7 +526,7 @@ impl<'frame> Drawer<'frame> {
view: self view: self
.taking_screenshot .taking_screenshot
.as_ref() .as_ref()
.map_or(&self.view, |s| s.texture_view()), .map_or(&self.surface_view, |s| s.texture_view()),
resolve_target: None, resolve_target: None,
ops: wgpu::Operations { ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color::TRANSPARENT), load: wgpu::LoadOp::Clear(wgpu::Color::TRANSPARENT),
@ -580,7 +581,7 @@ impl<'frame> Drawer<'frame> {
self.encoder.as_mut().unwrap(), self.encoder.as_mut().unwrap(),
self.taking_screenshot self.taking_screenshot
.as_ref() .as_ref()
.map_or(&self.view, |s| s.texture_view()), .map_or(&self.surface_view, |s| s.texture_view()),
&paint_jobs, &paint_jobs,
&screen_descriptor, &screen_descriptor,
None, None,
@ -754,13 +755,6 @@ impl<'frame> Drop for Drawer<'frame> {
.take() .take()
.zip(self.borrow.pipelines.blit()) .zip(self.borrow.pipelines.blit())
.map(|(screenshot, blit)| { .map(|(screenshot, blit)| {
let view = self.surface_texture.as_ref().unwrap().texture.create_view(
&wgpu::TextureViewDescriptor {
label: Some("Surface texture view"),
..Default::default()
},
);
// Image needs to be copied from the screenshot texture to the swapchain texture // Image needs to be copied from the screenshot texture to the swapchain texture
let mut render_pass = encoder.scoped_render_pass( let mut render_pass = encoder.scoped_render_pass(
"screenshot blit", "screenshot blit",
@ -768,7 +762,7 @@ impl<'frame> Drop for Drawer<'frame> {
&wgpu::RenderPassDescriptor { &wgpu::RenderPassDescriptor {
label: Some("Blit screenshot pass"), label: Some("Blit screenshot pass"),
color_attachments: &[Some(wgpu::RenderPassColorAttachment { color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &view, view: &self.surface_view,
resolve_target: None, resolve_target: None,
ops: wgpu::Operations { ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color::TRANSPARENT), load: wgpu::LoadOp::Clear(wgpu::Color::TRANSPARENT),

View File

@ -1039,9 +1039,10 @@ impl Window {
pub fn is_cursor_grabbed(&self) -> bool { self.cursor_grabbed } pub fn is_cursor_grabbed(&self) -> bool { self.cursor_grabbed }
pub fn grab_cursor(&mut self, grab: bool) { pub fn grab_cursor(&mut self, grab: bool) {
use winit::window::CursorGrabMode;
self.cursor_grabbed = grab; self.cursor_grabbed = grab;
self.window.set_cursor_visible(!grab); self.window.set_cursor_visible(!grab);
use winit::window::CursorGrabMode;
let res = if grab { let res = if grab {
self.window self.window
.set_cursor_grab(CursorGrabMode::Locked) .set_cursor_grab(CursorGrabMode::Locked)