11use wgpu_bootstrap:: {
2- cgmath,
3- context:: Context ,
4- egui,
5- runner:: App ,
2+ cgmath, egui,
63 util:: orbit_camera:: { CameraUniform , OrbitCamera } ,
7- wgpu:: { self , util:: DeviceExt , TextureView } ,
4+ wgpu:: { self , util:: DeviceExt } ,
5+ App , Context ,
86} ;
9- use winit:: event:: { DeviceEvent , WindowEvent } ;
107
118#[ repr( C ) ]
129#[ derive( Copy , Clone , Debug , bytemuck:: Pod , bytemuck:: Zeroable ) ]
@@ -160,9 +157,7 @@ pub struct GuiApp {
160157}
161158
162159impl GuiApp {
163- pub fn new ( context : & mut Context ) -> Self {
164- context. window ( ) . set_title ( "Gui App" ) ;
165-
160+ pub fn new ( context : & Context ) -> Self {
166161 let index_buffer = context
167162 . device ( )
168163 . create_buffer_init ( & wgpu:: util:: BufferInitDescriptor {
@@ -218,7 +213,7 @@ impl GuiApp {
218213 module : & shader,
219214 entry_point : "fs_main" ,
220215 targets : & [ Some ( wgpu:: ColorTargetState {
221- format : context. config ( ) . format ,
216+ format : context. format ( ) ,
222217 blend : Some ( wgpu:: BlendState :: REPLACE ) ,
223218 write_mask : wgpu:: ColorWrites :: ALL ,
224219 } ) ] ,
@@ -237,7 +232,7 @@ impl GuiApp {
237232 conservative : false ,
238233 } ,
239234 depth_stencil : Some ( wgpu:: DepthStencilState {
240- format : * context. depth_format ( ) ,
235+ format : context. depth_stencil_format ( ) ,
241236 depth_write_enabled : true ,
242237 depth_compare : wgpu:: CompareFunction :: Less ,
243238 stencil : wgpu:: StencilState :: default ( ) ,
@@ -255,7 +250,7 @@ impl GuiApp {
255250 let mut camera = OrbitCamera :: new (
256251 context,
257252 45.0 ,
258- ( context. config ( ) . width as f32 ) / ( context. config ( ) . height as f32 ) ,
253+ context. size ( ) . x / context. size ( ) . y ,
259254 0.1 ,
260255 100.0 ,
261256 ) ;
@@ -276,67 +271,24 @@ impl GuiApp {
276271}
277272
278273impl App for GuiApp {
279- fn window_event ( & mut self , context : & mut Context , event : & WindowEvent ) -> bool {
280- return self . camera . window_event ( context, event) ;
281- }
282-
283- fn device_event ( & mut self , context : & mut Context , event : & DeviceEvent ) -> bool {
284- return self . camera . device_event ( context, event) ;
274+ fn input ( & mut self , input : egui:: InputState , context : & Context ) {
275+ self . camera . input ( input, context) ;
285276 }
286277
287- fn render ( & mut self , context : & mut Context , view : & TextureView ) {
288- let mut encoder =
289- context
290- . device ( )
291- . create_command_encoder ( & wgpu:: CommandEncoderDescriptor {
292- label : Some ( "Render Encoder" ) ,
293- } ) ;
294-
295- {
296- let mut render_pass = encoder. begin_render_pass ( & wgpu:: RenderPassDescriptor {
297- label : Some ( "Render Pass" ) ,
298- color_attachments : & [ Some ( wgpu:: RenderPassColorAttachment {
299- view,
300- resolve_target : None ,
301- ops : wgpu:: Operations {
302- load : wgpu:: LoadOp :: Clear ( wgpu:: Color {
303- r : 1.0 ,
304- g : 1.0 ,
305- b : 1.0 ,
306- a : 1.0 ,
307- } ) ,
308- store : wgpu:: StoreOp :: Store ,
309- } ,
310- } ) ] ,
311- depth_stencil_attachment : Some ( wgpu:: RenderPassDepthStencilAttachment {
312- view : context. depth_texture_view ( ) ,
313- depth_ops : Some ( wgpu:: Operations {
314- load : wgpu:: LoadOp :: Clear ( 1.0 ) ,
315- store : wgpu:: StoreOp :: Store ,
316- } ) ,
317- stencil_ops : None ,
318- } ) ,
319- occlusion_query_set : None ,
320- timestamp_writes : None ,
321- } ) ;
322-
323- render_pass. set_pipeline ( & self . render_pipeline ) ;
324- render_pass. set_vertex_buffer ( 0 , self . vertex_buffer . slice ( ..) ) ;
325- render_pass. set_index_buffer ( self . index_buffer . slice ( ..) , wgpu:: IndexFormat :: Uint32 ) ;
326- render_pass. set_bind_group ( 0 , self . camera . bind_group ( ) , & [ ] ) ;
327- render_pass. draw_indexed ( 0 ..self . num_indices , 0 , 0 ..1 ) ;
328- }
329-
330- // submit will accept anything that implements IntoIter
331- context. queue ( ) . submit ( std:: iter:: once ( encoder. finish ( ) ) ) ;
278+ fn render ( & self , render_pass : & mut wgpu:: RenderPass < ' _ > ) {
279+ render_pass. set_pipeline ( & self . render_pipeline ) ;
280+ render_pass. set_vertex_buffer ( 0 , self . vertex_buffer . slice ( ..) ) ;
281+ render_pass. set_index_buffer ( self . index_buffer . slice ( ..) , wgpu:: IndexFormat :: Uint32 ) ;
282+ render_pass. set_bind_group ( 0 , self . camera . bind_group ( ) , & [ ] ) ;
283+ render_pass. draw_indexed ( 0 ..self . num_indices , 0 , 0 ..1 ) ;
332284 }
333285
334- fn update ( & mut self , _context : & mut Context , delta_time : f32 ) {
286+ fn update ( & mut self , delta_time : f32 , _context : & Context ) {
335287 self . fps = 1.0 / delta_time;
336288 }
337289
338- fn render_gui ( & mut self , context : & mut Context , egui_context : & egui :: Context ) {
339- egui:: Window :: new ( "Params" ) . show ( egui_context , |ui| {
290+ fn render_gui ( & mut self , egui_ctx : & egui :: Context , context : & Context ) {
291+ egui:: Window :: new ( "Params" ) . show ( egui_ctx , |ui| {
340292 let mut radius = self . camera . radius ( ) ;
341293 ui. add ( egui:: Slider :: new ( & mut radius, 2.0 ..=10.0 ) . text ( "radius" ) ) ;
342294 self . camera . set_radius ( radius) . update ( context) ;
0 commit comments