bevy_render/camera/
manual_texture_view.rs

1use crate::extract_resource::ExtractResource;
2use crate::render_resource::TextureView;
3use crate::texture::BevyDefault;
4use bevy_ecs::system::Resource;
5use bevy_ecs::{prelude::Component, reflect::ReflectComponent};
6use bevy_math::UVec2;
7use bevy_reflect::prelude::*;
8use bevy_utils::HashMap;
9use wgpu::TextureFormat;
10
11/// A unique id that corresponds to a specific [`ManualTextureView`] in the [`ManualTextureViews`] collection.
12#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Component, Reflect)]
13#[reflect(Component, Default)]
14pub struct ManualTextureViewHandle(pub u32);
15
16/// A manually managed [`TextureView`] for use as a [`crate::camera::RenderTarget`].
17#[derive(Debug, Clone, Component)]
18pub struct ManualTextureView {
19    pub texture_view: TextureView,
20    pub size: UVec2,
21    pub format: TextureFormat,
22}
23
24impl ManualTextureView {
25    pub fn with_default_format(texture_view: TextureView, size: UVec2) -> Self {
26        Self {
27            texture_view,
28            size,
29            format: TextureFormat::bevy_default(),
30        }
31    }
32}
33
34/// Stores manually managed [`ManualTextureView`]s for use as a [`crate::camera::RenderTarget`].
35#[derive(Default, Clone, Resource, ExtractResource)]
36pub struct ManualTextureViews(HashMap<ManualTextureViewHandle, ManualTextureView>);
37
38impl std::ops::Deref for ManualTextureViews {
39    type Target = HashMap<ManualTextureViewHandle, ManualTextureView>;
40
41    fn deref(&self) -> &Self::Target {
42        &self.0
43    }
44}
45
46impl std::ops::DerefMut for ManualTextureViews {
47    fn deref_mut(&mut self) -> &mut Self::Target {
48        &mut self.0
49    }
50}