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

[Merged by Bors] - Add conversions from Color to u32 #4088

Closed
wants to merge 3 commits into from
Closed

[Merged by Bors] - Add conversions from Color to u32 #4088

wants to merge 3 commits into from

Conversation

Azorlogh
Copy link
Contributor

@Azorlogh Azorlogh commented Mar 3, 2022

Objective

Solution

  • Added Color::as_rgba_u32 and Color::as_linear_rgba_u32

@github-actions github-actions bot added the S-Needs-Triage This issue needs to be labelled label Mar 3, 2022
@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen C-Usability A simple quality-of-life change that makes Bevy easier to use and removed S-Needs-Triage This issue needs to be labelled labels Mar 3, 2022
Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thanks :)

Copy link
Contributor

@superdump superdump left a 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.

}
}

/// Converts a `Color` to a `u32` from linear RBG colorspace
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Converts a `Color` to a `u32` from linear RBG colorspace
/// Converts a `Color` to a `u32` from linear RGB colorspace

@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Mar 4, 2022
@@ -487,6 +487,92 @@ impl Color {
} => [hue, saturation, lightness, alpha],
}
}

/// Converts a `Color` to a `u32` from sRGB colorspace.
Copy link
Member

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// 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.

Copy link
Member

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 😄

@mockersf
Copy link
Member

mockersf commented Mar 8, 2022

bors r+

bors bot pushed a commit that referenced this pull request Mar 8, 2022
# 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`
@bors bors bot changed the title Add conversions from Color to u32 [Merged by Bors] - Add conversions from Color to u32 Mar 8, 2022
@bors bors bot closed this Mar 8, 2022
bors bot pushed a commit that referenced this pull request Mar 29, 2022
# 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
aevyrie pushed a commit to aevyrie/bevy that referenced this pull request Jun 7, 2022
# 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`
aevyrie pushed a commit to aevyrie/bevy that referenced this pull request Jun 7, 2022
# 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
ItsDoot pushed a commit to ItsDoot/bevy that referenced this pull request Feb 1, 2023
# 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`
ItsDoot pushed a commit to ItsDoot/bevy that referenced this pull request Feb 1, 2023
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Usability A simple quality-of-life change that makes Bevy easier to use S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants