Skip to content

Commit c0eb89e

Browse files
authored
Make bevy_ui not depend on bevy_render (#20502)
# Objective - title ## Solution - use the system set - fix the InheritWeights system set naming convention while we're at it - move transparent image handle uuid to bevy_image - move ImagePlugin to bevy_image to initialize transparent image etc - rename remaining plugin to TexturePlugin - ok technically its a dev-dep still - sorry this could be split up better ## Testing
1 parent 1224ba7 commit c0eb89e

File tree

21 files changed

+145
-165
lines changed

21 files changed

+145
-165
lines changed

crates/bevy_animation/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,7 @@ impl Plugin for AnimationPlugin {
12451245
// `PostUpdate`. For now, we just disable ambiguity testing
12461246
// for this system.
12471247
animate_targets
1248-
.before(bevy_mesh::InheritWeights)
1248+
.before(bevy_mesh::InheritWeightSystems)
12491249
.ambiguous_with_all(),
12501250
trigger_untargeted_animation_events,
12511251
expire_completed_transitions,

crates/bevy_anti_aliasing/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ keywords = ["bevy"]
1212
trace = []
1313
webgl = []
1414
webgpu = []
15-
smaa_luts = ["bevy_render/ktx2", "bevy_image/ktx2", "bevy_image/zstd"]
15+
smaa_luts = ["bevy_image/ktx2", "bevy_image/zstd"]
1616

1717
[dependencies]
1818
# bevy

crates/bevy_camera/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub mod primitives;
66
mod projection;
77
pub mod visibility;
88

9+
use bevy_ecs::schedule::SystemSet;
910
pub use camera::*;
1011
pub use clear_color::*;
1112
pub use components::*;
@@ -37,3 +38,11 @@ pub mod prelude {
3738
PerspectiveProjection, Projection,
3839
};
3940
}
41+
42+
/// Label for `camera_system<T>`, shared across all `T`.
43+
#[derive(SystemSet, Clone, Eq, PartialEq, Hash, Debug)]
44+
pub struct CameraUpdateSystems;
45+
46+
/// Deprecated alias for [`CameraUpdateSystems`].
47+
#[deprecated(since = "0.17.0", note = "Renamed to `CameraUpdateSystems`.")]
48+
pub type CameraUpdateSystem = CameraUpdateSystems;

crates/bevy_camera/src/projection.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,6 @@ impl Plugin for CameraProjectionPlugin {
2727
}
2828
}
2929

30-
/// Label for `camera_system<T>`, shared across all `T`.
31-
#[derive(SystemSet, Clone, Eq, PartialEq, Hash, Debug)]
32-
pub struct CameraUpdateSystems;
33-
34-
/// Deprecated alias for [`CameraUpdateSystems`].
35-
#[deprecated(since = "0.17.0", note = "Renamed to `CameraUpdateSystems`.")]
36-
pub type CameraUpdateSystem = CameraUpdateSystems;
37-
3830
/// Describes a type that can generate a projection matrix, allowing it to be added to a
3931
/// [`Camera`]'s [`Projection`] component.
4032
///

crates/bevy_core_pipeline/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ keywords = ["bevy"]
1616
trace = []
1717
webgl = []
1818
webgpu = []
19-
tonemapping_luts = ["bevy_render/ktx2", "bevy_image/ktx2", "bevy_image/zstd"]
19+
tonemapping_luts = ["bevy_image/ktx2", "bevy_image/zstd"]
2020

2121
[dependencies]
2222
# bevy

crates/bevy_image/src/image.rs

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1+
use crate::ImageLoader;
2+
13
#[cfg(feature = "basis-universal")]
24
use super::basis::*;
35
#[cfg(feature = "dds")]
46
use super::dds::*;
57
#[cfg(feature = "ktx2")]
68
use super::ktx2::*;
9+
use bevy_app::{App, Plugin};
710
#[cfg(not(feature = "bevy_reflect"))]
811
use bevy_reflect::TypePath;
912
#[cfg(feature = "bevy_reflect")]
1013
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
1114

