aboutsummaryrefslogtreecommitdiff
path: root/src/components.rs
blob: 8e25530d11504d42efd30fdeb8af415936538718 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use std::sync::{Arc, Mutex};

use bevy::{ecs::query::QueryItem, prelude::*, render::extract_component::ExtractComponent};

use crate::render_assets::HeadlessRenderSource;

/// Headless render destination. Contains the image which the rendered frame is copied to.
#[derive(Component, Default, Clone)]
pub struct HeadlessRenderDestination(pub Arc<Mutex<Image>>);

impl ExtractComponent for HeadlessRenderDestination {
    type QueryData = (&'static Self, &'static Handle<HeadlessRenderSource>);

    type QueryFilter = ();

    type Out = (Self, Handle<HeadlessRenderSource>);

    fn extract_component(
        (destination, source_handle): QueryItem<'_, Self::QueryData>,
    ) -> Option<Self::Out> {
        Some((destination.clone(), source_handle.clone()))
    }
}

/// Bundle containing both a source and destination for headless rendering.
#[derive(Bundle)]
pub struct HeadlessRenderBundle {
    /// Source
    pub source: Handle<HeadlessRenderSource>,
    /// Destination
    pub dest: HeadlessRenderDestination,
}