Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/bevy_animation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,7 @@ impl Plugin for AnimationPlugin {
// `PostUpdate`. For now, we just disable ambiguity testing
// for this system.
animate_targets
.before(bevy_mesh::InheritWeights)
.before(bevy_mesh::InheritWeightSystems)
.ambiguous_with_all(),
trigger_untargeted_animation_events,
expire_completed_transitions,
Expand Down
9 changes: 9 additions & 0 deletions crates/bevy_camera/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub mod primitives;
mod projection;
pub mod visibility;

use bevy_ecs::schedule::SystemSet;
pub use camera::*;
pub use clear_color::*;
pub use components::*;
Expand Down Expand Up @@ -37,3 +38,11 @@ pub mod prelude {
PerspectiveProjection, Projection,
};
}

/// Label for `camera_system<T>`, shared across all `T`.
#[derive(SystemSet, Clone, Eq, PartialEq, Hash, Debug)]
pub struct CameraUpdateSystems;

/// Deprecated alias for [`CameraUpdateSystems`].
#[deprecated(since = "0.17.0", note = "Renamed to `CameraUpdateSystems`.")]
pub type CameraUpdateSystem = CameraUpdateSystems;
8 changes: 0 additions & 8 deletions crates/bevy_camera/src/projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@ impl Plugin for CameraProjectionPlugin {
}
}

/// Label for `camera_system<T>`, shared across all `T`.
#[derive(SystemSet, Clone, Eq, PartialEq, Hash, Debug)]
pub struct CameraUpdateSystems;

/// Deprecated alias for [`CameraUpdateSystems`].
#[deprecated(since = "0.17.0", note = "Renamed to `CameraUpdateSystems`.")]
pub type CameraUpdateSystem = CameraUpdateSystems;

/// Describes a type that can generate a projection matrix, allowing it to be added to a
/// [`Camera`]'s [`Projection`] component.
///
Expand Down
89 changes: 88 additions & 1 deletion crates/bevy_image/src/image.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
use crate::ImageLoader;

#[cfg(feature = "basis-universal")]
use super::basis::*;
#[cfg(feature = "dds")]
use super::dds::*;
#[cfg(feature = "ktx2")]
use super::ktx2::*;
use bevy_app::{App, Plugin};
#[cfg(not(feature = "bevy_reflect"))]
use bevy_reflect::TypePath;
#[cfg(feature = "bevy_reflect")]
use bevy_reflect::{std_traits::ReflectDefault, Reflect};

use bevy_asset::{Asset, RenderAssetUsages};
use bevy_asset::{uuid_handle, Asset, AssetApp, Assets, Handle, RenderAssetUsages};
use bevy_color::{Color, ColorToComponents, Gray, LinearRgba, Srgba, Xyza};
use bevy_ecs::resource::Resource;
use bevy_math::{AspectRatio, UVec2, UVec3, Vec2};
Expand All @@ -35,6 +38,90 @@ impl BevyDefault for TextureFormat {
}
}

/// A handle to a 1 x 1 transparent white image.
///
/// Like [`Handle<Image>::default`], this is a handle to a fallback image asset.
/// While that handle points to an opaque white 1 x 1 image, this handle points to a transparent 1 x 1 white image.
// Number randomly selected by fair WolframAlpha query. Totally arbitrary.
pub const TRANSPARENT_IMAGE_HANDLE: Handle<Image> =
uuid_handle!("d18ad97e-a322-4981-9505-44c59a4b5e46");

/// Adds the [`Image`] as an asset and makes sure that they are extracted and prepared for the GPU.
pub struct ImagePlugin {
/// The default image sampler to use when [`bevy_image::ImageSampler`] is set to `Default`.
pub default_sampler: ImageSamplerDescriptor,
}

impl Default for ImagePlugin {
fn default() -> Self {
ImagePlugin::default_linear()
}
}

impl ImagePlugin {
/// Creates image settings with linear sampling by default.
pub fn default_linear() -> ImagePlugin {
ImagePlugin {
default_sampler: ImageSamplerDescriptor::linear(),
}
}

/// Creates image settings with nearest sampling by default.
pub fn default_nearest() -> ImagePlugin {
ImagePlugin {
default_sampler: ImageSamplerDescriptor::nearest(),
}
}
}

