Skip to content

Commit 7ff3d87

Browse files
committed
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
1 parent 954022c commit 7ff3d87

File tree

2 files changed

+3
-10
lines changed

2 files changed

+3
-10
lines changed

crates/bevy_sprite/src/render/mod.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -498,12 +498,9 @@ pub fn queue_sprites(
498498

499499
// Store the vertex data and add the item to the render phase
500500
if current_batch.colored {
501-
let color = extracted_sprite.color.as_linear_rgba_f32();
502501
// encode color as a single u32 to save space
503-
let color = (color[0] * 255.0) as u32
504-
| ((color[1] * 255.0) as u32) << 8
505-
| ((color[2] * 255.0) as u32) << 16
506-
| ((color[3] * 255.0) as u32) << 24;
502+
let color = extracted_sprite.color.as_linear_rgba_u32();
503+
507504
for i in QUAD_INDICES.iter() {
508505
sprite_meta.colored_vertices.push(ColoredSpriteVertex {
509506
position: positions[*i],

crates/bevy_ui/src/render/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -360,12 +360,8 @@ pub fn prepare_uinodes(
360360
]
361361
.map(|pos| pos / atlas_extent);
362362

363-
let color = extracted_uinode.color.as_linear_rgba_f32();
364363
// encode color as a single u32 to save space
365-
let color = (color[0] * 255.0) as u32
366-
| ((color[1] * 255.0) as u32) << 8
367-
| ((color[2] * 255.0) as u32) << 16
368-
| ((color[3] * 255.0) as u32) << 24;
364+
let color = extracted_uinode.color.as_linear_rgba_u32();
369365

370366
for i in QUAD_INDICES {
371367
ui_meta.vertices.push(UiVertex {

0 commit comments

Comments
 (0)