Skip to content

Commit

Permalink
Fix compatibility issues in hello_window example. (#7009)
Browse files Browse the repository at this point in the history
  • Loading branch information
kpreid authored Jan 27, 2025
1 parent 321ee42 commit 98e0804
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
12 changes: 8 additions & 4 deletions examples/standalone/02_hello_window/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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());
Expand Down

0 comments on commit 98e0804

Please sign in to comment.