Skip to content

Commit

Permalink
select format capability (ref #122)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphamorim committed Jul 12, 2023
1 parent 7ebb007 commit c1e5dfd
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 29 deletions.
25 changes: 2 additions & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ bytemuck = { version = "1.13.1", features = [ "derive" ] }
log = "0.4.18"
serde = { version = "1.0.163", features = ["derive"] }
teletypewriter = { path = "teletypewriter" }
sugarloaf = { path = "sugarloaf" }
corcovado = { path = "corcovado" }
tokio = { version = "1.26.0", features = ["full"] }
wgpu = "0.16.2"
Expand Down
2 changes: 1 addition & 1 deletion rio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ libc = { workspace = true }
log = { workspace = true }
parking_lot = "0.12"
serde = { workspace = true }
sugarloaf = "0.0.7"
sugarloaf = { workspace = true }
teletypewriter = { workspace = true }
tokio = { version = "1.26.0", features = ["full"] }
unicode-width = "0.1.5"
Expand Down
20 changes: 15 additions & 5 deletions sugarloaf/src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,24 @@ impl Context {
log::info!("Selected adapter: {:?}", adapter.get_info());

let caps = surface.get_capabilities(&adapter);
let format = caps
.formats

// TODO: Fix formats with signs
let unsupported_formats = wgpu::TextureFormat::Rgb10a2Unorm;
let filtered_formats: Vec<wgpu::TextureFormat> = caps.formats
.iter()
.copied()
.find(wgpu::TextureFormat::is_srgb)
.or_else(|| caps.formats.first().copied())
.expect("Get preferred format");
.filter(|&x| {
x != unsupported_formats &&
wgpu::TextureFormat::has_color_aspect(&x)
})
.collect();

let mut format: wgpu::TextureFormat = caps.formats.first().unwrap().to_owned();
if !filtered_formats.is_empty() {
format = filtered_formats.last().unwrap().to_owned();
}

log::info!("Sugarloaf selected format: {format:?} from {:?}", caps.formats);
let (device, queue) = (async {
{
if let Ok(result) = adapter
Expand Down

0 comments on commit c1e5dfd

Please sign in to comment.