Skip to content

Commit

Permalink
Fix expecting always Rgba8Unorm backbuffer on Web & Bgra8Unorm on nat…
Browse files Browse the repository at this point in the history
…ive (#1413)
  • Loading branch information
Wumpf authored and emilk committed Mar 2, 2023
1 parent 7479ea9 commit 5467167
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@
"cSpell.words": [
"andreas",
"bbox",
"framebuffer",
"hoverable",
"Keypoint",
"memoffset",
"nyud",
"objectron",
"Skybox",
"smallvec",
"swapchain",
"texcoords",
"Tonemapper",
"tonemapping",
Expand Down
22 changes: 15 additions & 7 deletions crates/re_renderer/examples/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,19 @@ struct Application<E> {
re_ctx: RenderContext,
}

// Same as egui_wgpu::preferred_framebuffer_format
fn preferred_framebuffer_format(formats: &[wgpu::TextureFormat]) -> wgpu::TextureFormat {
for &format in formats {
if matches!(
format,
wgpu::TextureFormat::Rgba8Unorm | wgpu::TextureFormat::Bgra8Unorm
) {
return format;
}
}
formats[0] // take the first
}

impl<E: Example + 'static> Application<E> {
async fn new(event_loop: EventLoop<()>, window: Window) -> anyhow::Result<Self> {
let size = window.inner_size();
Expand Down Expand Up @@ -124,13 +137,8 @@ impl<E: Example + 'static> Application<E> {
let device = Arc::new(device);
let queue = Arc::new(queue);

// re_renderer is doing its own srgb conversion for each ViewBuilder for better egui compatibility.
let swapchain_format = if cfg!(target_arch = "wasm32") {
wgpu::TextureFormat::Rgba8Unorm
} else {
wgpu::TextureFormat::Bgra8Unorm
};

let swapchain_format =
preferred_framebuffer_format(&surface.get_capabilities(&adapter).formats);
let surface_config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: swapchain_format,
Expand Down
9 changes: 1 addition & 8 deletions crates/re_viewer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,11 @@ pub(crate) fn customize_eframe(cc: &eframe::CreationContext<'_>) -> re_ui::ReUi

let paint_callback_resources = &mut render_state.renderer.write().paint_callback_resources;

// TODO(andreas): Query used surface format from eframe/renderer.
let output_format_color = if cfg!(target_arch = "wasm32") {
wgpu::TextureFormat::Rgba8Unorm
} else {
wgpu::TextureFormat::Bgra8Unorm
};

paint_callback_resources.insert(RenderContext::new(
render_state.device.clone(),
render_state.queue.clone(),
RenderContextConfig {
output_format_color,
output_format_color: render_state.target_format,
hardware_tier: crate::hardware_tier(),
},
));
Expand Down

0 comments on commit 5467167

Please sign in to comment.