12-
use bevy_asset::{Asset, RenderAssetUsages};
15+
use bevy_asset::{uuid_handle, Asset, AssetApp, Assets, Handle, RenderAssetUsages};
1316
use bevy_color::{Color, ColorToComponents, Gray, LinearRgba, Srgba, Xyza};
1417
use bevy_ecs::resource::Resource;
1518
use bevy_math::{AspectRatio, UVec2, UVec3, Vec2};
@@ -35,6 +38,84 @@ impl BevyDefault for TextureFormat {
3538
}
3639
}
3740

41+
/// A handle to a 1 x 1 transparent white image.
42+
///
43+
/// Like [`Handle<Image>::default`], this is a handle to a fallback image asset.
44+
/// While that handle points to an opaque white 1 x 1 image, this handle points to a transparent 1 x 1 white image.
45+
// Number randomly selected by fair WolframAlpha query. Totally arbitrary.
46+
pub const TRANSPARENT_IMAGE_HANDLE: Handle<Image> =
47+
uuid_handle!("d18ad97e-a322-4981-9505-44c59a4b5e46");
48+
49+
/// Adds the [`Image`] as an asset and makes sure that they are extracted and prepared for the GPU.
50+
pub struct ImagePlugin {
51+
/// The default image sampler to use when [`ImageSampler`] is set to `Default`.
52+
pub default_sampler: ImageSamplerDescriptor,
53+
}
54+
55+
impl Default for ImagePlugin {
56+
fn default() -> Self {
57+
ImagePlugin::default_linear()
58+
}
59+
}
60+
61+
impl ImagePlugin {
62+
/// Creates image settings with linear sampling by default.
63+
pub fn default_linear() -> ImagePlugin {
64+
ImagePlugin {
65+
default_sampler: ImageSamplerDescriptor::linear(),
66+
}
67+
}
68+
69+
/// Creates image settings with nearest sampling by default.
70+
pub fn default_nearest() -> ImagePlugin {
71+
ImagePlugin {
72+
default_sampler: ImageSamplerDescriptor::nearest(),
73+
}
74+
}
75+
}
76+
77+
impl Plugin for ImagePlugin {
78+
fn build(&self, app: &mut App) {
79+
#[cfg(feature = "exr")]
80+
app.init_asset_loader::<crate::ExrTextureLoader>();
81+
82+
#[cfg(feature = "hdr")]
83+
app.init_asset_loader::<crate::HdrTextureLoader>();
84+
85+
app.init_asset::<Image>();
86+
#[cfg(feature = "bevy_reflect")]
87+
app.register_asset_reflect::<Image>();
88+
89+
let mut image_assets = app.world_mut().resource_mut::<Assets<Image>>();
90+
91+
image_assets
92+
.insert(&Handle::default(), Image::default())
93+
.unwrap();
94+
image_assets
95+
.insert(&TRANSPARENT_IMAGE_HANDLE, Image::transparent())
96+
.unwrap();
97+
98+
#[cfg(feature = "compressed_image_saver")]
99+
if let Some(processor) = app
100+
.world()
101+
.get_resource::<bevy_asset::processor::AssetProcessor>()
102+
{
103+
processor.register_processor::<bevy_asset::processor::LoadTransformAndSave<
104+
ImageLoader,
105+
bevy_asset::transformer::IdentityAssetTransformer<Image>,
106+
crate::CompressedImageSaver,
107+
>>(crate::CompressedImageSaver.into());
108+
processor.set_default_processor::<bevy_asset::processor::LoadTransformAndSave<
109+
ImageLoader,
110+
bevy_asset::transformer::IdentityAssetTransformer<Image>,
111+
crate::CompressedImageSaver,
112+
>>("png");
113+
}
114+
115+
app.preregister_asset_loader::<ImageLoader>(ImageLoader::SUPPORTED_FILE_EXTENSIONS);
116+
}
117+
}
118+
38119
pub const TEXTURE_ASSET_INDEX: u64 = 0;
39120
pub const SAMPLER_ASSET_INDEX: u64 = 1;
40121

crates/bevy_image/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub mod prelude {
66
pub use crate::{
77
dynamic_texture_atlas_builder::DynamicTextureAtlasBuilder,
88
texture_atlas::{TextureAtlas, TextureAtlasLayout, TextureAtlasSources},
9-
BevyDefault as _, Image, ImageFormat, TextureAtlasBuilder, TextureError,
9+
BevyDefault as _, Image, ImageFormat, ImagePlugin, TextureAtlasBuilder, TextureError,
1010
};
1111
}
1212

