-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[Merged by Bors] - Add conversions from Color to u32 #4088
Conversation
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.
Looks good! Thanks :)
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.
Minor comment typo. LGTM.
crates/bevy_render/src/color/mod.rs
Outdated
} | ||
} | ||
|
||
/// Converts a `Color` to a `u32` from linear RBG colorspace |
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.
/// Converts a `Color` to a `u32` from linear RBG colorspace | |
/// Converts a `Color` to a `u32` from linear RGB colorspace |
crates/bevy_render/src/color/mod.rs
Outdated
@@ -487,6 +487,92 @@ impl Color { | |||
} => [hue, saturation, lightness, alpha], | |||
} | |||
} | |||
|
|||
/// Converts a `Color` to a `u32` from sRGB colorspace. |
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.
Would it makes sense to describe how the colour is converted to u32 (each channel as a u8, order as alpha-blue-green-red) or is it standard enough to do it that way?
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 think it should be described. Perhaps both endianness (it wasn’t obvious to me a while ago that GPUs were generally little endian) and order.
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.
Should I change the comment to the following?
Converts Color
to a u32
from sRGB colorspace, mapping the RGBA channels in this order to a little-endian byte array (meaning A will be the most significant byte and R the least significant).
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.
Sounds good to me.
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.
/// Converts a `Color` to a `u32` from sRGB colorspace. | |
/// Converts Color to a u32 from sRGB colorspace | |
/// | |
/// Maps the RGBA channels in RGBA order to a little-endian byte array (GPUs are little-endian). | |
/// A will be the most significant byte and R the least significant. |
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.
A will be the most significant byte
that took me two reads to understand, with "will" being also a noun 😄
bors r+ |
# Objective - `Mesh::ATTRIBUTE_COLOR` expects colors as `u32`s but there is no function for easy conversion. - See #4037 (review) ## Solution - Added `Color::as_rgba_u32` and `Color::as_linear_rgba_u32`
# Objective Cleans up some duplicated color -> u32 conversion code in `bevy_sprite` and `bevy_ui` ## Solution Use `as_linear_rgba_u32` which was added recently by #4088
# Objective - `Mesh::ATTRIBUTE_COLOR` expects colors as `u32`s but there is no function for easy conversion. - See bevyengine#4037 (review) ## Solution - Added `Color::as_rgba_u32` and `Color::as_linear_rgba_u32`
# Objective Cleans up some duplicated color -> u32 conversion code in `bevy_sprite` and `bevy_ui` ## Solution Use `as_linear_rgba_u32` which was added recently by bevyengine#4088
# Objective - `Mesh::ATTRIBUTE_COLOR` expects colors as `u32`s but there is no function for easy conversion. - See bevyengine#4037 (review) ## Solution - Added `Color::as_rgba_u32` and `Color::as_linear_rgba_u32`
# Objective Cleans up some duplicated color -> u32 conversion code in `bevy_sprite` and `bevy_ui` ## Solution Use `as_linear_rgba_u32` which was added recently by bevyengine#4088
Objective
Mesh::ATTRIBUTE_COLOR
expects colors asu32
s but there is no function for easy conversion.Solution
Color::as_rgba_u32
andColor::as_linear_rgba_u32