bevy_render/camera/
manual_texture_view.rs

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