11use alloc:: sync:: Arc ;
2- use send_wrapper:: SendWrapper ;
32use core:: cell:: RefCell ;
43use core:: num:: NonZeroU64 ;
4+ use send_wrapper:: SendWrapper ;
55
66use eframe:: egui:: { self , Mesh , Rect } ;
77use eframe:: egui_wgpu:: wgpu:: util:: DeviceExt as _;
@@ -111,7 +111,7 @@ pub fn init_mesh_renderer(cc: &eframe::CreationContext) -> Option<()> {
111111 index_capacity : 0 ,
112112 vertex_count : 0 ,
113113 index_count : 0 ,
114- index_scratch : Vec :: with_capacity ( 1024 ) ,
114+ index_scratch : Vec :: with_capacity ( 1024 ) ,
115115 } ) ,
116116 } ) ) ;
117117
@@ -123,12 +123,12 @@ struct BufferState {
123123 vertex_capacity : usize ,
124124 vertex_count : usize ,
125125
126- index_buffer : Option < wgpu:: Buffer > ,
127- index_capacity : usize ,
128- index_count : usize ,
126+ index_buffer : Option < wgpu:: Buffer > ,
127+ index_capacity : usize ,
128+ index_count : usize ,
129129
130- /// used for offseting current mesh indices
131- index_scratch : Vec < u32 > ,
130+ /// used for offseting current mesh indices
131+ index_scratch : Vec < u32 > ,
132132}
133133
134134struct MeshRenderResources {
@@ -153,9 +153,8 @@ impl egui_wgpu::CallbackTrait for MeshCallback {
153153 egui_encoder : & mut wgpu:: CommandEncoder , resources : & mut egui_wgpu:: CallbackResources ,
154154 ) -> Vec < wgpu:: CommandBuffer > {
155155 let mesh_resources: & mut SendWrapper < MeshRenderResources > = resources. get_mut ( ) . unwrap ( ) ;
156- let mesh_resources: & mut MeshRenderResources = mesh_resources;
157- let state = & mut mesh_resources. state . borrow_mut ( ) ;
158-
156+ let mesh_resources: & mut MeshRenderResources = mesh_resources;
157+ let state = & mut mesh_resources. state . borrow_mut ( ) ;
159158
160159 if state. index_count == 0 {
161160 // uniform is always be the same within one frame, so we only need to update it the first time.
@@ -221,7 +220,7 @@ impl egui_wgpu::CallbackTrait for MeshCallback {
221220 state. index_capacity = new_capacity;
222221 }
223222
224- // write vertices
223+ // write vertices
225224 let vertex_offset = ( state. vertex_count * size_of :: < egui:: epaint:: Vertex > ( ) ) as u64 ;
226225 queue. write_buffer (
227226 state. vertex_buffer . as_ref ( ) . unwrap ( ) ,
@@ -231,10 +230,10 @@ impl egui_wgpu::CallbackTrait for MeshCallback {
231230
232231 // we have to adjust indices by the current vertex offset
233232 let base_vertex = state. vertex_count as u32 ;
234- state. index_scratch . clear ( ) ;
235- for idx in self . mesh . indices . iter ( ) {
236- state. index_scratch . push ( * idx + base_vertex) ;
237- }
233+ state. index_scratch . clear ( ) ;
234+ for idx in self . mesh . indices . iter ( ) {
235+ state. index_scratch . push ( * idx + base_vertex) ;
236+ }
238237 let index_offset = ( state. index_count * size_of :: < u32 > ( ) ) as u64 ;
239238 queue. write_buffer (
240239 state. index_buffer . as_ref ( ) . unwrap ( ) ,
@@ -253,7 +252,7 @@ impl egui_wgpu::CallbackTrait for MeshCallback {
253252 callback_resources : & egui_wgpu:: CallbackResources ,
254253 ) {
255254 let mesh_resources: & SendWrapper < MeshRenderResources > = callback_resources. get ( ) . unwrap ( ) ;
256- let mesh_resources : & MeshRenderResources = mesh_resources;
255+ let mesh_resources: & MeshRenderResources = mesh_resources;
257256 let state = & mut mesh_resources. state . borrow_mut ( ) ;
258257
259258 // we draw everything in the first pain callback
@@ -270,7 +269,7 @@ impl egui_wgpu::CallbackTrait for MeshCallback {
270269 render_pass. set_index_buffer ( index_buffer. slice ( ..) , wgpu:: IndexFormat :: Uint32 ) ;
271270 render_pass. draw_indexed ( 0 ..( state. index_count as u32 ) , 0 , 0 ..1 ) ;
272271
273- // reset counts back to 0, so we only draw in the first callback
272+ // reset counts back to 0, so we only draw in the first callback
274273 state. vertex_count = 0 ;
275274 state. index_count = 0 ;
276275 }
0 commit comments