aboutsummaryrefslogtreecommitdiff
path: root/stockton-render/src/draw/draw_passes/cons.rs
blob: 3209806144e356f47fb8a21aa62cfb245e32e01b (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//! Code for using multiple draw passes in place of just one
//! Note that this can be extended to an arbitrary amount of draw passes.

use std::sync::{Arc, RwLock};

use super::{DrawPass, IntoDrawPass};
use crate::types::*;
use stockton_types::Session;

use anyhow::Result;

/// One draw pass, then another.
pub struct ConsDrawPass<A: DrawPass, B: DrawPass> {
    pub a: A,
    pub b: B,
}

impl<A: DrawPass, B: DrawPass> DrawPass for ConsDrawPass<A, B> {
    fn queue_draw(
        &mut self,
        session: &Session,
        img_view: &ImageViewT,
        cmd_buffer: &mut CommandBufferT,
    ) -> Result<()> {
        self.a.queue_draw(session, img_view, cmd_buffer)?;
        self.b.queue_draw(session, img_view, cmd_buffer)?;

        Ok(())
    }

    fn deactivate(self, device: &mut Arc<RwLock<DeviceT>>) -> Result<()> {
        self.a.deactivate(device)?;
        self.b.deactivate(device)
    }
}

impl<A: DrawPass, B: DrawPass, IA: IntoDrawPass<A>, IB: IntoDrawPass<B>>
    IntoDrawPass<ConsDrawPass<A, B>> for (IA, IB)
{
    fn init(
        self,
        session: &Session,
        adapter: &Adapter,
        device: Arc<RwLock<DeviceT>>,
        queue_negotiator: &mut crate::draw::queue_negotiator::QueueNegotiator,
        swapchain_properties: &crate::draw::target::SwapchainProperties,
    ) -> Result<ConsDrawPass<A, B>> {
        Ok(ConsDrawPass {
            a: self.0.init(
                session,
                adapter,
                device.clone(),
                queue_negotiator,
                swapchain_properties,
            )?,
            b: self.1.init(
                session,
                adapter,
                device,
                queue_negotiator,
                swapchain_properties,
            )?,
        })
    }

    fn find_aux_queues<'a>(
        adapter: &'a Adapter,
        queue_negotiator: &mut crate::draw::queue_negotiator::QueueNegotiator,
    ) -> Result<Vec<(&'a QueueFamilyT, Vec<f32>)>> {
        let mut v = IA::find_aux_queues(adapter, queue_negotiator)?;
        v.extend(IB::find_aux_queues(adapter, queue_negotiator)?);
        Ok(v)
    }
}