forked from bevyengine/bevy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod.rs
62 lines (52 loc) · 1.84 KB
/
mod.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#[cfg(feature = "hdr")]
mod hdr_texture_loader;
#[allow(clippy::module_inception)]
mod image;
mod image_texture_loader;
mod texture_cache;
pub(crate) mod image_texture_conversion;
pub use self::image::*;
#[cfg(feature = "hdr")]
pub use hdr_texture_loader::*;
pub use image_texture_loader::*;
pub use texture_cache::*;
use crate::{render_asset::RenderAssetPlugin, RenderApp, RenderStage};
use bevy_app::{App, Plugin};
use bevy_asset::{AddAsset, Assets};
// 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;
impl Plugin for ImagePlugin {
fn build(&self, app: &mut App) {
#[cfg(feature = "png")]
{
app.init_asset_loader::<ImageTextureLoader>();
}
app.add_plugin(RenderAssetPlugin::<Image>::default())
.add_asset::<Image>();
app.world
.get_resource_mut::<Assets<Image>>()
.unwrap()
.set_untracked(DEFAULT_IMAGE_HANDLE, Image::default());
if let Ok(render_app) = app.get_sub_app_mut(RenderApp) {
render_app
.init_resource::<TextureCache>()
.add_system_to_stage(RenderStage::Cleanup, update_texture_cache_system);
}
}
}
// PERF: vulkan docs recommend using 24 bit depth for better performance
pub const DEFAULT_DEPTH_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Depth32Float;
pub trait BevyDefault {
fn bevy_default() -> Self;
}
impl BevyDefault for wgpu::TextureFormat {
fn bevy_default() -> Self {
if cfg!(target_os = "android") || cfg!(target_arch = "wasm32") {
// Bgra8UnormSrgb texture missing on some Android devices
wgpu::TextureFormat::Rgba8UnormSrgb
} else {
wgpu::TextureFormat::Bgra8UnormSrgb
}
}
}