rafx_framework/render_features/jobs/extract/
view_packet.rs

1use crate::render_features::render_features_prelude::*;
2
3/// Read documentation on `FramePacketData`.
4pub struct ViewPacket<FramePacketDataT: FramePacketData> {
5    view: RenderView,
6    view_frame_index: ViewFrameIndex,
7
8    pub(crate) per_view_data: AtomicOnceCell<FramePacketDataT::PerViewData>,
9    pub(crate) render_object_instances: Vec<RenderObjectInstancePerView>,
10    pub(crate) render_object_instances_data:
11        AtomicOnceCellArray<FramePacketDataT::RenderObjectInstancePerViewData>,
12
13    volumes: Vec<ObjectId>,
14}
15
16impl<FramePacketDataT: FramePacketData> ViewPacket<FramePacketDataT> {
17    pub fn new(
18        view_packet_size: &ViewPacketSize,
19        view_frame_index: ViewFrameIndex,
20    ) -> Self {
21        Self {
22            view: view_packet_size.view.clone(),
23            view_frame_index,
24            per_view_data: AtomicOnceCell::new(),
25            render_object_instances: Vec::with_capacity(
26                view_packet_size.num_render_object_instances,
27            ),
28            render_object_instances_data: AtomicOnceCellArray::with_capacity(
29                view_packet_size.num_render_object_instances,
30            ),
31            volumes: Vec::with_capacity(view_packet_size.num_volumes),
32        }
33    }
34
35    pub fn render_object_instances(&self) -> &Vec<RenderObjectInstancePerView> {
36        &self.render_object_instances
37    }
38
39    pub fn render_object_instances_data(
40        &self
41    ) -> &AtomicOnceCellArray<FramePacketDataT::RenderObjectInstancePerViewData> {
42        &self.render_object_instances_data
43    }
44
45    pub fn per_view_data(&self) -> &AtomicOnceCell<FramePacketDataT::PerViewData> {
46        &self.per_view_data
47    }
48
49    pub fn view_frame_index(&self) -> ViewFrameIndex {
50        self.view_frame_index
51    }
52
53    pub fn volumes(&self) -> &Vec<ObjectId> {
54        &self.volumes
55    }
56}
57
58impl<FramePacketDataT: 'static + FramePacketData> RenderFeatureViewPacket
59    for ViewPacket<FramePacketDataT>
60{
61    fn view(&self) -> &RenderView {
62        &self.view
63    }
64
65    fn view_frame_index(&self) -> ViewFrameIndex {
66        self.view_frame_index
67    }
68
69    fn num_render_object_instances(&self) -> usize {
70        self.render_object_instances.len()
71    }
72
73    fn push_render_object_instance(
74        &mut self,
75        render_object_instance_id: RenderObjectInstanceId,
76        render_object_instance: RenderObjectInstance,
77    ) -> RenderObjectInstancePerViewId {
78        let index = self.render_object_instances.len();
79        self.render_object_instances
80            .push(RenderObjectInstancePerView::new(
81                render_object_instance_id,
82                render_object_instance,
83            ));
84        index as RenderObjectInstancePerViewId
85    }
86
87    fn push_volume(
88        &mut self,
89        object_id: ObjectId,
90    ) {
91        self.volumes.push(object_id);
92    }
93}
94
95/// A specific `RenderObjectInstance` as viewed by some `RenderView`.
96#[derive(Copy, Eq, PartialEq, Hash, Clone, Debug)]
97pub struct RenderObjectInstancePerView {
98    pub render_object_instance_id: RenderObjectInstanceId,
99    pub render_object_instance: RenderObjectInstance,
100}
101
102impl RenderObjectInstancePerView {
103    pub fn new(
104        render_object_instance_id: RenderObjectInstanceId,
105        render_object_instance: RenderObjectInstance,
106    ) -> Self {
107        Self {
108            render_object_instance_id,
109            render_object_instance,
110        }
111    }
112}