crates/bevy_internal/Cargo.toml

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,16 @@ detailed_trace = ["bevy_ecs/detailed_trace", "bevy_render?/detailed_trace"]
2929
sysinfo_plugin = ["bevy_diagnostic/sysinfo_plugin"]
3030

3131
# Enables compressed KTX2 UASTC texture output on the asset processor
32-
compressed_image_saver = [
33-
"bevy_image/compressed_image_saver",
34-
"bevy_render/compressed_image_saver",
35-
]
36-
37-
# Texture formats that have specific rendering support (HDR enabled by default)
38-
basis-universal = ["bevy_image/basis-universal", "bevy_render/basis-universal"]
39-
exr = ["bevy_image/exr", "bevy_render/exr"]
40-
hdr = ["bevy_image/hdr", "bevy_render/hdr"]
41-
ktx2 = ["bevy_image/ktx2", "bevy_render/ktx2"]
32+
compressed_image_saver = ["bevy_image/compressed_image_saver"]
4233

4334
# For ktx2 supercompression
4435
zlib = ["bevy_image/zlib"]
4536
zstd = ["bevy_image/zstd"]
4637
zstd_rust = ["bevy_image/zstd_rust"]
4738
zstd_c = ["bevy_image/zstd_c"]
4839

49-
# Image format support (PNG enabled by default)
40+
# Image format support (HDR and PNG enabled by default)
41+
basis-universal = ["bevy_image/basis-universal"]
5042
bmp = ["bevy_image/bmp"]
5143
ff = ["bevy_image/ff"]
5244
gif = ["bevy_image/gif"]
@@ -59,6 +51,9 @@ tga = ["bevy_image/tga"]
5951
tiff = ["bevy_image/tiff"]
6052
webp = ["bevy_image/webp"]
6153
dds = ["bevy_image/dds"]
54+
exr = ["bevy_image/exr"]
55+
hdr = ["bevy_image/hdr"]
56+
ktx2 = ["bevy_image/ktx2"]
6257

6358
# Enable SPIR-V passthrough
6459
spirv_shader_passthrough = ["bevy_render/spirv_shader_passthrough"]
@@ -89,11 +84,14 @@ symphonia-wav = ["bevy_audio/symphonia-wav"]
8984

9085
# Shader formats
9186
shader_format_glsl = [
92-
"bevy_render/shader_format_glsl",
87+
"bevy_shader/shader_format_glsl",
9388
"bevy_pbr?/shader_format_glsl",
9489
]
95-
shader_format_spirv = ["bevy_render/shader_format_spirv"]
96-
shader_format_wesl = ["bevy_render/shader_format_wesl"]
90+
shader_format_spirv = [
91+
"bevy_shader/shader_format_spirv",
92+
"bevy_render?/shader_format_spirv",
93+
]
94+
shader_format_wesl = ["bevy_shader/shader_format_wesl"]
9795

9896
serialize = [
9997
"bevy_a11y?/serialize",

crates/bevy_internal/src/default_plugins.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ plugin_group! {
3131
bevy_render:::RenderPlugin,
3232
// NOTE: Load this after renderer initialization so that it knows about the supported
3333
// compressed texture formats.
34-
#[cfg(feature = "bevy_render")]
35-
bevy_render::texture:::ImagePlugin,
34+
#[cfg(feature = "bevy_image")]
35+
bevy_image:::ImagePlugin,
3636
#[cfg(feature = "bevy_render")]
3737
#[custom(cfg(all(not(target_arch = "wasm32"), feature = "multi_threaded")))]
3838
bevy_render::pipelined_rendering:::PipelinedRenderingPlugin,

crates/bevy_mesh/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,4 @@ impl BaseMeshPipelineKey {
7171

7272
/// `bevy_render::mesh::inherit_weights` runs in this `SystemSet`
7373
#[derive(Debug, Hash, PartialEq, Eq, Clone, SystemSet)]
74-
pub struct InheritWeights;
74+
pub struct InheritWeightSystems;

0 commit comments

Comments
 (0)