Skip to content

Commit de004da

Browse files
alice-i-cecileAlice Cecile
and
Alice Cecile
authored
Rename bevy_render::Color to LegacyColor (#12069)
# Objective The migration process for `bevy_color` (#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 #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]>
1 parent 10aef14 commit de004da

File tree

171 files changed

+1209
-1165
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

171 files changed

+1209
-1165
lines changed

crates/bevy_color/src/color.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{Alpha, Hsla, Lcha, LinearRgba, Oklaba, Srgba, StandardColor, Xyza};
22
use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize};
3-
use bevy_render::color::Color as LegacyColor;
3+
use bevy_render::color::LegacyColor;
44
use serde::{Deserialize, Serialize};
55

66
/// An enumerated type that can represent any of the color types in this crate.

crates/bevy_color/src/hsla.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ impl From<Srgba> for Hsla {
136136
}
137137
}
138138

139-
impl From<Hsla> for bevy_render::color::Color {
139+
impl From<Hsla> for bevy_render::color::LegacyColor {
140140
fn from(value: Hsla) -> Self {
141-
bevy_render::color::Color::Hsla {
141+
bevy_render::color::LegacyColor::Hsla {
142142
hue: value.hue,
143143
saturation: value.saturation,
144144
lightness: value.lightness,
@@ -147,10 +147,10 @@ impl From<Hsla> for bevy_render::color::Color {
147147
}
148148
}
149149

150-
impl From<bevy_render::color::Color> for Hsla {
151-
fn from(value: bevy_render::color::Color) -> Self {
150+
impl From<bevy_render::color::LegacyColor> for Hsla {
151+
fn from(value: bevy_render::color::LegacyColor) -> Self {
152152
match value.as_hsla() {
153-
bevy_render::color::Color::Hsla {
153+
bevy_render::color::LegacyColor::Hsla {
154154
hue,
155155
saturation,
156156
lightness,

crates/bevy_color/src/lcha.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ impl From<Lcha> for LinearRgba {
157157
}
158158
}
159159

160-
impl From<Lcha> for bevy_render::color::Color {
160+
impl From<Lcha> for bevy_render::color::LegacyColor {
161161
fn from(value: Lcha) -> Self {
162-
bevy_render::color::Color::Lcha {
162+
bevy_render::color::LegacyColor::Lcha {
163163
hue: value.hue,
164164
chroma: value.chroma,
165165
lightness: value.lightness,
@@ -168,10 +168,10 @@ impl From<Lcha> for bevy_render::color::Color {
168168
}
169169
}
170170

171-
impl From<bevy_render::color::Color> for Lcha {
172-
fn from(value: bevy_render::color::Color) -> Self {
171+
impl From<bevy_render::color::LegacyColor> for Lcha {
172+
fn from(value: bevy_render::color::LegacyColor) -> Self {
173173
match value.as_lcha() {
174-
bevy_render::color::Color::Lcha {
174+
bevy_render::color::LegacyColor::Lcha {
175175
hue,
176176
chroma,
177177
lightness,

crates/bevy_color/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub use oklaba::*;
9595
pub use srgba::*;
9696
pub use xyza::*;
9797

98-
use bevy_render::color::Color as LegacyColor;
98+
use bevy_render::color::LegacyColor;
9999

100100
/// Describes the traits that a color should implement for consistency.
101101
pub(crate) trait StandardColor

crates/bevy_color/src/linear_rgba.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,9 @@ impl From<Srgba> for LinearRgba {
172172
}
173173
}
174174

175-
impl From<LinearRgba> for bevy_render::color::Color {
175+
impl From<LinearRgba> for bevy_render::color::LegacyColor {
176176
fn from(value: LinearRgba) -> Self {
177-
bevy_render::color::Color::RgbaLinear {
177+
bevy_render::color::LegacyColor::RgbaLinear {
178178
red: value.red,
179179
green: value.green,
180180
blue: value.blue,
@@ -183,10 +183,10 @@ impl From<LinearRgba> for bevy_render::color::Color {
183183
}
184184
}
185185

186-
impl From<bevy_render::color::Color> for LinearRgba {
187-
fn from(value: bevy_render::color::Color) -> Self {
186+
impl From<bevy_render::color::LegacyColor> for LinearRgba {
187+
fn from(value: bevy_render::color::LegacyColor) -> Self {
188188
match value.as_rgba_linear() {
189-
bevy_render::color::Color::RgbaLinear {
189+
bevy_render::color::LegacyColor::RgbaLinear {
190190
red,
191191
green,
192192
blue,

crates/bevy_color/src/oklaba.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{
33
StandardColor,
44
};
55
use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize};
6-
use bevy_render::color::Color as LegacyColor;
6+
use bevy_render::color::LegacyColor;
77
use serde::{Deserialize, Serialize};
88

99
/// Color in Oklaba color space, with alpha

crates/bevy_color/src/srgba.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,9 @@ impl From<Oklaba> for Srgba {
267267
}
268268
}
269269

270-
impl From<Srgba> for bevy_render::color::Color {
270+
impl From<Srgba> for bevy_render::color::LegacyColor {
271271
fn from(value: Srgba) -> Self {
272-
bevy_render::color::Color::Rgba {
272+
bevy_render::color::LegacyColor::Rgba {
273273
red: value.red,
274274
green: value.green,
275275
blue: value.blue,
@@ -278,10 +278,10 @@ impl From<Srgba> for bevy_render::color::Color {
278278
}
279279
}
280280

281-
impl From<bevy_render::color::Color> for Srgba {
282-
fn from(value: bevy_render::color::Color) -> Self {
281+
impl From<bevy_render::color::LegacyColor> for Srgba {
282+
fn from(value: bevy_render::color::LegacyColor) -> Self {
283283
match value.as_rgba() {
284-
bevy_render::color::Color::Rgba {
284+
bevy_render::color::LegacyColor::Rgba {
285285
red,
286286
green,
287287
blue,

crates/bevy_color/src/xyza.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{Alpha, Hsla, Lcha, LinearRgba, Luminance, Mix, Oklaba, Srgba, StandardColor};
22
use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize};
3-
use bevy_render::color::Color;
3+
use bevy_render::color::LegacyColor;
44
use serde::{Deserialize, Serialize};
55

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

211-
impl From<Color> for Xyza {
212-
fn from(value: Color) -> Self {
211+
impl From<LegacyColor> for Xyza {
212+
fn from(value: LegacyColor) -> Self {
213213
LinearRgba::from(value).into()
214214
}
215215
}
216216

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

crates/bevy_core_pipeline/src/bloom/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use bevy_render::{
1717
extract_component::{
1818
ComponentUniforms, DynamicUniformIndex, ExtractComponentPlugin, UniformComponentPlugin,
1919
},
20-
prelude::Color,
20+
prelude::LegacyColor,
2121
render_graph::{NodeRunError, RenderGraphApp, RenderGraphContext, ViewNode, ViewNodeRunner},
2222
render_resource::*,
2323
renderer::{RenderContext, RenderDevice},
@@ -240,7 +240,7 @@ impl ViewNode for BloomNode {
240240
mip as f32,
241241
(bloom_texture.mip_count - 1) as f32,
242242
);
243-
upsampling_pass.set_blend_constant(Color::rgb_linear(blend, blend, blend));
243+
upsampling_pass.set_blend_constant(LegacyColor::rgb_linear(blend, blend, blend));
244244
upsampling_pass.draw(0..3, 0..1);
245245
}
246246

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

crates/bevy_core_pipeline/src/core_3d/mod.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ use bevy_app::{App, Plugin, PostUpdate};
4949
use bevy_ecs::prelude::*;
5050
use bevy_render::{
5151
camera::{Camera, ExtractedCamera},
52-
color::Color,
52+
color::LegacyColor,
5353
extract_component::ExtractComponentPlugin,
5454
mesh::Mesh,
5555
prelude::Msaa,
@@ -836,18 +836,19 @@ pub fn prepare_prepass_textures(
836836
});
837837

838838
commands.entity(entity).insert(ViewPrepassTextures {
839-
depth: cached_depth_texture.map(|t| ColorAttachment::new(t, None, Some(Color::BLACK))),
839+
depth: cached_depth_texture
840+
.map(|t| ColorAttachment::new(t, None, Some(LegacyColor::BLACK))),
840841
normal: cached_normals_texture
841-
.map(|t| ColorAttachment::new(t, None, Some(Color::BLACK))),
842+
.map(|t| ColorAttachment::new(t, None, Some(LegacyColor::BLACK))),
842843
// Red and Green channels are X and Y components of the motion vectors
843844
// Blue channel doesn't matter, but set to 0.0 for possible faster clear
844845
// https://gpuopen.com/performance/#clears
845846
motion_vectors: cached_motion_vectors_texture
846-
.map(|t| ColorAttachment::new(t, None, Some(Color::BLACK))),
847+
.map(|t| ColorAttachment::new(t, None, Some(LegacyColor::BLACK))),
847848
deferred: cached_deferred_texture
848-
.map(|t| ColorAttachment::new(t, None, Some(Color::BLACK))),
849+
.map(|t| ColorAttachment::new(t, None, Some(LegacyColor::BLACK))),
849850
deferred_lighting_pass_id: cached_deferred_lighting_pass_id_texture
850-
.map(|t| ColorAttachment::new(t, None, Some(Color::BLACK))),
851+
.map(|t| ColorAttachment::new(t, None, Some(LegacyColor::BLACK))),
851852
size,
852853
});
853854
}

crates/bevy_core_pipeline/src/msaa_writeback.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use bevy_app::{App, Plugin};
77
use bevy_ecs::prelude::*;
88
use bevy_render::{
99
camera::ExtractedCamera,
10-
color::Color,
10+
color::LegacyColor,
1111
render_graph::{Node, NodeRunError, RenderGraphApp, RenderGraphContext},
1212
render_resource::BindGroupEntries,
1313
renderer::RenderContext,
@@ -93,7 +93,7 @@ impl Node for MsaaWritebackNode {
9393
view: target.sampled_main_texture_view().unwrap(),
9494
resolve_target: Some(post_process.destination),
9595
ops: Operations {
96-
load: LoadOp::Clear(Color::BLACK.into()),
96+
load: LoadOp::Clear(LegacyColor::BLACK.into()),
9797
store: StoreOp::Store,
9898
},
9999
})],

crates/bevy_gizmos/src/aabb.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use bevy_ecs::{
1212
system::{Query, Res},
1313
};
1414
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
15-
use bevy_render::{color::Color, primitives::Aabb};
15+
use bevy_render::{color::LegacyColor, primitives::Aabb};
1616
use bevy_transform::{
1717
components::{GlobalTransform, Transform},
1818
TransformSystem,
@@ -57,7 +57,7 @@ pub struct AabbGizmoConfigGroup {
5757
/// A random color is chosen per box if `None`.
5858
///
5959
/// Defaults to `None`.
60-
pub default_color: Option<Color>,
60+
pub default_color: Option<LegacyColor>,
6161
}
6262

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

7373
fn draw_aabbs(
@@ -96,7 +96,7 @@ fn draw_all_aabbs(
9696
}
9797
}
9898

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

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

111-
Color::hsl(hue, 1., 0.5)
111+
LegacyColor::hsl(hue, 1., 0.5)
112112
}
113113

114114
fn aabb_transform(aabb: Aabb, transform: GlobalTransform) -> GlobalTransform {

crates/bevy_gizmos/src/arcs.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use crate::circles::DEFAULT_CIRCLE_SEGMENTS;
77
use crate::prelude::{GizmoConfigGroup, Gizmos};
88
use bevy_math::{Quat, Vec2, Vec3};
9-
use bevy_render::color::Color;
9+
use bevy_render::color::LegacyColor;
1010
use std::f32::consts::TAU;
1111

1212
// === 2D ===
@@ -30,12 +30,12 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
3030
/// # use bevy_math::prelude::*;
3131
/// # use std::f32::consts::PI;
3232
/// fn system(mut gizmos: Gizmos) {
33-
/// gizmos.arc_2d(Vec2::ZERO, 0., PI / 4., 1., Color::GREEN);
33+
/// gizmos.arc_2d(Vec2::ZERO, 0., PI / 4., 1., LegacyColor::GREEN);
3434
///
3535
/// // Arcs have 32 line-segments by default.
3636
/// // You may want to increase this for larger arcs.
3737
/// gizmos
38-
/// .arc_2d(Vec2::ZERO, 0., PI / 4., 5., Color::RED)
38+
/// .arc_2d(Vec2::ZERO, 0., PI / 4., 5., LegacyColor::RED)
3939
/// .segments(64);
4040
/// }
4141
/// # bevy_ecs::system::assert_is_system(system);
@@ -47,7 +47,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
4747
direction_angle: f32,
4848
arc_angle: f32,
4949
radius: f32,
50-
color: Color,
50+
color: LegacyColor,
5151
) -> Arc2dBuilder<'_, 'w, 's, T> {
5252
Arc2dBuilder {
5353
gizmos: self,
@@ -68,7 +68,7 @@ pub struct Arc2dBuilder<'a, 'w, 's, T: GizmoConfigGroup> {
6868
direction_angle: f32,
6969
arc_angle: f32,
7070
radius: f32,
71-
color: Color,
71+
color: LegacyColor,
7272
segments: Option<usize>,
7373
}
7474

@@ -152,7 +152,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
152152
/// 0.25,
153153
/// Vec3::ONE,
154154
/// rotation,
155-
/// Color::ORANGE
155+
/// LegacyColor::ORANGE
156156
/// )
157157
/// .segments(100);
158158
/// }
@@ -165,7 +165,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
165165
radius: f32,
166166
position: Vec3,
167167
rotation: Quat,
168-
color: Color,
168+
color: LegacyColor,
169169
) -> Arc3dBuilder<'_, 'w, 's, T> {
170170
Arc3dBuilder {
171171
gizmos: self,
@@ -202,7 +202,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
202202
/// Vec3::ONE,
203203
/// Vec3::ONE + Vec3::NEG_ONE,
204204
/// Vec3::ZERO,
205-
/// Color::ORANGE
205+
/// LegacyColor::ORANGE
206206
/// )
207207
/// .segments(100);
208208
/// }
@@ -221,7 +221,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
221221
center: Vec3,
222222
from: Vec3,
223223
to: Vec3,
224-
color: Color,
224+
color: LegacyColor,
225225
) -> Arc3dBuilder<'_, 'w, 's, T> {
226226
self.arc_from_to(center, from, to, color, |x| x)
227227
}
@@ -248,7 +248,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
248248
/// Vec3::ONE,
249249
/// Vec3::ONE + Vec3::NEG_ONE,
250250
/// Vec3::ZERO,
251-
/// Color::ORANGE
251+
/// LegacyColor::ORANGE
252252
/// )
253253
/// .segments(100);
254254
/// }
@@ -267,7 +267,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
267267
center: Vec3,
268268
from: Vec3,
269269
to: Vec3,
270-
color: Color,
270+
color: LegacyColor,
271271
) -> Arc3dBuilder<'_, 'w, 's, T> {
272272
self.arc_from_to(center, from, to, color, |angle| {
273273
if angle > 0.0 {
@@ -286,7 +286,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
286286
center: Vec3,
287287
from: Vec3,
288288
to: Vec3,
289-
color: Color,
289+
color: LegacyColor,
290290
angle_fn: impl Fn(f32) -> f32,
291291
) -> Arc3dBuilder<'_, 'w, 's, T> {
292292
// `from` and `to` can be the same here since in either case nothing gets rendered and the
@@ -331,7 +331,7 @@ pub struct Arc3dBuilder<'a, 'w, 's, T: GizmoConfigGroup> {
331331
rotation: Quat,
332332
angle: f32,
333333
radius: f32,
334-
color: Color,
334+
color: LegacyColor,
335335
segments: Option<usize>,
336336
}
337337

0 commit comments

Comments
 (0)