Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix expecting always Rgba8Unorm backbuffer on Web & Bgra8Unorm on native #1413

Merged
merged 2 commits into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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