Record a cached model draw command. The actual rendering happens in end_frame().
(&mut self, handle_bits: u64, position: [f32; 3], scale: f32, tint: [f32; 4])
| 12341 | |
| 12342 | /// Record a cached model draw command. The actual rendering happens in end_frame(). |
| 12343 | pub fn draw_model_cached(&mut self, handle_bits: u64, position: [f32; 3], scale: f32, tint: [f32; 4]) { |
| 12344 | let mesh_count = match self.model_gpu_cache.get(&handle_bits) { |
| 12345 | Some(Some(meshes)) => meshes.len(), |
| 12346 | _ => return, |
| 12347 | }; |
| 12348 | |
| 12349 | for mesh_idx in 0..mesh_count { |
| 12350 | let slot = self.next_model_uniform_slot; |
| 12351 | self.next_model_uniform_slot += 1; |
| 12352 | |
| 12353 | // Grow uniform pool if needed |
| 12354 | self.ensure_model_uniform_slot(slot); |
| 12355 | |
| 12356 | // Compute model MVP: VP * translate(position) * scale(s) |
| 12357 | let model_matrix = mat4_multiply( |
| 12358 | mat4_translate(IDENTITY_MAT4, position), |
| 12359 | mat4_scale(IDENTITY_MAT4, [scale, scale, scale]), |
| 12360 | ); |
| 12361 | let model_mvp = mat4_multiply(self.current_vp_matrix, model_matrix); |
| 12362 | |
| 12363 | // Write uniform for this draw |
| 12364 | self.queue.write_buffer( |
| 12365 | &self.model_uniform_buffers[slot], |
| 12366 | 0, |
| 12367 | bytemuck::bytes_of(&Uniforms3D { mvp: model_mvp, model: model_matrix, prev_mvp: model_mvp, model_tint: tint }), |
| 12368 | ); |
| 12369 | |
| 12370 | self.model_draw_commands.push(CachedModelDraw { |
| 12371 | uniform_slot: slot, |
| 12372 | cache_handle: handle_bits, |
| 12373 | mesh_idx, |
| 12374 | }); |
| 12375 | } |
| 12376 | } |
| 12377 | |
| 12378 | fn ensure_model_uniform_slot(&mut self, slot: usize) { |
| 12379 | while self.model_uniform_buffers.len() <= slot { |
no test coverage detected