Skip to content
This repository was archived by the owner on Jun 18, 2021. It is now read-only.

Commit 423f576

Browse files
committed
Use srgb for swapchain when possible
1 parent bbbeb24 commit 423f576

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

examples/framework.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,12 @@ async fn run_async<E: Example>(event_loop: EventLoop<()>, window: Window) {
7676

7777
let mut sc_desc = wgpu::SwapChainDescriptor {
7878
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT,
79-
format: wgpu::TextureFormat::Bgra8Unorm,
79+
// TODO: Allow srgb unconditionally
80+
format: if cfg!(target_arch = "wasm32") {
81+
wgpu::TextureFormat::Bgra8Unorm
82+
} else {
83+
wgpu::TextureFormat::Bgra8UnormSrgb
84+
},
8085
width: size.width,
8186
height: size.height,
8287
present_mode: wgpu::PresentMode::Mailbox,

examples/hello-triangle/main.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use winit::{
44
window::Window,
55
};
66

7-
async fn run(event_loop: EventLoop<()>, window: Window) {
7+
async fn run(event_loop: EventLoop<()>, window: Window, swapchain_format: wgpu::TextureFormat) {
88
let size = window.inner_size();
99
let surface = wgpu::Surface::create(&window);
1010

@@ -84,7 +84,7 @@ async fn run(event_loop: EventLoop<()>, window: Window) {
8484

8585
let mut sc_desc = wgpu::SwapChainDescriptor {
8686
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT,
87-
format: wgpu::TextureFormat::Bgra8Unorm,
87+
format: swapchain_format,
8888
width: size.width,
8989
height: size.height,
9090
present_mode: wgpu::PresentMode::Mailbox,
@@ -143,7 +143,8 @@ fn main() {
143143
#[cfg(not(target_arch = "wasm32"))]
144144
{
145145
env_logger::init();
146-
futures::executor::block_on(run(event_loop, window));
146+
// Temporarily avoid srgb formats for the swapchain on the web
147+
futures::executor::block_on(run(event_loop, window, wgpu::TextureFormat::Bgra8Unorm));
147148
}
148149
#[cfg(target_arch = "wasm32")]
149150
{
@@ -159,6 +160,10 @@ fn main() {
159160
.ok()
160161
})
161162
.expect("couldn't append canvas to document body");
162-
wasm_bindgen_futures::spawn_local(run(event_loop, window));
163+
wasm_bindgen_futures::spawn_local(run(
164+
event_loop,
165+
window,
166+
wgpu::TextureFormat::Bgra8UnormSrgb,
167+
));
163168
}
164169
}

0 commit comments

Comments
 (0)