@@ -40,27 +40,28 @@ enum BufferType {
40
40
41
41
/// Information about the screen used for rendering.
42
42
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 ,
49
48
}
50
49
51
50
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
+ ]
56
57
}
57
58
}
58
59
59
60
/// Uniform buffer used when rendering.
60
61
#[ derive( Clone , Copy , Debug ) ]
61
62
#[ repr( C ) ]
62
63
struct UniformBuffer {
63
- screen_size : [ f32 ; 2 ] ,
64
+ screen_size_in_points : [ f32 ; 2 ] ,
64
65
}
65
66
66
67
unsafe impl Pod for UniformBuffer { }
@@ -103,7 +104,7 @@ impl RenderPass {
103
104
let uniform_buffer = device. create_buffer_init ( & wgpu:: util:: BufferInitDescriptor {
104
105
label : Some ( "egui_uniform_buffer" ) ,
105
106
contents : bytemuck:: cast_slice ( & [ UniformBuffer {
106
- screen_size : [ 0.0 , 0.0 ] ,
107
+ screen_size_in_points : [ 0.0 , 0.0 ] ,
107
108
} ] ) ,
108
109
usage : wgpu:: BufferUsages :: UNIFORM | wgpu:: BufferUsages :: COPY_DST ,
109
110
} ) ;
@@ -285,9 +286,8 @@ impl RenderPass {
285
286
286
287
rpass. set_bind_group ( 0 , & self . uniform_bind_group , & [ ] ) ;
287
288
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 ;
291
291
292
292
for (
293
293
(
@@ -304,16 +304,16 @@ impl RenderPass {
304
304
. zip ( self . index_buffers . iter ( ) )
305
305
{
306
306
// 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 ;
311
311
312
312
// 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 ) ;
317
317
318
318
let clip_min_x = clip_min_x. round ( ) as u32 ;
319
319
let clip_min_y = clip_min_y. round ( ) as u32 ;
@@ -325,10 +325,10 @@ impl RenderPass {
325
325
326
326
{
327
327
// 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) ;
332
332
333
333
// Skip rendering with zero-sized clip areas.
334
334
if width == 0 || height == 0 {
@@ -359,7 +359,6 @@ impl RenderPass {
359
359
Ok ( ( ) )
360
360
}
361
361
362
- /// Add a new texture in raw RGBA format to be added on the next call to `update_textures`.
363
362
/// Should be called before `execute()`.
364
363
pub fn update_texture (
365
364
& mut self ,
@@ -463,7 +462,6 @@ impl RenderPass {
463
462
} ;
464
463
}
465
464
466
- /// Mark a texture to be destroyed on the next call to `update_textures`.
467
465
/// Should be called before `execute()`.
468
466
pub fn free_texture ( & mut self , id : & egui:: TextureId ) {
469
467
self . textures . remove ( id) ;
@@ -481,15 +479,15 @@ impl RenderPass {
481
479
let index_size = self . index_buffers . len ( ) ;
482
480
let vertex_size = self . vertex_buffers . len ( ) ;
483
481
484
- let ( logical_width , logical_height ) = screen_descriptor. logical_size ( ) ;
482
+ let screen_size_in_points = screen_descriptor. screen_size_in_points ( ) ;
485
483
486
484
self . update_buffer (
487
485
device,
488
486
queue,
489
487
& BufferType :: Uniform ,
490
488
0 ,
491
489
bytemuck:: cast_slice ( & [ UniformBuffer {
492
- screen_size : [ logical_width as f32 , logical_height as f32 ] ,
490
+ screen_size_in_points ,
493
491
} ] ) ,
494
492
) ;
495
493
@@ -543,28 +541,28 @@ impl RenderPass {
543
541
index : usize ,
544
542
data : & [ u8 ] ,
545
543
) {
546
- let ( buffer, storage, name ) = match buffer_type {
544
+ let ( buffer, storage, label ) = match buffer_type {
547
545
BufferType :: Index => (
548
546
& mut self . index_buffers [ index] ,
549
547
wgpu:: BufferUsages :: INDEX ,
550
- "index " ,
548
+ "egui_index_buffer " ,
551
549
) ,
552
550
BufferType :: Vertex => (
553
551
& mut self . vertex_buffers [ index] ,
554
552
wgpu:: BufferUsages :: VERTEX ,
555
- "vertex " ,
553
+ "egui_vertex_buffer " ,
556
554
) ,
557
555
BufferType :: Uniform => (
558
556
& mut self . uniform_buffer ,
559
557
wgpu:: BufferUsages :: UNIFORM ,
560
- "uniform " ,
558
+ "egui_uniform_buffer " ,
561
559
) ,
562
560
} ;
563
561
564
562
if data. len ( ) > buffer. size {
565
563
buffer. size = data. len ( ) ;
566
564
buffer. buffer = device. create_buffer_init ( & wgpu:: util:: BufferInitDescriptor {
567
- label : Some ( format ! ( "egui_{}_buffer" , name ) . as_str ( ) ) ,
565
+ label : Some ( label ) ,
568
566
contents : bytemuck:: cast_slice ( data) ,
569
567
usage : storage | wgpu:: BufferUsages :: COPY_DST ,
570
568
} ) ;
0 commit comments