-
-
Couldn't load subscription status.
- Fork 4.2k
Port bevy_core_pipeline to LinearRgba
#12116
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
Changes from all commits
db5157c
deee6c4
22ce9f6
6d0c7e6
7c85c0e
d25a008
df70ae3
423bc0b
f0c8414
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 |
|---|---|---|
|
|
@@ -23,6 +23,30 @@ pub struct LinearRgba { | |
| impl StandardColor for LinearRgba {} | ||
|
|
||
| impl LinearRgba { | ||
| /// A fully black color with full alpha. | ||
| pub const BLACK: Self = Self { | ||
| red: 0.0, | ||
| green: 0.0, | ||
| blue: 0.0, | ||
| alpha: 1.0, | ||
| }; | ||
|
|
||
| /// A fully white color with full alpha. | ||
| pub const WHITE: Self = Self { | ||
| red: 1.0, | ||
| green: 1.0, | ||
| blue: 1.0, | ||
| alpha: 1.0, | ||
| }; | ||
|
|
||
| /// A fully transparent color. | ||
| pub const NONE: Self = Self { | ||
| red: 0.0, | ||
| green: 0.0, | ||
| blue: 0.0, | ||
| alpha: 0.0, | ||
| }; | ||
|
|
||
| /// Construct a new [`LinearRgba`] color from components. | ||
| pub const fn new(red: f32, green: f32, blue: f32, alpha: f32) -> Self { | ||
| Self { | ||
|
|
@@ -49,6 +73,18 @@ impl LinearRgba { | |
| } | ||
| } | ||
|
|
||
| /// Construct a new [`LinearRgba`] color with the same value for all channels and an alpha of 1.0. | ||
| /// | ||
| /// A value of 0.0 is black, and a value of 1.0 is white. | ||
| pub const fn gray(value: f32) -> Self { | ||
| Self { | ||
| red: value, | ||
| green: value, | ||
| blue: value, | ||
| alpha: 1.0, | ||
| } | ||
| } | ||
|
|
||
| /// Return a copy of this color with the red channel set to the given value. | ||
| pub const fn with_red(self, red: f32) -> Self { | ||
| Self { red, ..self } | ||
|
|
@@ -81,12 +117,7 @@ impl LinearRgba { | |
| impl Default for LinearRgba { | ||
| /// Construct a new [`LinearRgba`] color with the default values (white with full alpha). | ||
| fn default() -> Self { | ||
| Self { | ||
| red: 1., | ||
| green: 1., | ||
| blue: 1., | ||
| alpha: 1., | ||
| } | ||
| Self::WHITE | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -205,6 +236,17 @@ impl From<Hsla> for LinearRgba { | |
| } | ||
| } | ||
|
|
||
| impl From<LinearRgba> for wgpu::Color { | ||
| fn from(color: LinearRgba) -> Self { | ||
| wgpu::Color { | ||
| r: color.red as f64, | ||
| g: color.green as f64, | ||
| b: color.blue as f64, | ||
| a: color.alpha as f64, | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+239
to
+248
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. Since 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. That's a good question. I think that should be investigated after migration: then we can get both benchmark results and see if there's meaningfully improved color fidelity or numerical stability. 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. Probably won't make a big difference on the code-path where 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. Well, at this rate I guess we're getting |
||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.