1use std::marker::PhantomData;
2
3use crate::{BufferId, NodeKey, TextureId};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6pub enum DynamicResource {
7 Texture(TextureId),
8 Buffer(BufferId),
9}
10
11#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
12pub struct ParamKey {
13 pub owner: NodeKey,
14 pub slot: u32,
15}
16
17#[derive(Debug, Clone, PartialEq, Eq)]
18pub enum ParamTarget {
19 Buffer(BufferId),
20 Texture(TextureId),
21}
22
23#[derive(Debug, Clone)]
24pub struct ParamSlot {
25 pub key: ParamKey,
26 pub target: ParamTarget,
27}
28
29#[derive(Debug, Clone)]
30pub enum Upload<'a> {
31 Buffer {
32 id: BufferId,
33 offset: u64,
34 data: &'a [u8],
35 },
36 TextureRgba8 {
37 id: TextureId,
38 data: &'a [u8],
39 bytes_per_row: u32,
40 rows_per_image: u32,
41 },
42 TextureRgba8Region {
43 id: TextureId,
44 data: &'a [u8],
45 origin: [u32; 3],
46 size: crate::Size,
47 bytes_per_row: u32,
48 rows_per_image: u32,
49 },
50 TextureRgba16Float {
51 id: TextureId,
52 data: &'a [u16],
53 bytes_per_row: u32,
54 rows_per_image: u32,
55 },
56}
57
58#[derive(Debug, Clone, Default)]
59pub struct FrameUpdate<'a> {
60 pub(crate) uploads: Vec<Upload<'a>>,
61 _marker: PhantomData<&'a ()>,
62}
63
64impl<'a> FrameUpdate<'a> {
65 pub fn new() -> Self {
66 Self::default()
67 }
68
69 pub fn uploads(&self) -> &[Upload<'a>] {
70 &self.uploads
71 }
72
73 pub fn write_buffer(&mut self, id: BufferId, offset: u64, data: &'a [u8]) -> &mut Self {
74 self.uploads.push(Upload::Buffer { id, offset, data });
75 self
76 }
77
78 pub fn write_texture_rgba8(
79 &mut self,
80 id: TextureId,
81 data: &'a [u8],
82 bytes_per_row: u32,
83 rows_per_image: u32,
84 ) -> &mut Self {
85 self.uploads.push(Upload::TextureRgba8 {
86 id,
87 data,
88 bytes_per_row,
89 rows_per_image,
90 });
91 self
92 }
93
94 pub fn write_texture_rgba8_region(
95 &mut self,
96 id: TextureId,
97 data: &'a [u8],
98 origin: [u32; 3],
99 size: crate::Size,
100 bytes_per_row: u32,
101 rows_per_image: u32,
102 ) -> &mut Self {
103 self.uploads.push(Upload::TextureRgba8Region {
104 id,
105 data,
106 origin,
107 size,
108 bytes_per_row,
109 rows_per_image,
110 });
111 self
112 }
113
114 pub fn write_texture_rgba16_float(
115 &mut self,
116 id: TextureId,
117 data: &'a [u16],
118 bytes_per_row: u32,
119 rows_per_image: u32,
120 ) -> &mut Self {
121 self.uploads.push(Upload::TextureRgba16Float {
122 id,
123 data,
124 bytes_per_row,
125 rows_per_image,
126 });
127 self
128 }
129}