Skip to content

Commit

Permalink
Rename bevy_render::Color to LegacyColor (bevyengine#12069)
Browse files Browse the repository at this point in the history
# Objective

The migration process for `bevy_color` (bevyengine#12013) will be fairly involved:
there will be hundreds of affected files, and a large number of APIs.

## Solution

To allow us to proceed granularly, we're going to keep both
`bevy_color::Color` (new) and `bevy_render::Color` (old) around until
the migration is complete.

However, simply doing this directly is confusing! They're both called
`Color`, making it very hard to tell when a portion of the code has been
ported.

As discussed in bevyengine#12056, by renaming the old `Color` type, we can make it
easier to gradually migrate over, one API at a time.

## Migration Guide

THIS MIGRATION GUIDE INTENTIONALLY LEFT BLANK.

This change should not be shipped to end users: delete this section in
the final migration guide!

---------

Co-authored-by: Alice Cecile <[email protected]>
  • Loading branch information
2 people authored and msvbg committed Feb 26, 2024
1 parent 975e7c2 commit f940f78
Show file tree
Hide file tree
Showing 171 changed files with 1,209 additions and 1,165 deletions.
2 changes: 1 addition & 1 deletion crates/bevy_color/src/color.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{Alpha, Hsla, Lcha, LinearRgba, Oklaba, Srgba, StandardColor, Xyza};
use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize};
use bevy_render::color::Color as LegacyColor;
use bevy_render::color::LegacyColor;
use serde::{Deserialize, Serialize};

/// An enumerated type that can represent any of the color types in this crate.
Expand Down
10 changes: 5 additions & 5 deletions crates/bevy_color/src/hsla.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ impl From<Srgba> for Hsla {
}
}

