Skip to main content

ssruntime/context/
buffers.rs

1//! Zero-copy getters for the per-frame buffers the last [`Context::get_frame_data`] built.
2
3use super::Context;
4use crate::resource::StaticMeshBuffers;
5
6impl<'a> Context<'a> {
7    /// Pointer to the frame data built by the last [`get_frame_data`] call,
8    /// without re-evaluating it. Null until the first call, and again after
9    /// `reset` / `bind_resource`; valid until the next `get_frame_data`.
10    ///
11    /// [`get_frame_data`]: Self::get_frame_data
12    pub fn get_frame_data_ptr(&self) -> *const u8 {
13        if !self.eval.frame_data_ready {
14            return ::core::ptr::null();
15        }
16        self.eval.fb.finished_data().as_ptr()
17    }
18
19    /// Byte length of the buffer [`get_frame_data_ptr`] points at.
20    ///
21    /// [`get_frame_data_ptr`]: Self::get_frame_data_ptr
22    pub fn get_frame_data_len(&self) -> usize {
23        if !self.eval.frame_data_ready {
24            return 0;
25        }
26        self.eval.fb.finished_data().len()
27    }
28
29    pub fn get_world_matrices_ptr(&self) -> *const f32 {
30        self.instance.globals.world_matrices.as_ptr() as *const f32
31    }
32
33    pub fn get_world_matrices_len(&self) -> usize {
34        self.instance.globals.world_matrices.len() * 16
35    }
36
37    pub fn get_local_uvs_ptr(&self) -> *const f32 {
38        self.instance.globals.local_uvs.as_ptr()
39    }
40
41    pub fn get_local_uvs_len(&self) -> usize {
42        self.instance.globals.local_uvs.len()
43    }
44
45    pub fn get_shape_vertices_ptr(&self) -> *const f32 {
46        self.instance.globals.shape_vertices.as_ptr()
47    }
48
49    pub fn get_shape_vertices_len(&self) -> usize {
50        self.instance.globals.shape_vertices.len()
51    }
52
53    pub fn get_shape_vertex_box_coords_ptr(&self) -> *const f32 {
54        self.instance.globals.shape_vertex_box_coords.as_ptr()
55    }
56
57    pub fn get_shape_vertex_box_coords_len(&self) -> usize {
58        self.instance.globals.shape_vertex_box_coords.len()
59    }
60
61    pub fn get_shape_vertex_counts_ptr(&self) -> *const i32 {
62        self.instance.globals.shape_vertex_counts.as_ptr()
63    }
64
65    pub fn get_mesh_vertices_x_ptr(&self) -> *const f32 {
66        self.instance.globals.mesh_vertices_x.as_ptr()
67    }
68
69    pub fn get_mesh_vertices_x_len(&self) -> usize {
70        self.instance.globals.mesh_vertices_x.len()
71    }
72
73    pub fn get_mesh_vertices_y_ptr(&self) -> *const f32 {
74        self.instance.globals.mesh_vertices_y.as_ptr()
75    }
76
77    pub fn get_mesh_vertices_y_len(&self) -> usize {
78        self.instance.globals.mesh_vertices_y.len()
79    }
80
81    pub fn get_mesh_vertex_offsets_ptr(&self) -> *const u32 {
82        self.instance.globals.mesh_vertex_offsets.as_ptr()
83    }
84
85    pub fn get_mesh_vertex_offsets_len(&self) -> usize {
86        self.instance.globals.mesh_vertex_offsets.len()
87    }
88
89    /// The static mesh buffers this instance draws with: none before the first
90    /// Direct-mode `get_frame_data`, and none in SceneGraph mode.
91    fn static_mesh(&self) -> Option<&StaticMeshBuffers> {
92        self.eval.resource?.static_mesh(self.instance.globals.mesh_layout)
93    }
94
95    pub fn get_mesh_uvs_ptr(&self) -> *const f32 {
96        self.static_mesh().map_or(::core::ptr::NonNull::dangling().as_ptr(), |m| m.uvs.as_ptr())
97    }
98
99    pub fn get_mesh_uvs_len(&self) -> usize {
100        self.static_mesh().map_or(0, |m| m.uvs.len())
101    }
102
103    pub fn get_mesh_indices_ptr(&self) -> *const i32 {
104        self.static_mesh().map_or(::core::ptr::NonNull::dangling().as_ptr(), |m| m.indices.as_ptr())
105    }
106
107    pub fn get_mesh_indices_len(&self) -> usize {
108        self.static_mesh().map_or(0, |m| m.indices.len())
109    }
110
111    pub fn get_mesh_index_offsets_ptr(&self) -> *const u32 {
112        self.static_mesh().map_or(::core::ptr::NonNull::dangling().as_ptr(), |m| m.index_offsets.as_ptr())
113    }
114
115    pub fn get_mesh_index_offsets_len(&self) -> usize {
116        self.static_mesh().map_or(0, |m| m.index_offsets.len())
117    }
118
119    pub fn get_nines_vertices_ptr(&self) -> *const f32 {
120        self.instance.globals.nines.vertices.as_ptr()
121    }
122
123    pub fn get_nines_vertices_len(&self) -> usize {
124        self.instance.globals.nines.vertices.len()
125    }
126
127    pub fn get_nines_uvs_ptr(&self) -> *const f32 {
128        self.instance.globals.nines.uvs.as_ptr()
129    }
130
131    pub fn get_nines_uvs_len(&self) -> usize {
132        self.instance.globals.nines.uvs.len()
133    }
134
135    pub fn get_nines_box_coords_ptr(&self) -> *const f32 {
136        self.instance.globals.nines.box_coords.as_ptr()
137    }
138
139    pub fn get_nines_box_coords_len(&self) -> usize {
140        self.instance.globals.nines.box_coords.len()
141    }
142
143    pub fn get_nines_indices_ptr(&self) -> *const i32 {
144        self.instance.globals.nines.indices.as_ptr()
145    }
146
147    pub fn get_nines_indices_len(&self) -> usize {
148        self.instance.globals.nines.indices.len()
149    }
150
151    pub fn get_nines_vertex_offsets_ptr(&self) -> *const u32 {
152        self.instance.globals.nines.vertex_offsets.as_ptr()
153    }
154
155    pub fn get_nines_vertex_offsets_len(&self) -> usize {
156        self.instance.globals.nines.vertex_offsets.len()
157    }
158
159    pub fn get_nines_index_offsets_ptr(&self) -> *const u32 {
160        self.instance.globals.nines.index_offsets.as_ptr()
161    }
162
163    pub fn get_nines_index_offsets_len(&self) -> usize {
164        self.instance.globals.nines.index_offsets.len()
165    }
166
167    pub fn get_shape_vertex_counts_len(&self) -> usize {
168        self.instance.globals.shape_vertex_counts.len()
169    }
170
171    pub fn get_cell_meta_ptr(&self) -> *const f32 {
172        self.instance.resolved_layer.cell_meta_per_part.as_ptr()
173    }
174
175    pub fn get_cell_meta_len(&self) -> usize {
176        self.instance.resolved_layer.cell_meta_per_part.len()
177    }
178
179    pub fn get_local_vertices_ptr(&self) -> *const f32 {
180        self.instance.resolved_layer.local_vertices.as_ptr()
181    }
182
183    pub fn get_local_vertices_len(&self) -> usize {
184        self.instance.resolved_layer.local_vertices.len()
185    }
186}