Skip to content

Commit

Permalink
Clean up duplicated color conversion code (bevyengine#4360)
Browse files Browse the repository at this point in the history
# 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
  • Loading branch information
rparrett committed Mar 29, 2022
1 parent 954022c commit 7ff3d87
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
7 changes: 2 additions & 5 deletions crates/bevy_sprite/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,12 +498,9 @@ pub fn queue_sprites(

// Store the vertex data and add the item to the render phase
if current_batch.colored {
let color = extracted_sprite.color.as_linear_rgba_f32();
// encode color as a single u32 to save space
let color = (color[0] * 255.0) as u32
| ((color[1] * 255.0) as u32) << 8
| ((color[2] * 255.0) as u32) << 16
| ((color[3] * 255.0) as u32) << 24;
let color = extracted_sprite.color.as_linear_rgba_u32();

for i in QUAD_INDICES.iter() {
sprite_meta.colored_vertices.push(ColoredSpriteVertex {
position: positions[*i],
Expand Down
6 changes: 1 addition & 5 deletions crates/bevy_ui/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,8 @@ pub fn prepare_uinodes(
]
.map(|pos| pos / atlas_extent);

let color = extracted_uinode.color.as_linear_rgba_f32();
// encode color as a single u32 to save space
let color = (color[0] * 255.0) as u32
| ((color[1] * 255.0) as u32) << 8
| ((color[2] * 255.0) as u32) << 16
| ((color[3] * 255.0) as u32) << 24;
let color = extracted_uinode.color.as_linear_rgba_u32();

for i in QUAD_INDICES {
ui_meta.vertices.push(UiVertex {
Expand Down

0 comments on commit 7ff3d87

Please sign in to comment.