From 5a1ad48f35f4cd28bb4dc4cd56f56ac289a50ab3 Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Tue, 5 Dec 2023 16:29:44 +0100 Subject: [PATCH] indentation, comment and naming fixes --- crates/re_renderer/src/context.rs | 31 ++++++++----------- crates/re_renderer/src/renderer/compositor.rs | 2 +- .../re_renderer/src/renderer/debug_overlay.rs | 2 +- .../re_renderer/src/renderer/depth_cloud.rs | 2 +- .../src/renderer/generic_skybox.rs | 2 +- crates/re_renderer/src/renderer/lines.rs | 2 +- .../re_renderer/src/renderer/mesh_renderer.rs | 2 +- .../re_renderer/src/renderer/point_cloud.rs | 2 +- crates/re_renderer/src/renderer/rectangles.rs | 2 +- .../re_renderer/src/renderer/test_triangle.rs | 2 +- 10 files changed, 22 insertions(+), 27 deletions(-) diff --git a/crates/re_renderer/src/context.rs b/crates/re_renderer/src/context.rs index f3bae8cc5bb4..456c075775b7 100644 --- a/crates/re_renderer/src/context.rs +++ b/crates/re_renderer/src/context.rs @@ -396,31 +396,26 @@ impl RenderContext { } /// Gets a renderer with the specified type, initializing it if necessary. - pub fn get_renderer( - &self, - ) -> MappedRwLockReadGuard<'_, R> { + pub fn renderer(&self) -> MappedRwLockReadGuard<'_, R> { + // Most likely we already have the renderer. Take a read lock and return it. + if let Ok(renderer) = + parking_lot::RwLockReadGuard::try_map(self.renderers.read(), |r| r.get::()) { - // Most likely we already have the renderer. Take a read lock and return it. - if let Ok(renderer) = - parking_lot::RwLockReadGuard::try_map(self.renderers.read(), |r| r.get::()) - { - return renderer; - } + return renderer; } // If it wasn't there we have to add it. // This path is rare since it happens only once per renderer type in the lifetime of the ctx. // (we don't discard renderers ever) - { - self.renderers.write().get_or_create::<_, R>( - &self.shared_renderer_data, - &self.gpu_resources, - &self.device, - &self.resolver, - ); - } + self.renderers.write().get_or_create::<_, R>( + &self.shared_renderer_data, + &self.gpu_resources, + &self.device, + &self.resolver, + ); + // Release write lock again and only take a read lock. - // safe to unwrap since we just created it. + // safe to unwrap since we just created it and nobody removes elements from the renderer. parking_lot::RwLockReadGuard::map(self.renderers.read(), |r| r.get::().unwrap()) } diff --git a/crates/re_renderer/src/renderer/compositor.rs b/crates/re_renderer/src/renderer/compositor.rs index 37b132aa5efd..9310502a57da 100644 --- a/crates/re_renderer/src/renderer/compositor.rs +++ b/crates/re_renderer/src/renderer/compositor.rs @@ -54,7 +54,7 @@ impl CompositorDrawData { outline_final_voronoi: Option<&GpuTexture>, outline_config: &Option, ) -> Self { - let compositor = ctx.get_renderer::(); + let compositor = ctx.renderer::(); let outline_config = outline_config.clone().unwrap_or(OutlineConfig { outline_radius_pixel: 0.0, diff --git a/crates/re_renderer/src/renderer/debug_overlay.rs b/crates/re_renderer/src/renderer/debug_overlay.rs index b2ce0d6b3990..d19de8319a3f 100644 --- a/crates/re_renderer/src/renderer/debug_overlay.rs +++ b/crates/re_renderer/src/renderer/debug_overlay.rs @@ -77,7 +77,7 @@ impl DebugOverlayDrawData { screen_resolution: glam::UVec2, overlay_rect: RectInt, ) -> Result { - let debug_overlay = ctx.get_renderer::(); + let debug_overlay = ctx.renderer::(); let mode = match debug_texture .texture diff --git a/crates/re_renderer/src/renderer/depth_cloud.rs b/crates/re_renderer/src/renderer/depth_cloud.rs index f0c759d55df3..0cb3d6480598 100644 --- a/crates/re_renderer/src/renderer/depth_cloud.rs +++ b/crates/re_renderer/src/renderer/depth_cloud.rs @@ -243,7 +243,7 @@ impl DepthCloudDrawData { radius_boost_in_ui_points_for_outlines, } = depth_clouds; - let renderer = ctx.get_renderer::(); + let renderer = ctx.renderer::(); let bg_layout = renderer.bind_group_layout; if depth_clouds.is_empty() { diff --git a/crates/re_renderer/src/renderer/generic_skybox.rs b/crates/re_renderer/src/renderer/generic_skybox.rs index 39a9184efb4b..494ed22c8f4b 100644 --- a/crates/re_renderer/src/renderer/generic_skybox.rs +++ b/crates/re_renderer/src/renderer/generic_skybox.rs @@ -31,7 +31,7 @@ impl DrawData for GenericSkyboxDrawData { impl GenericSkyboxDrawData { pub fn new(ctx: &RenderContext) -> Self { - let _ = ctx.get_renderer::(); // TODO(andreas): This should happen automatically. + let _ = ctx.renderer::(); // TODO(andreas): This line ensures that the renderer exists. Currently this needs to be done ahead of time, but should be fully automatic! GenericSkyboxDrawData {} } } diff --git a/crates/re_renderer/src/renderer/lines.rs b/crates/re_renderer/src/renderer/lines.rs index 445d8f3cc795..ed180106c30a 100644 --- a/crates/re_renderer/src/renderer/lines.rs +++ b/crates/re_renderer/src/renderer/lines.rs @@ -376,7 +376,7 @@ impl LineDrawData { ctx: &RenderContext, line_builder: LineStripSeriesBuilder, ) -> Result { - let line_renderer = ctx.get_renderer::(); + let line_renderer = ctx.renderer::(); if line_builder.strips.is_empty() { return Ok(LineDrawData { diff --git a/crates/re_renderer/src/renderer/mesh_renderer.rs b/crates/re_renderer/src/renderer/mesh_renderer.rs index 9d0f55e2e4d6..f77aeda056bc 100644 --- a/crates/re_renderer/src/renderer/mesh_renderer.rs +++ b/crates/re_renderer/src/renderer/mesh_renderer.rs @@ -157,7 +157,7 @@ impl MeshDrawData { pub fn new(ctx: &RenderContext, instances: &[MeshInstance]) -> anyhow::Result { re_tracing::profile_function!(); - let _mesh_renderer = ctx.get_renderer::(); + let _mesh_renderer = ctx.renderer::(); if instances.is_empty() { return Ok(MeshDrawData { diff --git a/crates/re_renderer/src/renderer/point_cloud.rs b/crates/re_renderer/src/renderer/point_cloud.rs index 8d8cc2469dfd..d0a5d9e8b755 100644 --- a/crates/re_renderer/src/renderer/point_cloud.rs +++ b/crates/re_renderer/src/renderer/point_cloud.rs @@ -186,7 +186,7 @@ impl PointCloudDrawData { ) -> Result { re_tracing::profile_function!(); - let point_renderer = ctx.get_renderer::(); + let point_renderer = ctx.renderer::(); let vertices = builder.vertices.as_slice(); let batches = builder.batches.as_slice(); diff --git a/crates/re_renderer/src/renderer/rectangles.rs b/crates/re_renderer/src/renderer/rectangles.rs index 0407d3f1e8c9..59eea5e43024 100644 --- a/crates/re_renderer/src/renderer/rectangles.rs +++ b/crates/re_renderer/src/renderer/rectangles.rs @@ -400,7 +400,7 @@ impl RectangleDrawData { pub fn new(ctx: &RenderContext, rectangles: &[TexturedRect]) -> Result { re_tracing::profile_function!(); - let rectangle_renderer = ctx.get_renderer::(); + let rectangle_renderer = ctx.renderer::(); if rectangles.is_empty() { return Ok(RectangleDrawData { diff --git a/crates/re_renderer/src/renderer/test_triangle.rs b/crates/re_renderer/src/renderer/test_triangle.rs index 071c01a138a8..092fb2ed28d2 100644 --- a/crates/re_renderer/src/renderer/test_triangle.rs +++ b/crates/re_renderer/src/renderer/test_triangle.rs @@ -22,7 +22,7 @@ impl DrawData for TestTriangleDrawData { impl TestTriangleDrawData { pub fn new(ctx: &RenderContext) -> Self { - let _ = ctx.get_renderer::(); // TODO(andreas): This should happen automatically. + let _ = ctx.renderer::(); // TODO(andreas): This line ensures that the renderer exists. Currently this needs to be done ahead of time, but should be fully automatic! TestTriangleDrawData {} } }