From 98e080410f6e0bf9d39d123c2c0ea84385f91dd3 Mon Sep 17 00:00:00 2001 From: Kevin Reid Date: Mon, 27 Jan 2025 09:14:20 -0800 Subject: [PATCH] Fix compatibility issues in hello_window example. (#7009) --- examples/README.md | 3 ++- examples/standalone/02_hello_window/src/main.rs | 12 ++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/examples/README.md b/examples/README.md index d00191c847..20bd282389 100644 --- a/examples/README.md +++ b/examples/README.md @@ -14,7 +14,8 @@ be cloned out of the repository to serve as a starting point for your own projec | Name | Description | Platforms | |--------|-------------|-----------| -| [hello compute](standalone/1_hello_compute/) | Simplest example and shows how to run a compute shader on a given set of input data and get the results back. | Native-Only | +| [hello compute](standalone/01_hello_compute/) | Simplest example and shows how to run a compute shader on a given set of input data and get the results back. | Native-Only | +| [hello window](standalone/02_hello_window/) | Shows how to create a window and render into it. | Native-Only | You can also use [`cargo-generate`](https://github.com/cargo-generate/cargo-generate) to easily use these as a basis for your own projects. diff --git a/examples/standalone/02_hello_window/src/main.rs b/examples/standalone/02_hello_window/src/main.rs index cfd1210e16..848e4e5f91 100644 --- a/examples/standalone/02_hello_window/src/main.rs +++ b/examples/standalone/02_hello_window/src/main.rs @@ -60,14 +60,13 @@ impl State { let surface_config = wgpu::SurfaceConfiguration { usage: wgpu::TextureUsages::RENDER_ATTACHMENT, format: self.surface_format, - // Without add_srgb_suffix() the image we will be working with - // might not be "gamma correct". + // Request compatibility with the sRGB-format texture view we‘re going to create later. view_formats: vec![self.surface_format.add_srgb_suffix()], alpha_mode: wgpu::CompositeAlphaMode::Auto, width: self.size.width, height: self.size.height, desired_maximum_frame_latency: 2, - present_mode: wgpu::PresentMode::Mailbox, + present_mode: wgpu::PresentMode::AutoVsync, }; self.surface.configure(&self.device, &surface_config); } @@ -87,7 +86,12 @@ impl State { .expect("failed to acquire next swapchain texture"); let texture_view = surface_texture .texture - .create_view(&wgpu::TextureViewDescriptor::default()); + .create_view(&wgpu::TextureViewDescriptor { + // Without add_srgb_suffix() the image we will be working with + // might not be "gamma correct". + format: Some(self.surface_format.add_srgb_suffix()), + ..Default::default() + }); // Renders a GREEN screen let mut encoder = self.device.create_command_encoder(&Default::default());