From 52d633948ac61de62bed025800542e815b32efee Mon Sep 17 00:00:00 2001 From: cryscan Date: Fri, 4 Nov 2022 23:12:59 -0400 Subject: [PATCH 1/3] Macro for load internal binary asset. --- crates/bevy_asset/src/assets.rs | 38 +++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/crates/bevy_asset/src/assets.rs b/crates/bevy_asset/src/assets.rs index f637250780b6a..8e212fcfca37d 100644 --- a/crates/bevy_asset/src/assets.rs +++ b/crates/bevy_asset/src/assets.rs @@ -443,6 +443,44 @@ macro_rules! load_internal_asset { }}; } +/// Loads an internal binary asset. +/// +/// Internal binary assets (e.g. spir-v shaders) are bundled directly into the app and can't be hot reloaded +/// using the conventional API. See `DebugAssetServerPlugin`. +#[cfg(feature = "debug_asset_server")] +#[macro_export] +macro_rules! load_internal_binary_asset { + ($app: ident, $handle: ident, $path_str: expr, $loader: expr) => {{ + { + let mut debug_app = $app + .world + .non_send_resource_mut::<$crate::debug_asset_server::DebugAssetApp>(); + $crate::debug_asset_server::register_handle_with_loader( + $loader, + &mut debug_app, + $handle, + file!(), + $path_str, + ); + } + let mut assets = $app.world.resource_mut::<$crate::Assets<_>>(); + assets.set_untracked($handle, ($loader)(include_bytes!($path_str))); + }}; +} + +/// Loads an internal binary asset. +/// +/// Internal assets (e.g. shaders) are bundled directly into the app and can't be hot reloaded +/// using the conventional API. See `DebugAssetServerPlugin`. +#[cfg(not(feature = "debug_asset_server"))] +#[macro_export] +macro_rules! load_internal_binary_asset { + ($app: ident, $handle: ident, $path_str: expr, $loader: expr) => {{ + let mut assets = $app.world.resource_mut::<$crate::Assets<_>>(); + assets.set_untracked($handle, ($loader)(include_bytes!($path_str))); + }}; +} + #[cfg(test)] mod tests { use bevy_app::App; From 552998110f1e742d5dc55e76b96c6fd780a1ebbf Mon Sep 17 00:00:00 2001 From: cryscan Date: Fri, 4 Nov 2022 23:18:14 -0400 Subject: [PATCH 2/3] Sync documents for both added macro. --- crates/bevy_asset/src/assets.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_asset/src/assets.rs b/crates/bevy_asset/src/assets.rs index 8e212fcfca37d..8565bb3129b69 100644 --- a/crates/bevy_asset/src/assets.rs +++ b/crates/bevy_asset/src/assets.rs @@ -470,7 +470,7 @@ macro_rules! load_internal_binary_asset { /// Loads an internal binary asset. /// -/// Internal assets (e.g. shaders) are bundled directly into the app and can't be hot reloaded +/// Internal binary assets (e.g. spir-v shaders) are bundled directly into the app and can't be hot reloaded /// using the conventional API. See `DebugAssetServerPlugin`. #[cfg(not(feature = "debug_asset_server"))] #[macro_export] From ea98066c287e96685152346554f4a8e55d42f700 Mon Sep 17 00:00:00 2001 From: cryscan Date: Fri, 4 Nov 2022 23:27:35 -0400 Subject: [PATCH 3/3] Add `as_ref()`. --- crates/bevy_asset/src/assets.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_asset/src/assets.rs b/crates/bevy_asset/src/assets.rs index 8565bb3129b69..19749df7cf897 100644 --- a/crates/bevy_asset/src/assets.rs +++ b/crates/bevy_asset/src/assets.rs @@ -464,7 +464,7 @@ macro_rules! load_internal_binary_asset { ); } let mut assets = $app.world.resource_mut::<$crate::Assets<_>>(); - assets.set_untracked($handle, ($loader)(include_bytes!($path_str))); + assets.set_untracked($handle, ($loader)(include_bytes!($path_str).as_ref())); }}; } @@ -477,7 +477,7 @@ macro_rules! load_internal_binary_asset { macro_rules! load_internal_binary_asset { ($app: ident, $handle: ident, $path_str: expr, $loader: expr) => {{ let mut assets = $app.world.resource_mut::<$crate::Assets<_>>(); - assets.set_untracked($handle, ($loader)(include_bytes!($path_str))); + assets.set_untracked($handle, ($loader)(include_bytes!($path_str).as_ref())); }}; }