impl From<Hsla> for bevy_render::color::Color {
impl From<Hsla> for bevy_render::color::LegacyColor {
fn from(value: Hsla) -> Self {
bevy_render::color::Color::Hsla {
bevy_render::color::LegacyColor::Hsla {
hue: value.hue,
saturation: value.saturation,
lightness: value.lightness,
Expand All @@ -147,10 +147,10 @@ impl From<Hsla> for bevy_render::color::Color {
}
}

impl From<bevy_render::color::Color> for Hsla {
fn from(value: bevy_render::color::Color) -> Self {
impl From<bevy_render::color::LegacyColor> for Hsla {
fn from(value: bevy_render::color::LegacyColor) -> Self {
match value.as_hsla() {
bevy_render::color::Color::Hsla {
bevy_render::color::LegacyColor::Hsla {
hue,
saturation,
lightness,
Expand Down
10 changes: 5 additions & 5 deletions crates/bevy_color/src/lcha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ impl From<Lcha> for LinearRgba {
}
}

impl From<Lcha> for bevy_render::color::Color {
impl From<Lcha> for bevy_render::color::LegacyColor {
fn from(value: Lcha) -> Self {
bevy_render::color::Color::Lcha {
bevy_render::color::LegacyColor::Lcha {
hue: value.hue,
chroma: value.chroma,
lightness: value.lightness,
Expand All @@ -168,10 +168,10 @@ impl From<Lcha> for bevy_render::color::Color {
}
}

impl From<bevy_render::color::Color> for Lcha {
fn from(value: bevy_render::color::Color) -> Self {
impl From<bevy_render::color::LegacyColor> for Lcha {
fn from(value: bevy_render::color::LegacyColor) -> Self {
match value.as_lcha() {
bevy_render::color::Color::Lcha {
bevy_render::color::LegacyColor::Lcha {
hue,
chroma,
lightness,
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_color/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub use oklaba::*;
pub use srgba::*;
pub use xyza::*;

use bevy_render::color::Color as LegacyColor;
use bevy_render::color::LegacyColor;

/// Describes the traits that a color should implement for consistency.
pub(crate) trait StandardColor
Expand Down
10 changes: 5 additions & 5 deletions crates/bevy_color/src/linear_rgba.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ impl From<Srgba> for LinearRgba {
}
}

impl From<LinearRgba> for bevy_render::color::Color {
impl From<LinearRgba> for bevy_render::color::LegacyColor {
fn from(value: LinearRgba) -> Self {
bevy_render::color::Color::RgbaLinear {
bevy_render::color::LegacyColor::RgbaLinear {
red: value.red,
green: value.green,
blue: value.blue,
Expand All @@ -183,10 +183,10 @@ impl From<LinearRgba> for bevy_render::color::Color {
}
}

impl From<bevy_render::color::Color> for LinearRgba {
fn from(value: bevy_render::color::Color) -> Self {
impl From<bevy_render::color::LegacyColor> for LinearRgba {
fn from(value: bevy_render::color::LegacyColor) -> Self {
match value.as_rgba_linear() {
bevy_render::color::Color::RgbaLinear {
bevy_render::color::LegacyColor::RgbaLinear {
red,
green,
blue,
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_color/src/oklaba.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
StandardColor,
};
use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize};
use bevy_render::color::Color as LegacyColor;
use bevy_render::color::LegacyColor;
use serde::{Deserialize, Serialize};

/// Color in Oklaba color space, with alpha
Expand Down
10 changes: 5 additions & 5 deletions crates/bevy_color/src/srgba.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@ impl From<Oklaba> for Srgba {
}
}

impl From<Srgba> for bevy_render::color::Color {
impl From<Srgba> for bevy_render::color::LegacyColor {
fn from(value: Srgba) -> Self {
bevy_render::color::Color::Rgba {
bevy_render::color::LegacyColor::Rgba {
red: value.red,
green: value.green,
blue: value.blue,
Expand All @@ -278,10 +278,10 @@ impl From<Srgba> for bevy_render::color::Color {
}
}

impl From<bevy_render::color::Color> for Srgba {
fn from(value: bevy_render::color::Color) -> Self {
impl From<bevy_render::color::LegacyColor> for Srgba {
fn from(value: bevy_render::color::LegacyColor) -> Self {
match value.as_rgba() {
bevy_render::color::Color::Rgba {
bevy_render::color::LegacyColor::Rgba {
red,
green,
blue,
Expand Down
8 changes: 4 additions & 4 deletions crates/bevy_color/src/xyza.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{Alpha, Hsla, Lcha, LinearRgba, Luminance, Mix, Oklaba, Srgba, StandardColor};
use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize};
use bevy_render::color::Color;
use bevy_render::color::LegacyColor;
use serde::{Deserialize, Serialize};

/// [CIE 1931](https://en.wikipedia.org/wiki/CIE_1931_color_space) color space, also known as XYZ, with an alpha channel.
Expand Down Expand Up @@ -208,13 +208,13 @@ impl From<Xyza> for Oklaba {
}
}

impl From<Color> for Xyza {
fn from(value: Color) -> Self {
impl From<LegacyColor> for Xyza {
fn from(value: LegacyColor) -> Self {
LinearRgba::from(value).into()
}
}

impl From<Xyza> for Color {
impl From<Xyza> for LegacyColor {
fn from(value: Xyza) -> Self {
LinearRgba::from(value).into()
}
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_core_pipeline/src/bloom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use bevy_render::{
extract_component::{
ComponentUniforms, DynamicUniformIndex, ExtractComponentPlugin, UniformComponentPlugin,
},
prelude::Color,
prelude::LegacyColor,
render_graph::{NodeRunError, RenderGraphApp, RenderGraphContext, ViewNode, ViewNodeRunner},
render_resource::*,
renderer::{RenderContext, RenderDevice},
Expand Down Expand Up @@ -240,7 +240,7 @@ impl ViewNode for BloomNode {
mip as f32,
(bloom_texture.mip_count - 1) as f32,
);
upsampling_pass.set_blend_constant(Color::rgb_linear(blend, blend, blend));
upsampling_pass.set_blend_constant(LegacyColor::rgb_linear(blend, blend, blend));
upsampling_pass.draw(0..3, 0..1);
}

Expand All @@ -267,7 +267,7 @@ impl ViewNode for BloomNode {
}
let blend =
compute_blend_factor(bloom_settings, 0.0, (bloom_texture.mip_count - 1) as f32);
upsampling_final_pass.set_blend_constant(Color::rgb_linear(blend, blend, blend));
upsampling_final_pass.set_blend_constant(LegacyColor::rgb_linear(blend, blend, blend));
upsampling_final_pass.draw(0..3, 0..1);
}

Expand Down
13 changes: 7 additions & 6 deletions crates/bevy_core_pipeline/src/core_3d/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ use bevy_app::{App, Plugin, PostUpdate};
use bevy_ecs::prelude::*;
use bevy_render::{
camera::{Camera, ExtractedCamera},
color::Color,
color::LegacyColor,
extract_component::ExtractComponentPlugin,
mesh::Mesh,
prelude::Msaa,
Expand Down Expand Up @@ -836,18 +836,19 @@ pub fn prepare_prepass_textures(
});

commands.entity(entity).insert(ViewPrepassTextures {
depth: cached_depth_texture.map(|t| ColorAttachment::new(t, None, Some(Color::BLACK))),
depth: cached_depth_texture
.map(|t| ColorAttachment::new(t, None, Some(LegacyColor::BLACK))),
normal: cached_normals_texture
.map(|t| ColorAttachment::new(t, None, Some(Color::BLACK))),
.map(|t| ColorAttachment::new(t, None, Some(LegacyColor::BLACK))),
// Red and Green channels are X and Y components of the motion vectors
// Blue channel doesn't matter, but set to 0.0 for possible faster clear
// https://gpuopen.com/performance/#clears
motion_vectors: cached_motion_vectors_texture
.map(|t| ColorAttachment::new(t, None, Some(Color::BLACK))),
.map(|t| ColorAttachment::new(t, None, Some(LegacyColor::BLACK))),
deferred: cached_deferred_texture
.map(|t| ColorAttachment::new(t, None, Some(Color::BLACK))),
.map(|t| ColorAttachment::new(t, None, Some(LegacyColor::BLACK))),
deferred_lighting_pass_id: cached_deferred_lighting_pass_id_texture
.map(|t| ColorAttachment::new(t, None, Some(Color::BLACK))),
.map(|t| ColorAttachment::new(t, None, Some(LegacyColor::BLACK))),
size,
});
}
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_core_pipeline/src/msaa_writeback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use bevy_app::{App, Plugin};
use bevy_ecs::prelude::*;
use bevy_render::{
camera::ExtractedCamera,
color::Color,
color::LegacyColor,
render_graph::{Node, NodeRunError, RenderGraphApp, RenderGraphContext},
render_resource::BindGroupEntries,
renderer::RenderContext,
Expand Down Expand Up @@ -93,7 +93,7 @@ impl Node for MsaaWritebackNode {
view: target.sampled_main_texture_view().unwrap(),
resolve_target: Some(post_process.destination),
ops: Operations {
load: LoadOp::Clear(Color::BLACK.into()),
load: LoadOp::Clear(LegacyColor::BLACK.into()),
store: StoreOp::Store,
},
})],
Expand Down
10 changes: 5 additions & 5 deletions crates/bevy_gizmos/src/aabb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use bevy_ecs::{
system::{Query, Res},
};
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use bevy_render::{color::Color, primitives::Aabb};
use bevy_render::{color::LegacyColor, primitives::Aabb};
use bevy_transform::{
components::{GlobalTransform, Transform},
TransformSystem,
Expand Down Expand Up @@ -57,7 +57,7 @@ pub struct AabbGizmoConfigGroup {
/// A random color is chosen per box if `None`.
///
/// Defaults to `None`.
pub default_color: Option<Color>,
pub default_color: Option<LegacyColor>,
}

/// Add this [`Component`] to an entity to draw its [`Aabb`] component.
Expand All @@ -67,7 +67,7 @@ pub struct ShowAabbGizmo {
/// The color of the box.
///
/// The default color from the [`AabbGizmoConfigGroup`] config is used if `None`,
pub color: Option<Color>,
pub color: Option<LegacyColor>,
}

fn draw_aabbs(
Expand Down Expand Up @@ -96,7 +96,7 @@ fn draw_all_aabbs(
}
}

fn color_from_entity(entity: Entity) -> Color {
fn color_from_entity(entity: Entity) -> LegacyColor {
let index = entity.index();

// from https://extremelearning.com.au/unreasonable-effectiveness-of-quasirandom-sequences/
Expand All @@ -108,7 +108,7 @@ fn color_from_entity(entity: Entity) -> Color {
const RATIO_360: f32 = 360.0 / u32::MAX as f32;
let hue = index.wrapping_mul(FRAC_U32MAX_GOLDEN_RATIO) as f32 * RATIO_360;

Color::hsl(hue, 1., 0.5)
LegacyColor::hsl(hue, 1., 0.5)
}

fn aabb_transform(aabb: Aabb, transform: GlobalTransform) -> GlobalTransform {
Expand Down
26 changes: 13 additions & 13 deletions crates/bevy_gizmos/src/arcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use crate::circles::DEFAULT_CIRCLE_SEGMENTS;
use crate::prelude::{GizmoConfigGroup, Gizmos};
use bevy_math::{Quat, Vec2, Vec3};
use bevy_render::color::Color;
use bevy_render::color::LegacyColor;
use std::f32::consts::TAU;

// === 2D ===
Expand All @@ -30,12 +30,12 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
/// # use bevy_math::prelude::*;
/// # use std::f32::consts::PI;
/// fn system(mut gizmos: Gizmos) {
/// gizmos.arc_2d(Vec2::ZERO, 0., PI / 4., 1., Color::GREEN);
/// gizmos.arc_2d(Vec2::ZERO, 0., PI / 4., 1., LegacyColor::GREEN);
///
/// // Arcs have 32 line-segments by default.
/// // You may want to increase this for larger arcs.
/// gizmos
/// .arc_2d(Vec2::ZERO, 0., PI / 4., 5., Color::RED)
/// .arc_2d(Vec2::ZERO, 0., PI / 4., 5., LegacyColor::RED)
/// .segments(64);
/// }
/// # bevy_ecs::system::assert_is_system(system);
Expand All @@ -47,7 +47,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
direction_angle: f32,
arc_angle: f32,
radius: f32,
color: Color,
color: LegacyColor,
) -> Arc2dBuilder<'_, 'w, 's, T> {
Arc2dBuilder {
gizmos: self,
Expand All @@ -68,7 +68,7 @@ pub struct Arc2dBuilder<'a, 'w, 's, T: GizmoConfigGroup> {
direction_angle: f32,
arc_angle: f32,
radius: f32,
color: Color,
color: LegacyColor,
segments: Option<usize>,
}

Expand Down Expand Up @@ -152,7 +152,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
/// 0.25,
/// Vec3::ONE,
/// rotation,
/// Color::ORANGE
/// LegacyColor::ORANGE
/// )
/// .segments(100);
/// }
Expand All @@ -165,7 +165,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
radius: f32,
position: Vec3,
rotation: Quat,
color: Color,
color: LegacyColor,
) -> Arc3dBuilder<'_, 'w, 's, T> {
Arc3dBuilder {
gizmos: self,
Expand Down Expand Up @@ -202,7 +202,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
/// Vec3::ONE,
/// Vec3::ONE + Vec3::NEG_ONE,
/// Vec3::ZERO,
/// Color::ORANGE
/// LegacyColor::ORANGE
/// )
/// .segments(100);
/// }
Expand All @@ -221,7 +221,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
center: Vec3,
from: Vec3,
to: Vec3,
color: Color,
color: LegacyColor,
) -> Arc3dBuilder<'_, 'w, 's, T> {
self.arc_from_to(center, from, to, color, |x| x)
}
Expand All @@ -248,7 +248,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
/// Vec3::ONE,
/// Vec3::ONE + Vec3::NEG_ONE,
/// Vec3::ZERO,
/// Color::ORANGE
/// LegacyColor::ORANGE
/// )
/// .segments(100);
/// }
Expand All @@ -267,7 +267,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
center: Vec3,
from: Vec3,
to: Vec3,
color: Color,
color: LegacyColor,
) -> Arc3dBuilder<'_, 'w, 's, T> {
self.arc_from_to(center, from, to, color, |angle| {
if angle > 0.0 {
Expand All @@ -286,7 +286,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
center: Vec3,
from: Vec3,
to: Vec3,
color: Color,
color: LegacyColor,
angle_fn: impl Fn(f32) -> f32,
) -> Arc3dBuilder<'_, 'w, 's, T> {
// `from` and `to` can be the same here since in either case nothing gets rendered and the
Expand Down Expand Up @@ -331,7 +331,7 @@ pub struct Arc3dBuilder<'a, 'w, 's, T: GizmoConfigGroup> {
rotation: Quat,
angle: f32,
radius: f32,
color: Color,
color: LegacyColor,
segments: Option<usize>,
}

Expand Down
Loading

0 comments on commit f940f78

Please sign in to comment.