Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bevyengine
GitHub Repository: bevyengine/bevy
Path: blob/main/crates/bevy_asset/src/render_asset.rs
6601 views
1
use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize};
2
use serde::{Deserialize, Serialize};
3
4
bitflags::bitflags! {
5
/// Defines where the asset will be used.
6
///
7
/// If an asset is set to the `RENDER_WORLD` but not the `MAIN_WORLD`, the asset will be
8
/// unloaded from the asset server once it's been extracted and prepared in the render world.
9
///
10
/// Unloading the asset saves on memory, as for most cases it is no longer necessary to keep
11
/// it in RAM once it's been uploaded to the GPU's VRAM. However, this means you can no longer
12
/// access the asset from the CPU (via the `Assets<T>` resource) once unloaded (without re-loading it).
13
///
14
/// If you never need access to the asset from the CPU past the first frame it's loaded on,
15
/// or only need very infrequent access, then set this to `RENDER_WORLD`. Otherwise, set this to
16
/// `RENDER_WORLD | MAIN_WORLD`.
17
///
18
/// If you have an asset that doesn't actually need to end up in the render world, like an Image
19
/// that will be decoded into another Image asset, use `MAIN_WORLD` only.
20
///
21
/// ## Platform-specific
22
///
23
/// On Wasm, it is not possible for now to free reserved memory. To control memory usage, load assets
24
/// in sequence and unload one before loading the next. See this
25
/// [discussion about memory management](https://github.com/WebAssembly/design/issues/1397) for more
26
/// details.
27
#[repr(transparent)]
28
#[derive(Serialize, Deserialize, Hash, Clone, Copy, PartialEq, Eq, Debug, Reflect)]
29
#[reflect(opaque)]
30
#[reflect(Serialize, Deserialize, Hash, Clone, PartialEq, Debug)]
31
pub struct RenderAssetUsages: u8 {
32
/// The bit flag for the main world.
33
const MAIN_WORLD = 1 << 0;
34
/// The bit flag for the render world.
35
const RENDER_WORLD = 1 << 1;
36
}
37
}
38
39
impl Default for RenderAssetUsages {
40
/// Returns the default render asset usage flags:
41
/// `RenderAssetUsages::MAIN_WORLD | RenderAssetUsages::RENDER_WORLD`
42
///
43
/// This default configuration ensures the asset persists in the main world, even after being prepared for rendering.
44
///
45
/// If your asset does not change, consider using `RenderAssetUsages::RENDER_WORLD` exclusively. This will cause
46
/// the asset to be unloaded from the main world once it has been prepared for rendering. If the asset does not need
47
/// to reach the render world at all, use `RenderAssetUsages::MAIN_WORLD` exclusively.
48
fn default() -> Self {
49
RenderAssetUsages::MAIN_WORLD | RenderAssetUsages::RENDER_WORLD
50
}
51
}
52
53