Skip to content

Commit 103085e

Browse files
committed
Make bevy_ui not depend on bevy_render
1 parent 5be9c68 commit 103085e

File tree

18 files changed

+141
-146
lines changed

18 files changed

+141
-146
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_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_image/src/image.rs

Lines changed: 88 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,90 @@ 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 [`bevy_image::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+
{
81+
app.init_asset_loader::<crate::ExrTextureLoader>();
82+
}
83+
84+
#[cfg(feature = "hdr")]
85+
{
86+
app.init_asset_loader::<crate::HdrTextureLoader>();
87+
}
88+
89+
app.init_asset::<Image>();
90+
#[cfg(feature = "bevy_reflect")]
91+
app.register_asset_reflect::<Image>();
92+
93+
let mut image_assets = app.world_mut().resource_mut::<Assets<Image>>();
94+
95+
image_assets
96+
.insert(&Handle::default(), Image::default())
97+
.unwrap();
98+
image_assets
99+
.insert(&TRANSPARENT_IMAGE_HANDLE, Image::transparent())
100+
.unwrap();
101+
102+
#[cfg(feature = "compressed_image_saver")]
103+
if let Some(processor) = app
104+
.world()
105+
.get_resource::<bevy_asset::processor::AssetProcessor>()
106+
{
107+
processor.register_processor::<bevy_asset::processor::LoadTransformAndSave<
108+
ImageLoader,
109+
bevy_asset::transformer::IdentityAssetTransformer<Image>,
110+
crate::CompressedImageSaver,
111+
>>(crate::CompressedImageSaver.into());
112+
processor.set_default_processor::<bevy_asset::processor::LoadTransformAndSave<
113+
ImageLoader,
114+
bevy_asset::transformer::IdentityAssetTransformer<Image>,
115+
crate::CompressedImageSaver,
116+
>>("png");
117+
}
118+
119+
if !ImageLoader::SUPPORTED_FILE_EXTENSIONS.is_empty() {
120+
app.preregister_asset_loader::<ImageLoader>(ImageLoader::SUPPORTED_FILE_EXTENSIONS);
121+
}
122+
}
123+
}
124+
38125
pub const TEXTURE_ASSET_INDEX: u64 = 0;
39126
pub const SAMPLER_ASSET_INDEX: u64 = 1;
40127

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/src/default_plugins.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ 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_image")]
35+
bevy_image:::ImagePlugin,
3436
#[cfg(feature = "bevy_render")]
35-
bevy_render::texture:::ImagePlugin,
37+
bevy_render::texture:::TexturePlugin,
3638
#[cfg(feature = "bevy_render")]
3739
#[custom(cfg(all(not(target_arch = "wasm32"), feature = "multi_threaded")))]
3840
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;

crates/bevy_render/src/lib.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,8 @@ mod wgpu_wrapper;
7272
pub mod prelude {
7373
#[doc(hidden)]
7474
pub use crate::{
75-
alpha::AlphaMode,
76-
camera::NormalizedRenderTargetExt as _,
77-
texture::{ImagePlugin, ManualTextureViews},
78-
view::Msaa,
79-
ExtractSchedule,
75+
alpha::AlphaMode, camera::NormalizedRenderTargetExt as _, texture::ManualTextureViews,
76+
view::Msaa, ExtractSchedule,
8077
};
8178
}
8279

crates/bevy_render/src/mesh/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl Plugin for MeshPlugin {
5151
pub struct MorphPlugin;
5252
impl Plugin for MorphPlugin {
5353
fn build(&self, app: &mut App) {
54-
app.add_systems(PostUpdate, inherit_weights.in_set(InheritWeights));
54+
app.add_systems(PostUpdate, inherit_weights.in_set(InheritWeightSystems));
5555
}
5656
}
5757

crates/bevy_render/src/render_resource/texture.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ impl Deref for Sampler {
160160
/// A rendering resource for the default image sampler which is set during renderer
161161
/// initialization.
162162
///
163-
/// The [`ImagePlugin`](crate::texture::ImagePlugin) can be set during app initialization to change the default
163+
/// The [`ImagePlugin`](bevy_image::ImagePlugin) can be set during app initialization to change the default
164164
/// image sampler.
165165
#[derive(Resource, Debug, Clone, Deref, DerefMut)]
166166
pub struct DefaultImageSampler(pub(crate) Sampler);

0 commit comments

Comments
 (0)