-
Notifications
You must be signed in to change notification settings - Fork 950
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
Add back get_preferred_format and sRGB preference #2785
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3447,13 +3447,32 @@ impl Drop for SurfaceTexture { | |
|
||
impl Surface { | ||
/// Returns a vec of supported texture formats to use for the [`Surface`] with this adapter. | ||
/// Note: The first format in the vector is preferred | ||
/// | ||
/// Returns None if the surface is incompatible with the adapter. | ||
pub fn get_supported_formats(&self, adapter: &Adapter) -> Option<Vec<TextureFormat>> { | ||
Context::surface_get_supported_formats(&*self.context, &self.id, &adapter.id) | ||
} | ||
|
||
/// Returns an optimal texture format to use for the [`Surface`] with this adapter. | ||
pub fn get_preferred_format(&self, adapter: &Adapter) -> Option<wgt::TextureFormat> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of doing this separately, both methods of "preferred" format should return the same value. How about inside of get_supported_formats we just bring the srgb formats to the front - |
||
// Check the four formats mentioned in the WebGPU spec. | ||
// Also, prefer sRGB over linear as it is better in | ||
// representing perceived colors. | ||
let preferred_formats = [ | ||
wgt::TextureFormat::Bgra8UnormSrgb, | ||
wgt::TextureFormat::Rgba8UnormSrgb, | ||
wgt::TextureFormat::Bgra8Unorm, | ||
wgt::TextureFormat::Rgba8Unorm, | ||
wgt::TextureFormat::Rgba16Float, | ||
]; | ||
|
||
let formats = self.get_supported_formats(adapter)?; | ||
preferred_formats | ||
.iter() | ||
.cloned() | ||
.find(|preferred| formats.contains(preferred)) | ||
} | ||
|
||
/// Initializes [`Surface`] for presentation. | ||
/// | ||
/// # Panics | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sold on needing a separate api here - especially if we remove the outer option.