From 5330510a1ae9900859fc573913b4a4f583ecedd5 Mon Sep 17 00:00:00 2001 From: Rob Parrett Date: Tue, 29 Mar 2022 23:03:22 +0000 Subject: [PATCH] Clean up duplicated color conversion code (#4360) # 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 --- crates/bevy_sprite/src/render/mod.rs | 7 ++----- crates/bevy_ui/src/render/mod.rs | 6 +----- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/crates/bevy_sprite/src/render/mod.rs b/crates/bevy_sprite/src/render/mod.rs index 692cac7b3429a7..5ce2a809bfa904 100644 --- a/crates/bevy_sprite/src/render/mod.rs +++ b/crates/bevy_sprite/src/render/mod.rs @@ -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], diff --git a/crates/bevy_ui/src/render/mod.rs b/crates/bevy_ui/src/render/mod.rs index 66bf980263cd72..554c3b3e7e681f 100644 --- a/crates/bevy_ui/src/render/mod.rs +++ b/crates/bevy_ui/src/render/mod.rs @@ -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 {