Skip to content

Commit 65a999b

Browse files
committed
Minor cleanup
1 parent f2fd6b9 commit 65a999b

File tree

5 files changed

+38
-42
lines changed

5 files changed

+38
-42
lines changed

eframe/src/epi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ impl std::str::FromStr for Renderer {
294294
#[cfg(feature = "wgpu")]
295295
"wgpu" => Ok(Self::Wgpu),
296296

297-
_ =>Err(format!("eframe renderer {name:?} is not available. Make sure that the corresponding eframe feature is enabled."))
297+
_ => Err(format!("eframe renderer {name:?} is not available. Make sure that the corresponding eframe feature is enabled."))
298298
}
299299
}
300300
}

eframe/src/native/epi_integration.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub fn window_builder(
2828
multisampling: _, // used in `fn create_display`
2929
depth_buffer: _, // used in `fn create_display`
3030
stencil_buffer: _, // used in `fn create_display`
31-
renderer: _, // looked at in eframe::run_native
31+
renderer: _, // used in `fn run_native`
3232
} = native_options;
3333

3434
let window_icon = icon_data.clone().and_then(load_icon);

egui-wgpu/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
[![Latest version](https://img.shields.io/crates/v/egui-wgpu.svg)](https://crates.io/crates/egui-wgpu)
44
[![Documentation](https://docs.rs/egui-wgpu/badge.svg)](https://docs.rs/egui-wgpu)
5-
[![unsafe forbidden](https://img.shields.io/badge/unsafe-forbidden-success.svg)](https://github.com/rust-secure-code/safety-dance/)
65
![MIT](https://img.shields.io/badge/license-MIT-blue.svg)
76
![Apache](https://img.shields.io/badge/license-Apache-blue.svg)
87

egui-wgpu/src/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,8 @@ impl Painter {
100100

101101
// Upload all resources for the GPU.
102102
let screen_descriptor = renderer::ScreenDescriptor {
103-
physical_width: self.surface_config.width,
104-
physical_height: self.surface_config.height,
105-
scale_factor: pixels_per_point,
103+
size_in_pixels: [self.surface_config.width, self.surface_config.height],
104+
pixels_per_point,
106105
};
107106

108107
for (id, image_delta) in &textures_delta.set {

egui-wgpu/src/renderer.rs

+34-36
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,28 @@ enum BufferType {
4040

4141
/// Information about the screen used for rendering.
4242
pub struct ScreenDescriptor {
43-
/// Width of the window in physical pixel.
44-
pub physical_width: u32,
45-
/// Height of the window in physical pixel.
46-
pub physical_height: u32,
47-
/// HiDPI scale factor.
48-
pub scale_factor: f32,
43+
/// Size of the window in physical pixels.
44+
pub size_in_pixels: [u32; 2],
45+
46+
/// HiDPI scale factor (pixels per point).
47+
pub pixels_per_point: f32,
4948
}
5049

5150
impl ScreenDescriptor {
52-
fn logical_size(&self) -> (u32, u32) {
53-
let logical_width = self.physical_width as f32 / self.scale_factor;
54-
let logical_height = self.physical_height as f32 / self.scale_factor;
55-
(logical_width as u32, logical_height as u32)
51+
/// size in "logical" points
52+
fn screen_size_in_points(&self) -> [f32; 2] {
53+
[
54+
self.size_in_pixels[0] as f32 / self.pixels_per_point,
55+
self.size_in_pixels[1] as f32 / self.pixels_per_point,
56+
]
5657
}
5758
}
5859

5960
/// Uniform buffer used when rendering.
6061
#[derive(Clone, Copy, Debug)]
6162
#[repr(C)]
6263
struct UniformBuffer {
63-
screen_size: [f32; 2],
64+
screen_size_in_points: [f32; 2],
6465
}
6566

6667
unsafe impl Pod for UniformBuffer {}
@@ -103,7 +104,7 @@ impl RenderPass {
103104
let uniform_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
104105
label: Some("egui_uniform_buffer"),
105106
contents: bytemuck::cast_slice(&[UniformBuffer {
106-
screen_size: [0.0, 0.0],
107+
screen_size_in_points: [0.0, 0.0],
107108
}]),
108109
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
109110
});
@@ -285,9 +286,8 @@ impl RenderPass {
285286

286287
rpass.set_bind_group(0, &self.uniform_bind_group, &[]);
287288

288-
let scale_factor = screen_descriptor.scale_factor;
289-
let physical_width = screen_descriptor.physical_width;
290-
let physical_height = screen_descriptor.physical_height;
289+
let pixels_per_point = screen_descriptor.pixels_per_point;
290+
let size_in_pixels = screen_descriptor.size_in_pixels;
291291

292292
for (
293293
(
@@ -304,16 +304,16 @@ impl RenderPass {
304304
.zip(self.index_buffers.iter())
305305
{
306306
// Transform clip rect to physical pixels.
307-
let clip_min_x = scale_factor * clip_rect.min.x;
308-
let clip_min_y = scale_factor * clip_rect.min.y;
309-
let clip_max_x = scale_factor * clip_rect.max.x;
310-
let clip_max_y = scale_factor * clip_rect.max.y;
307+
let clip_min_x = pixels_per_point * clip_rect.min.x;
308+
let clip_min_y = pixels_per_point * clip_rect.min.y;
309+
let clip_max_x = pixels_per_point * clip_rect.max.x;
310+
let clip_max_y = pixels_per_point * clip_rect.max.y;
311311

312312
// Make sure clip rect can fit within an `u32`.
313-
let clip_min_x = clip_min_x.clamp(0.0, physical_width as f32);
314-
let clip_min_y = clip_min_y.clamp(0.0, physical_height as f32);
315-
let clip_max_x = clip_max_x.clamp(clip_min_x, physical_width as f32);
316-
let clip_max_y = clip_max_y.clamp(clip_min_y, physical_height as f32);
313+
let clip_min_x = clip_min_x.clamp(0.0, size_in_pixels[0] as f32);
314+
let clip_min_y = clip_min_y.clamp(0.0, size_in_pixels[1] as f32);
315+
let clip_max_x = clip_max_x.clamp(clip_min_x, size_in_pixels[0] as f32);
316+
let clip_max_y = clip_max_y.clamp(clip_min_y, size_in_pixels[1] as f32);
317317

318318
let clip_min_x = clip_min_x.round() as u32;
319319
let clip_min_y = clip_min_y.round() as u32;
@@ -325,10 +325,10 @@ impl RenderPass {
325325

326326
{
327327
// Clip scissor rectangle to target size.
328-
let x = clip_min_x.min(physical_width);
329-
let y = clip_min_y.min(physical_height);
330-
let width = width.min(physical_width - x);
331-
let height = height.min(physical_height - y);
328+
let x = clip_min_x.min(size_in_pixels[0]);
329+
let y = clip_min_y.min(size_in_pixels[1]);
330+
let width = width.min(size_in_pixels[0] - x);
331+
let height = height.min(size_in_pixels[1] - y);
332332

333333
// Skip rendering with zero-sized clip areas.
334334
if width == 0 || height == 0 {
@@ -359,7 +359,6 @@ impl RenderPass {
359359
Ok(())
360360
}
361361

362-
/// Add a new texture in raw RGBA format to be added on the next call to `update_textures`.
363362
/// Should be called before `execute()`.
364363
pub fn update_texture(
365364
&mut self,
@@ -463,7 +462,6 @@ impl RenderPass {
463462
};
464463
}
465464

466-
/// Mark a texture to be destroyed on the next call to `update_textures`.
467465
/// Should be called before `execute()`.
468466
pub fn free_texture(&mut self, id: &egui::TextureId) {
469467
self.textures.remove(id);
@@ -481,15 +479,15 @@ impl RenderPass {
481479
let index_size = self.index_buffers.len();
482480
let vertex_size = self.vertex_buffers.len();
483481

484-
let (logical_width, logical_height) = screen_descriptor.logical_size();
482+
let screen_size_in_points = screen_descriptor.screen_size_in_points();
485483

486484
self.update_buffer(
487485
device,
488486
queue,
489487
&BufferType::Uniform,
490488
0,
491489
bytemuck::cast_slice(&[UniformBuffer {
492-
screen_size: [logical_width as f32, logical_height as f32],
490+
screen_size_in_points,
493491
}]),
494492
);
495493

@@ -543,28 +541,28 @@ impl RenderPass {
543541
index: usize,
544542
data: &[u8],
545543
) {
546-
let (buffer, storage, name) = match buffer_type {
544+
let (buffer, storage, label) = match buffer_type {
547545
BufferType::Index => (
548546
&mut self.index_buffers[index],
549547
wgpu::BufferUsages::INDEX,
550-
"index",
548+
"egui_index_buffer",
551549
),
552550
BufferType::Vertex => (
553551
&mut self.vertex_buffers[index],
554552
wgpu::BufferUsages::VERTEX,
555-
"vertex",
553+
"egui_vertex_buffer",
556554
),
557555
BufferType::Uniform => (
558556
&mut self.uniform_buffer,
559557
wgpu::BufferUsages::UNIFORM,
560-
"uniform",
558+
"egui_uniform_buffer",
561559
),
562560
};
563561

564562
if data.len() > buffer.size {
565563
buffer.size = data.len();
566564
buffer.buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
567-
label: Some(format!("egui_{}_buffer", name).as_str()),
565+
label: Some(label),
568566
contents: bytemuck::cast_slice(data),
569567
usage: storage | wgpu::BufferUsages::COPY_DST,
570568
});

0 commit comments

Comments
 (0)