impl Plugin for ImagePlugin {
fn build(&self, app: &mut App) {
#[cfg(feature = "exr")]
{
app.init_asset_loader::<crate::ExrTextureLoader>();
}

#[cfg(feature = "hdr")]
{
app.init_asset_loader::<crate::HdrTextureLoader>();
}

app.init_asset::<Image>();
#[cfg(feature = "bevy_reflect")]
app.register_asset_reflect::<Image>();

let mut image_assets = app.world_mut().resource_mut::<Assets<Image>>();

image_assets
.insert(&Handle::default(), Image::default())
.unwrap();
image_assets
.insert(&TRANSPARENT_IMAGE_HANDLE, Image::transparent())
.unwrap();

#[cfg(feature = "compressed_image_saver")]
if let Some(processor) = app
.world()
.get_resource::<bevy_asset::processor::AssetProcessor>()
{
processor.register_processor::<bevy_asset::processor::LoadTransformAndSave<
ImageLoader,
bevy_asset::transformer::IdentityAssetTransformer<Image>,
crate::CompressedImageSaver,
>>(crate::CompressedImageSaver.into());
processor.set_default_processor::<bevy_asset::processor::LoadTransformAndSave<
ImageLoader,
bevy_asset::transformer::IdentityAssetTransformer<Image>,
crate::CompressedImageSaver,
>>("png");
}

if !ImageLoader::SUPPORTED_FILE_EXTENSIONS.is_empty() {
app.preregister_asset_loader::<ImageLoader>(ImageLoader::SUPPORTED_FILE_EXTENSIONS);
}
}
}

pub const TEXTURE_ASSET_INDEX: u64 = 0;
pub const SAMPLER_ASSET_INDEX: u64 = 1;

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_image/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub mod prelude {
pub use crate::{
dynamic_texture_atlas_builder::DynamicTextureAtlasBuilder,
texture_atlas::{TextureAtlas, TextureAtlasLayout, TextureAtlasSources},
BevyDefault as _, Image, ImageFormat, TextureAtlasBuilder, TextureError,
BevyDefault as _, Image, ImageFormat, ImagePlugin, TextureAtlasBuilder, TextureError,
};
}

