Skip to content

Commit 4f81cf8

Browse files
authored
add doc comment to manual texture view and handle (#21087)
# Objective Addresses #21037 ## Solution explain how `ManualTextureViews` can be used. ------ I think the handles should be atomically increasing ids like other internal ids so that users don't have to pick a random offset into `u32` to avoid colliding with other `ManualTextureView`s (I'm not sure if there ever are multiple systems/libraries using this functionality in the same world, but it's not forbidden). A quick search through github shows most people just start at 0. I'm hoping these docs might make it into 0.17 though, so unless someone disagrees with me or that change would prevent some use-case I'm not aware of, I plan on creating a PR for that in in 0.18.
1 parent 5fbd2e6 commit 4f81cf8

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

crates/bevy_camera/src/camera.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,8 @@ pub enum NormalizedRenderTarget {
882882
}
883883

884884
/// A unique id that corresponds to a specific `ManualTextureView` in the `ManualTextureViews` collection.
885+
///
886+
/// See `ManualTextureViews` in `bevy_camera` for more details.
885887
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Component, Reflect)]
886888
#[reflect(Component, Default, Debug, PartialEq, Hash, Clone)]
887889
pub struct ManualTextureViewHandle(pub u32);

crates/bevy_render/src/texture/manual_texture_view.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,30 @@ impl ManualTextureView {
2626
}
2727
}
2828

29-
/// Stores manually managed [`ManualTextureView`]s for use as a [`bevy_camera::RenderTarget`].
29+
/// Resource that stores manually managed [`ManualTextureView`]s for use as a [`RenderTarget`](bevy_camera::RenderTarget).
30+
/// This type dereferences to a `HashMap<ManualTextureViewHandle, ManualTextureView>`.
31+
/// To add a new texture view, pick a new [`ManualTextureViewHandle`] and insert it into the map.
32+
/// Then, to render to the view, set a [`Camera`](bevy_camera::Camera)s `target` to `RenderTarget::TextureView(handle)`.
33+
/// ```ignore
34+
/// # use bevy_ecs::prelude::*;
35+
/// # let mut world = World::default();
36+
/// # world.insert_resource(ManualTextureViews::default());
37+
/// # let texture_view = todo!();
38+
/// let manual_views = world.resource_mut::<ManualTextureViews>();
39+
/// let manual_view = ManualTextureView::with_default_format(texture_view, UVec2::new(1024, 1024));
40+
///
41+
/// // Choose an unused handle value; it's likely only you are inserting manual views.
42+
/// const MANUAL_VIEW_HANDLE: ManualTextureViewHandle = ManualTextureViewHandle::new(42);
43+
/// manual_views.insert(MANUAL_VIEW_HANDLE, manual_view);
44+
///
45+
/// // Now you can spawn a Cemera that renders to the manual view:
46+
/// # use bevy_camera::{Camera, RenderTarget};
47+
/// world.spawn(Camera {
48+
/// target: RenderTarget::TextureView(MANUAL_VIEW_HANDLE),
49+
/// ..Default::default()
50+
/// });
51+
/// ```
52+
/// Bevy will then use the `ManualTextureViews` resource to find your texture view and render to it.
3053
#[derive(Default, Clone, Resource, ExtractResource)]
3154
pub struct ManualTextureViews(HashMap<ManualTextureViewHandle, ManualTextureView>);
3255

0 commit comments

Comments
 (0)