Open Warpten opened 2 weeks ago
commit 88466f4c88d2ef8e81dd9f4b97825fa0fe32bca2
Author: Warpten <vertozor@gmail.com>
Date: Thu Jun 6 10:43:11 2024 +0200
Remove scale factor duplication
diff --git a/renderer/src/gui/context.rs b/renderer/src/gui/context.rs
index 9650e3a..83fbd76 100644
--- a/renderer/src/gui/context.rs
+++ b/renderer/src/gui/context.rs
@@ -105,7 +105,9 @@ impl<T : Default> Renderer for Interface<T> {
let output = self.context.end_frame();
self.egui.handle_platform_output(window.handle(), output.platform_output.clone());
- let clipped_meshes = self.context.tessellate(output.shapes, self.scale_factor as _);
+ let scale_factor = self.rendering_context.window.handle().scale_factor();
+
+ let clipped_meshes = self.context.tessellate(output.shapes, scale_factor as _);
self.paint(&frame.cmd, swapchain, framebuffer, frame.index, clipped_meshes, output.textures_delta);
}
@@ -135,7 +137,6 @@ pub struct Interface<State : Default> {
command_pool : CommandPool,
frame_data : Vec<InterfaceFrameData>,
render_pass : RenderPass,
- pub scale_factor : f64,
// The sampler used when updating textures used by the GUI.
sampler : Sampler,
textures : HashMap<TextureId, Texture>,
@@ -293,8 +294,6 @@ impl<State : Default> Interface<State> {
sampler,
command_pool,
- scale_factor : context.window.handle().scale_factor(),
-
textures : HashMap::default(),
render_pass,
@@ -352,8 +351,9 @@ impl<State : Default> Interface<State> {
.height(swapchain.extent.height as f32)
]);
- let width_points = swapchain.extent.width as f32 / self.scale_factor as f32;
- let height_points = swapchain.extent.height as f32 / self.scale_factor as f32;
+ let scale_factor = self.rendering_context.window.handle().scale_factor() as f32;
+ let width_points = swapchain.extent.width as f32 / scale_factor;
+ let height_points = swapchain.extent.height as f32 / scale_factor;
cmd.push_constants(&self.pipeline, vk::ShaderStageFlags::VERTEX, 0, bytes_of(&width_points));
cmd.push_constants(&self.pipeline, vk::ShaderStageFlags::VERTEX, size_of_val(&width_points) as u32, bytes_of(&height_points));
@@ -394,12 +394,12 @@ impl<State : Default> Interface<State> {
}
let min = egui::Pos2 {
- x : f32::clamp(clip_rect.min.x * self.scale_factor as f32, 0.0, swapchain.extent.width as f32),
- y : f32::clamp(clip_rect.min.y * self.scale_factor as f32, 0.0, swapchain.extent.height as f32)
+ x : f32::clamp(clip_rect.min.x * scale_factor, 0.0, swapchain.extent.width as f32),
+ y : f32::clamp(clip_rect.min.y * scale_factor, 0.0, swapchain.extent.height as f32)
};
let max = egui::Pos2 {
- x : f32::clamp(clip_rect.max.x * self.scale_factor as f32, min.x, swapchain.extent.width as f32),
- y : f32::clamp(clip_rect.max.y * self.scale_factor as f32, min.y, swapchain.extent.height as f32),
+ x : f32::clamp(clip_rect.max.x * scale_factor, min.x, swapchain.extent.width as f32),
+ y : f32::clamp(clip_rect.max.y * scale_factor, min.y, swapchain.extent.height as f32),
};
// Record draw commands
diff --git a/renderer/src/orchestration/rendering.rs b/renderer/src/orchestration/rendering.rs
index 6fa497c..2c10ec0 100644
--- a/renderer/src/orchestration/rendering.rs
+++ b/renderer/src/orchestration/rendering.rs
@@ -310,7 +310,5 @@ impl RendererOrchestrator {
for i in 0..self.swapchain.image_count() {
self.frames.push(FrameData::new(i, &self.context));
}
-
- // I think that's it? Everything should drop.
}
}
Lost patches here.