Expand Down
4 changes: 3 additions & 1 deletion crates/bevy_internal/src/default_plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ plugin_group! {
bevy_render:::RenderPlugin,
// NOTE: Load this after renderer initialization so that it knows about the supported
// compressed texture formats.
#[cfg(feature = "bevy_image")]
bevy_image:::ImagePlugin,
#[cfg(feature = "bevy_render")]
bevy_render::texture:::ImagePlugin,
bevy_render::texture:::TexturePlugin,
#[cfg(feature = "bevy_render")]
#[custom(cfg(all(not(target_arch = "wasm32"), feature = "multi_threaded")))]
bevy_render::pipelined_rendering:::PipelinedRenderingPlugin,
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_mesh/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ impl BaseMeshPipelineKey {

/// `bevy_render::mesh::inherit_weights` runs in this `SystemSet`
#[derive(Debug, Hash, PartialEq, Eq, Clone, SystemSet)]
pub struct InheritWeights;
pub struct InheritWeightSystems;
7 changes: 2 additions & 5 deletions crates/bevy_render/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,8 @@ mod wgpu_wrapper;
pub mod prelude {
#[doc(hidden)]
pub use crate::{
alpha::AlphaMode,
camera::NormalizedRenderTargetExt as _,
texture::{ImagePlugin, ManualTextureViews},
view::Msaa,
ExtractSchedule,
alpha::AlphaMode, camera::NormalizedRenderTargetExt as _, texture::ManualTextureViews,
view::Msaa, ExtractSchedule,
};
}

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_render/src/mesh/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl Plugin for MeshPlugin {
pub struct MorphPlugin;
impl Plugin for MorphPlugin {
fn build(&self, app: &mut App) {
app.add_systems(PostUpdate, inherit_weights.in_set(InheritWeights));
app.add_systems(PostUpdate, inherit_weights.in_set(InheritWeightSystems));
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_render/src/render_resource/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl Deref for Sampler {
/// A rendering resource for the default image sampler which is set during renderer
/// initialization.
///
/// The [`ImagePlugin`](crate::texture::ImagePlugin) can be set during app initialization to change the default
/// The [`ImagePlugin`](bevy_image::ImagePlugin) can be set during app initialization to change the default
/// image sampler.
#[derive(Resource, Debug, Clone, Deref, DerefMut)]
pub struct DefaultImageSampler(pub(crate) Sampler);
101 changes: 10 additions & 91 deletions crates/bevy_render/src/texture/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,7 @@ mod texture_attachment;
mod texture_cache;

pub use crate::render_resource::DefaultImageSampler;
#[cfg(feature = "compressed_image_saver")]
use bevy_image::CompressedImageSaver;
#[cfg(feature = "hdr")]
use bevy_image::HdrTextureLoader;
use bevy_image::{
CompressedImageFormatSupport, CompressedImageFormats, Image, ImageLoader,
ImageSamplerDescriptor,
};
use bevy_image::{CompressedImageFormatSupport, CompressedImageFormats, ImageLoader, ImagePlugin};
pub use fallback_image::*;
pub use gpu_image::*;
pub use manual_texture_view::*;
Expand All @@ -24,103 +17,26 @@ use crate::{
renderer::RenderDevice, Render, RenderApp, RenderSystems,
};
use bevy_app::{App, Plugin};
use bevy_asset::{uuid_handle, AssetApp, Assets, Handle};
use bevy_asset::AssetApp;
use bevy_ecs::prelude::*;
use tracing::warn;

/// A handle to a 1 x 1 transparent white image.
///
/// Like [`Handle<Image>::default`], this is a handle to a fallback image asset.
/// While that handle points to an opaque white 1 x 1 image, this handle points to a transparent 1 x 1 white image.
// Number randomly selected by fair WolframAlpha query. Totally arbitrary.
pub const TRANSPARENT_IMAGE_HANDLE: Handle<Image> =
uuid_handle!("d18ad97e-a322-4981-9505-44c59a4b5e46");

// TODO: replace Texture names with Image names?
/// Adds the [`Image`] as an asset and makes sure that they are extracted and prepared for the GPU.
pub struct ImagePlugin {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh why was this even in bevy_render T_T

/// The default image sampler to use when [`bevy_image::ImageSampler`] is set to `Default`.
pub default_sampler: ImageSamplerDescriptor,
}

impl Default for ImagePlugin {
fn default() -> Self {
ImagePlugin::default_linear()
}
}

impl ImagePlugin {
/// Creates image settings with linear sampling by default.
pub fn default_linear() -> ImagePlugin {
ImagePlugin {
default_sampler: ImageSamplerDescriptor::linear(),
}
}

/// Creates image settings with nearest sampling by default.
pub fn default_nearest() -> ImagePlugin {
ImagePlugin {
default_sampler: ImageSamplerDescriptor::nearest(),
}
}
}
#[derive(Default)]
pub struct TexturePlugin;

impl Plugin for ImagePlugin {
impl Plugin for TexturePlugin {
fn build(&self, app: &mut App) {
#[cfg(feature = "exr")]
{
app.init_asset_loader::<bevy_image::ExrTextureLoader>();
}

#[cfg(feature = "hdr")]
{
app.init_asset_loader::<HdrTextureLoader>();
}

app.add_plugins((
RenderAssetPlugin::<GpuImage>::default(),
ExtractResourcePlugin::<ManualTextureViews>::default(),
))
.init_resource::<ManualTextureViews>()
.init_asset::<Image>()
.register_asset_reflect::<Image>();

let mut image_assets = app.world_mut().resource_mut::<Assets<Image>>();

image_assets
.insert(&Handle::default(), Image::default())
.unwrap();
image_assets
.insert(&TRANSPARENT_IMAGE_HANDLE, Image::transparent())
.unwrap();

#[cfg(feature = "compressed_image_saver")]
if let Some(processor) = app
.world()
.get_resource::<bevy_asset::processor::AssetProcessor>()
{
processor.register_processor::<bevy_asset::processor::LoadTransformAndSave<
ImageLoader,
bevy_asset::transformer::IdentityAssetTransformer<Image>,
CompressedImageSaver,
>>(CompressedImageSaver.into());
processor.set_default_processor::<bevy_asset::processor::LoadTransformAndSave<
ImageLoader,
bevy_asset::transformer::IdentityAssetTransformer<Image>,
CompressedImageSaver,
>>("png");
}

.init_resource::<ManualTextureViews>();
if let Some(render_app) = app.get_sub_app_mut(RenderApp) {
render_app.init_resource::<TextureCache>().add_systems(
Render,
update_texture_cache_system.in_set(RenderSystems::Cleanup),
);
}

if !ImageLoader::SUPPORTED_FILE_EXTENSIONS.is_empty() {
app.preregister_asset_loader::<ImageLoader>(ImageLoader::SUPPORTED_FILE_EXTENSIONS);
}
}

fn finish(&self, app: &mut App) {
Expand All @@ -137,11 +53,14 @@ impl Plugin for ImagePlugin {

app.register_asset_loader(ImageLoader::new(supported_compressed_formats));
}
let default_sampler = app.get_added_plugins::<ImagePlugin>()[0]
.default_sampler
.clone();

if let Some(render_app) = app.get_sub_app_mut(RenderApp) {
let default_sampler = {
let device = render_app.world().resource::<RenderDevice>();
device.create_sampler(&self.default_sampler.as_wgpu())
device.create_sampler(&default_sampler.as_wgpu())
};
render_app
.insert_resource(DefaultImageSampler(default_sampler))
Expand Down
4 changes: 3 additions & 1 deletion crates/bevy_ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ bevy_image = { path = "../bevy_image", version = "0.17.0-dev" }
bevy_input = { path = "../bevy_input", version = "0.17.0-dev" }
bevy_math = { path = "../bevy_math", version = "0.17.0-dev" }
bevy_reflect = { path = "../bevy_reflect", version = "0.17.0-dev" }
bevy_render = { path = "../bevy_render", version = "0.17.0-dev" }
bevy_sprite = { path = "../bevy_sprite", version = "0.17.0-dev" }
bevy_text = { path = "../bevy_text", version = "0.17.0-dev" }
bevy_picking = { path = "../bevy_picking", version = "0.17.0-dev", optional = true }
Expand All @@ -43,6 +42,9 @@ smallvec = { version = "1", default-features = false }
accesskit = "0.21"
tracing = { version = "0.1", default-features = false, features = ["std"] }

[dev-dependencies]
bevy_render = { path = "../bevy_render", version = "0.17.0-dev" }

[features]
default = []
serialize = [
Expand Down
Loading
Loading