From 11077150cbc909e414cf5b27f18d02629e6b01da Mon Sep 17 00:00:00 2001 From: Micha White Date: Thu, 20 Oct 2022 23:19:00 -0400 Subject: Made the run function generic --- alligator_render/examples/black.rs | 2 +- alligator_render/examples/bmp.rs | 2 +- alligator_render/examples/bunnymark.rs | 3 ++- alligator_render/src/instance.rs | 8 ++++++-- alligator_render/src/renderer.rs | 2 +- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/alligator_render/examples/black.rs b/alligator_render/examples/black.rs index 622429f..b8846ca 100644 --- a/alligator_render/examples/black.rs +++ b/alligator_render/examples/black.rs @@ -17,5 +17,5 @@ fn main() { let renderer = Renderer::new(&config).unwrap(); println!("Startup time: {:?}", start.elapsed()); - renderer.run(Box::leak(Box::new(update))); + renderer.run(update); } diff --git a/alligator_render/examples/bmp.rs b/alligator_render/examples/bmp.rs index 23842a9..b8ce00c 100644 --- a/alligator_render/examples/bmp.rs +++ b/alligator_render/examples/bmp.rs @@ -84,5 +84,5 @@ fn main() { ..Default::default() }); - renderer.run(Box::leak(Box::new(update))); + renderer.run(update); } diff --git a/alligator_render/examples/bunnymark.rs b/alligator_render/examples/bunnymark.rs index 759d725..a343ce5 100644 --- a/alligator_render/examples/bunnymark.rs +++ b/alligator_render/examples/bunnymark.rs @@ -121,6 +121,7 @@ fn main() { .textures_mut() .load_from_memory(bunny, ImageFormat::Farbfeld) .unwrap(); + let state = Box::leak(Box::new(State::new(texture_id))); - renderer.run(Box::leak(Box::new(|r| state.update(r)))); + renderer.run(|r| state.update(r)); } diff --git a/alligator_render/src/instance.rs b/alligator_render/src/instance.rs index 2d1808f..e346cae 100644 --- a/alligator_render/src/instance.rs +++ b/alligator_render/src/instance.rs @@ -151,8 +151,12 @@ impl InstanceBuffer { } // the instances must be sorted by z-index before being handed to the GPU - let mut sorted = self.instances.clone(); - sorted.sort_by(|a, b| a.z_index.total_cmp(&b.z_index)); + let sorted = { + profiling::scope!("depth sorting"); + let mut sorted = self.instances.clone(); + sorted.sort_by(|a, b| a.z_index.total_cmp(&b.z_index)); + sorted + }; queue.write_buffer( &self.instance_buffer, diff --git a/alligator_render/src/renderer.rs b/alligator_render/src/renderer.rs index ec3cac5..9f4aad1 100644 --- a/alligator_render/src/renderer.rs +++ b/alligator_render/src/renderer.rs @@ -372,7 +372,7 @@ impl Renderer { } /// Run the renderer indefinitely - pub fn run(mut self, f: &'static mut dyn FnMut(&mut Self)) -> ! { + pub fn run(mut self, mut f: F) -> ! { self.window.set_visible(true); let event_loop = self.event_loop(); event_loop.run(move |event, _, control_flow| match event { -- cgit v1.2.3